<commit_before>should = require('chai').Should()
async = require('async')
Client = require('request-json').JsonClient
app = require('../server')

client = new Client("http://localhost:7000/")


# connection to DB for "hand work"
cradle = require 'cradle'
connection = new cradle.Connection
    cache: true,
    raw: false
db = connection.database('cozy')


# helpers

# Function for async to create and index notes
createNoteFunction = (title, content) ->
    (callback) ->
        note =
            title: title
            content: content
            docType: "Note"

        client.post "data/", note, (error, response, body) ->
            client.post "data/index/#{body._id}",
                fields: ["title", "content"]
                , callback


describe "Indexation", ->

    # Clear DB, create a new one, then init data for tests.
    before (done) ->
        client.del "data/index/clear-all/", (err, response) ->
            db.destroy ->
                console.log 'DB destroyed'
                db.create ->
                    console.log 'DB recreated'
                    done()

    # Start application before starting tests.
    before (done) ->
        app.listen(8888)
        done()



    describe "indexing and searching", ->
        it "Given I index four notes", (done) ->
            async.series [
                createNoteFunction "Note 01", "little stories begin"
                createNoteFunction "Note 02", "great dragons are coming"
                createNoteFunction "Note 03", "small hobbits are afraid"
                createNoteFunction "Note 04", "such as humans"
            ], ->
                done()
            
        it "When I send a request to search the notes containing dragons", (done) ->
            client.post "data/search/note", { query: "dragons" }, \
                    (error, response, body) =>
                @result = body
                done()<commit_msg>debug index tests<commit_after>should = require('chai').Should()
async = require('async')
Client = require('request-json').JsonClient
app = require('../server')

client = new Client("http://localhost:8888/")


# connection to DB for "hand work"
cradle = require 'cradle'
connection = new cradle.Connection
    cache: true,
    raw: false
db = connection.database('cozy')


# helpers

# Function for async to create and index notes
createNoteFunction = (title, content) ->
    (callback) ->
        note =
            title: title
            content: content
            docType: "Note"

        client.post "data/", note, (error, response, body) ->
            console.log error if error
            client.post "data/index/#{body._id}",
                fields: ["title", "content"]
                , callback


describe "Indexation", ->

    # Start application before starting tests.
    before (done) ->
        app.listen(8888)
        done()

    # Clear DB, create a new one, then init data for tests.
    before (done) ->
        client.del "data/index/clear-all/", (err, response) ->
            console.log err if err
            db.destroy ->
                console.log 'DB destroyed'
                db.create ->
                    console.log 'DB recreated'
                    done()


    describe "indexing and searching", ->
        it "Given I index four notes", (done) ->
            async.series [
                createNoteFunction "Note 01", "little stories begin"
                createNoteFunction "Note 02", "great dragons are coming"
                createNoteFunction "Note 03", "small hobbits are afraid"
                createNoteFunction "Note 04", "such as humans"
            ], ->
                done()
            
        it "When I send a request to search the notes containing dragons", (done) ->
            client.post "data/search/note", { query: "dragons" }, \
                    (error, response, body) =>
                @result = body
                done()
{'fraction_non_alphanumeric': 0.11645054665649632, 'fraction_numerical': 0.00813628273582507, 'mean_word_length': 1.7821782178217822, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1646418', 'n_tokens_mistral': 1082, 'n_tokens_neox': 996, 'n_words': 329}