<commit_before>'use strict';

/*jshint expr: true*/

const expect = require( 'chai' ).expect;

const proxyquire = require( 'proxyquire' ).noCallThru();

const sinon = require( 'sinon' );

// sets LAMBDA_TASK_ROOT
require( 'lambda-tester' );

const configUtils = require( '../config-utils' );

const MODULE_PATH = 'lib/config/index';

//var logger = require( '../../../lib/logger' ).setLevel( 'debug' );

describe( MODULE_PATH, function() {

    let s3Stub;

    let configModule;

    beforeEach( function() {

        configUtils.removeConfig();

        s3Stub = {

            load: sinon.stub()
        }

        configModule = proxyquire( '../../../' + MODULE_PATH, {

                './s3': s3Stub
            });
    });

    after( function() {

        configUtils.removeConfig();
    });

    describe( 'Configuration', function() {

        describe( 'constructor (via .create)', function() {

            it( 'normal operation', function() {

                let config = configModule.create();

                expect( config._loaded ).to.be.false;
            });
        });

        describe( '.load', function() {

            it( 'no configuration file', function() {

                let config = configModule.create();

                config.load();

                expect( config._loaded ).to.be.true;

                expect( config.get() ).to.eql( {} );
            });

            it( 'simple configuration file, no s3', function() {

                var configData = {

                    jwt: {

                        token_name: 'bearer'
                    }
                }

                configUtils.writeConfig( JSON.stringify( configData ) );

                let config = configModule.create();

                config.load();

                expect( config._loaded ).to.be.true;

                expect( config.get() ).to.eql( configData );
            });

            it( 'simple configuration file, path provided, no s3', function() {

                var configData = {

                    jwt: {

                        token_name: 'bearer'
                    }
                }

                configUtils.writeConfig( JSON.stringify( configData ) );

                let config = configModule.create();

                config.load( configUtils.path );

                expect( config._loaded ).to.be.true;

                expect( config.get() ).to.eql( configData );
            });

            it( 'simple configuration file with s3 refer', function() {

                var s3Data = {

                    jwt: {
<commit_msg>Added case to test on()<commit_after>'use strict';

/*jshint expr: true*/

const expect = require( 'chai' ).expect;

const proxyquire = require( 'proxyquire' ).noCallThru();

const sinon = require( 'sinon' );

// sets LAMBDA_TASK_ROOT
require( 'lambda-tester' );

const configUtils = require( '../config-utils' );

const MODULE_PATH = 'lib/config/index';

//var logger = require( '../../../lib/logger' ).setLevel( 'debug' );

describe( MODULE_PATH, function() {

    let s3Stub;

    let configModule;

    beforeEach( function() {

        configUtils.removeConfig();

        s3Stub = {

            load: sinon.stub()
        }

        configModule = proxyquire( '../../../' + MODULE_PATH, {

                './s3': s3Stub
            });
    });

    after( function() {

        configUtils.removeConfig();
    });

    describe( 'Configuration', function() {

        describe( 'constructor (via .create)', function() {

            it( 'normal operation', function() {

                let config = configModule.create();

                expect( config._loaded ).to.be.false;
            });
        });

        describe( '.load', function() {

            it( 'no configuration file', function() {

                let config = configModule.create();

                config.load();

                expect( config._loaded ).to.be.true;

                expect( config.get() ).to.eql( {} );
            });

            it( 'simple configuration file, no s3', function( done ) {

                var configData = {

                    jwt: {

                        token_name: 'bearer'
                    }
                }

                configUtils.writeConfig( JSON.stringify( configData ) );

                let config = configModule.create();

                config.on( 'update', function() {

                    expect( config.get() ).to.eql( configData );

                    process.nextTick( done );
                });

                config.load();
                
                expect( config._loaded ).to.be.true;
            });

            it( 'simple configuration file, path provided, no s3', function() {

                var configData = {

                    jwt: {

                        token_name: 'bearer'
                    }
                }

                configUtils.writeConfig( JSON.stringify( configData ) );

                let config = configModule.create();

                config.load( configUtils.path );

                expect( config._loaded ).to.be.true;

                expect( config.get() ).to.eql( configData );
            });

            it( 'simple configuration file with s3 refer', function() {

                var s3Data = {

                    jwt: {

{'fraction_non_alphanumeric': 0.13334583645911477, 'fraction_numerical': 0.003000750187546887, 'mean_word_length': 1.3776192599197503, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5805914', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1343, 'n_words': 328}