<commit_before>should = require 'should'
moment = require 'moment'
express = require 'express'
fs = require 'fs'

Konnector = require '../server/models/konnector'
Bill = require '../server/models/bill'
Commit = require '../server/models/commit'
konnectorHash = require '../server/lib/konnector_hash'
createKonnectors = require '../server/init/konnectors'


describe 'Konnector model', ->

    createdFile = null
    server = null
    importDone = false

    konnector = new Konnector
        name: 'Test'
        slug: 'test'
        fieldValues: []
        importInterval: 'week'

    before (done) ->
        app = express()
        server = app.listen 12223, (err) ->
            map = (doc) ->
                emit doc._id, doc
                return
            Konnector.defineRequest 'all', map, ->

                createKonnectors ->
                    konnectorHash['test'] =
                        name: 'Test'
                        slug: 'test'
                        fields:
                            login: 'text'
                            password: 'password'
                        fetch: (values, callback) ->
                            importDone = true
                            callback()
                        models:
                            bills: Bill
                            commits: Commit
                        init: ->

                    done()


    after (done) ->
        server.close()
        if konnector.id?
            konnector.destroy done
        else
            done()


    it 'turn encrypted fields in normal fields', ->
        konnector.password = JSON.stringify password: '<PASSWORD>'
        konnector.injectEncryptedFields()
        should.exist konnector.fieldValues.password
        konnector.fieldValues.password.should.equal '<PASSWORD>'

    it 'remove encrypted fields from normal fields', ->
        konnector.removeEncryptedFields konnectorHash.test.fields<commit_msg>Fix a warning for Travis tests<commit_after>should = require 'should'
moment = require 'moment'
express = require 'express'
fs = require 'fs'

Konnector = require '../server/models/konnector'
Bill = require '../server/models/bill'
Commit = require '../server/models/commit'
konnectorHash = require '../server/lib/konnector_hash'
createKonnectors = require '../server/init/konnectors'


describe 'Konnector model', ->

    createdFile = null
    server = null
    importDone = false

    konnector = new Konnector
        name: 'Test'
        slug: 'test'
        fieldValues: []
        importInterval: 'week'

    before (done) ->
        app = express()
        server = app.listen 12223, (err) ->
            map = (doc) ->
                emit doc._id, doc
                return
            Konnector.defineRequest 'all', map, ->

                createKonnectors ->
                    konnectorHash['test'] =
                        name: 'Test'
                        slug: 'test'
                        fields:
                            login: 'text'
                            password: 'password'
                        fetch: (values, callback) ->
                            importDone = true
                            callback()
                        models:
                            bills: Bill
                            commits: Commit
                        init: ->

                    done()


    after (done) ->
        server.close()
        if konnector.id?
            konnector.destroy done
        else
            done()


    it 'turn encrypted fields in normal fields', ->
        konnector.password = JSON.stringify password: '<PASSWORD>'
        konnector.injectEncryptedFields()
        should.exist konnector.fieldValues.password
        konnector.fieldValues.password.should.equal '<PASSWORD>'

    it 'remove encrypted fields from normal fields', ->
        konnector.id = '123'
        konnector.removeEncryptedFields konnectorHash.test.fields
{'fraction_non_alphanumeric': 0.0963000506842372, 'fraction_numerical': 0.003294475418144957, 'mean_word_length': 1.4067073170731708, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, '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': '4486765', 'n_tokens_mistral': 1022, 'n_tokens_neox': 962, 'n_words': 248}