<commit_before>const expect = require('chai').expect;
const mockery = require('mockery');
const sinon = require('sinon');

describe('Index unit tests', () => {
    let subject;
    let event;
    const responseStub = sinon.stub();
    const validateStub = sinon.stub();
    const createStub = sinon.stub();
    const updateStub = sinon.stub();
    const deleteStub = sinon.stub();
    const logStub = sinon.stub();
    const logEventStub = sinon.stub();
    const normalizeStub = sinon.stub();

    before(() => {
        mockery.enable({
            useCleanCache: true,
            warnOnUnregistered: false,
        });

        const pluginMock = {
            validate: validateStub,
            schema: {},
            create: createStub,
            update: updateStub,
            delete: deleteStub,
        };

        mockery.registerMock('./lib/cfn-response', responseStub);
        mockery.registerMock('./lib/log-event', logEventStub);
        mockery.registerMock('plugin', pluginMock);
        mockery.registerMock('./lib/normalize', normalizeStub);
        subject = require('../../src/index');
    });
    beforeEach(() => {
        responseStub.reset();
        responseStub.yields();
        validateStub.reset();
        validateStub.returns();
        createStub.reset();
        createStub.yields(null, { success: true });
        updateStub.reset();
        updateStub.yields(null, { success: true });
        deleteStub.reset();
        deleteStub.yields(null, { success: true });
        logStub.reset();
        logStub.returns();
        normalizeStub.reset();
        normalizeStub.returnsArg(0);
        logEventStub.reset();
        logEventStub.returns();
        event = {
            RequestType: 'Create',
            ResourceType: 'Custom::Plugin',
            ResourceProperties: {
                Property: 'test',
            },
            OldResourceProperties: {
                OldProperty: 'test2',
            },
        };
    });
    after(() => {
        mockery.deregisterAll();
        mockery.disable();
    });

    describe('__construct', () => {
        it('should succeed', (done) => {
            expect(subject()).to.be.an('object');
            done();
        });
    });

    describe('register', () => {
        it('should succeed', (done) => {
            const lulo = subject().register('testPlugin', {});
            expect(lulo).to.be.an('object');
            expect(lulo.plugins.testPlugin).to.be.an('object');
            done();
        });
        it('should fail on duplicate', (done) => {
            expect(registerDuplicate).to.throw(/Trying to register same plugin name twice/);
            done();

            function registerDuplicate() {
                subject()
                    .register('testPlugin', {})
                    .register('otherPlugin', {})
                    .register('testPlugin', {});
            }
        });
    });

    describe('handler', () => {
        it('Create should succeed', (done) => {
            subject({ logEvents: true })
                .register('Plugin', require('plugin')) // eslint-disable-line import/no-extraneous-dependencies
                .handler(event, {}, () => {
                    expect(logEventStub.calledOnce).to.equal(true);
                    expect(responseStub.calledOnce).to.equal(true);
                    expect(responseStub.calledWith(null, sinon.match.has('success', true), sinon.match.object,
                        sinon.match.object, sinon.match.bool, sinon.match.func)).to.equal(true);
                    expect(validateStub.calledOnce).to.equal(true);
                    expect(createStub.calledOnce).to.equal(true);
                    expect(deleteStub.called).to.equal(false);
                    expect(updateStub.called).to.equal(false);
                    done();
                });
        });
        it('Update should succeed, with config overrides', (done) => {
            subject()
                .register('Plugin', require('plugin'), { logEvents: true, logResponse: true, maskedProperties: [] }) // eslint-disable-line import/no-extraneous-dependencies
                .handler({ RequestType: 'Update', ResourceType: 'Custom::Plugin' }, {}, () => {
                    expect(logEventStub.called).to.equal(true);<commit_msg>lint fix<commit_after>const expect = require('chai').expect;
const mockery = require('mockery');
const sinon = require('sinon');

describe('Index unit tests', () => {
    let subject;
    let event;
    const responseStub = sinon.stub();
    const validateStub = sinon.stub();
    const createStub = sinon.stub();
    const updateStub = sinon.stub();
    const deleteStub = sinon.stub();
    const logStub = sinon.stub();
    const logEventStub = sinon.stub();
    const normalizeStub = sinon.stub();

    before(() => {
        mockery.enable({
            useCleanCache: true,
            warnOnUnregistered: false,
        });

        const pluginMock = {
            validate: validateStub,
            schema: {},
            create: createStub,
            update: updateStub,
            delete: deleteStub,
        };

        mockery.registerMock('./lib/cfn-response', responseStub);
        mockery.registerMock('./lib/log-event', logEventStub);
        mockery.registerMock('plugin', pluginMock);
        mockery.registerMock('./lib/normalize', normalizeStub);
        subject = require('../../src/index');
    });
    beforeEach(() => {
        responseStub.reset();
        responseStub.yields();
        validateStub.reset();
        validateStub.returns();
        createStub.reset();
        createStub.yields(null, { success: true });
        updateStub.reset();
        updateStub.yields(null, { success: true });
        deleteStub.reset();
        deleteStub.yields(null, { success: true });
        logStub.reset();
        logStub.returns();
        normalizeStub.reset();
        normalizeStub.returnsArg(0);
        logEventStub.reset();
        logEventStub.returns();
        event = {
            RequestType: 'Create',
            ResourceType: 'Custom::Plugin',
            ResourceProperties: {
                Property: 'test',
            },
            OldResourceProperties: {
                OldProperty: 'test2',
            },
        };
    });
    after(() => {
        mockery.deregisterAll();
        mockery.disable();
    });

    describe('__construct', () => {
        it('should succeed', (done) => {
            expect(subject()).to.be.an('object');
            done();
        });
    });

    describe('register', () => {
        it('should succeed', (done) => {
            const lulo = subject().register('testPlugin', {});
            expect(lulo).to.be.an('object');
            expect(lulo.plugins.testPlugin).to.be.an('object');
            done();
        });
        it('should fail on duplicate', (done) => {
            expect(registerDuplicate).to.throw(/Trying to register same plugin name twice/);
            done();

            function registerDuplicate() {
                subject()
                    .register('testPlugin', {})
                    .register('otherPlugin', {})
                    .register('testPlugin', {});
            }
        });
    });

    describe('handler', () => {
        it('Create should succeed', (done) => {
            subject({ logEvents: true })
                .register('Plugin', require('plugin')) // eslint-disable-line import/no-extraneous-dependencies
                .handler(event, {}, () => {
                    expect(logEventStub.calledOnce).to.equal(true);
                    expect(responseStub.calledOnce).to.equal(true);
                    expect(responseStub.calledWith(null, sinon.match.has('success', true), sinon.match.object,
                        sinon.match.object, sinon.match.bool, sinon.match.func)).to.equal(true);
                    expect(validateStub.calledOnce).to.equal(true);
                    expect(createStub.calledOnce).to.equal(true);
                    expect(deleteStub.called).to.equal(false);
                    expect(updateStub.called).to.equal(false);
                    done();
                });
        });
        it('Update should succeed, with config overrides', (done) => {
            subject()
                .register('Plugin', require('plugin'), { logEvents: true, logResponse: true, maskedProperties: [] }) // eslint-disable-line import/no-extraneous-dependencies, max-len
                .handler({ RequestType: 'Update', ResourceType: 'Custom::Plugin' }, {}, () => {
                    expect(logEventStub.called).to.equal(true);
{'fraction_non_alphanumeric': 0.15211333023687879, 'fraction_numerical': 0.00046446818392940084, 'mean_word_length': 1.8922095366017462, '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': '6412875', 'n_tokens_mistral': 2270, 'n_tokens_neox': 2291, 'n_words': 379}