<commit_before>var should = require('should'),
    sinon = require('sinon'),
    proxyquire = require('proxyquire').noCallThru();

require('should-sinon');

describe('Dynamo', function() {
    var dynastyMock,
        collectionMock,
        collectionObj,
        Storage,
        config;

    beforeEach(function() {
        config = {dynamoRegion: 'region',
                  dynamoAccessKey: 'key',
                  dynamoAccessSecret: 'secret'};

        collectionObj = {
            find: sinon.stub(),
            insert: sinon.stub()
        };

        collectionMock = {
            table: sinon.stub().returns(collectionObj)
        };

        dynastyMock = sinon.stub().returns(collectionMock);

        Storage = proxyquire('../src/index', {dynasty: dynastyMock});
    });

    describe('Initialization', function() {
        it('should throw an error if config is missing', function() {
            Storage.should.throw('Need to provide dynamo dynamoRegion, ' +
            'dynamoAccessKey, dynamoAccessSecret');
        });

        it('should throw an error if dynamoRegion is missing', function() {
            config.dynamoRegion = null;
            (function() {Storage(config);}).should.throw('Need to provide dynamo dynamoRegion, ' +
            'dynamoAccessKey, dynamoAccessSecret');
        });

        it('should throw an error if dynamoAccessKey is missing', function() {
            config.dynamoAccessKey = null;
            (function() {Storage(config);}).should.throw('Need to provide dynamo dynamoRegion, ' +
            'dynamoAccessKey, dynamoAccessSecret');
        });

        it('should throw an error if dynamoAccessSecret is missing', function() {
            config.dynamoAccessSecret = null;
            (function() {Storage(config);}).should.throw('Need to provide dynamo dynamoRegion, ' +
            'dynamoAccessKey, dynamoAccessSecret');
        });

        it('should initialize dynasty with dynamoRegion, dynamoAccessKey, dynamoAccessSecret', function() {
            Storage(config);
            dynastyMock.callCount.should.equal(1);
            dynastyMock.args[0][0].should.deepEqual({
                region: 'region',
                accessKeyId: 'key',
                secretAccessKey: 'secret'
            });
        });
    });

    ['teams', 'channels', 'users'].forEach(function(method) {
        describe(method + '.get', function() {
            it('should call find with callback', function() {
                var cb = sinon.stub();

                Storage(config)[method].get('walterwhite', cb);
                collectionObj.find.should.be.calledWith({hash: 'walterwhite', range: method}, cb);
            });
        });

        describe(method + '.save', function() {

            it('should call insert', function() {
                var data = {id: 'walterwhite', type: method},
                    cb = sinon.stub();

                Storage(config)[method].save(data, cb);
                collectionObj.insert.should.be.calledWith(
                    data,
                    cb
                );
            });
        });
    });
});
<commit_msg>Flip hash and range to work as dynamo wants them to<commit_after>var should = require('should'),
    sinon = require('sinon'),
    proxyquire = require('proxyquire').noCallThru();

require('should-sinon');

describe('Dynamo', function() {
    var dynastyMock,
        collectionMock,
        collectionObj,
        Storage,
        config;

    beforeEach(function() {
        config = {dynamoRegion: 'region',
                  dynamoAccessKey: 'key',
                  dynamoAccessSecret: 'secret'};

        collectionObj = {
            find: sinon.stub(),
            insert: sinon.stub()
        };

        collectionMock = {
            table: sinon.stub().returns(collectionObj)
        };

        dynastyMock = sinon.stub().returns(collectionMock);

        Storage = proxyquire('../src/index', {dynasty: dynastyMock});
    });

    describe('Initialization', function() {
        it('should throw an error if config is missing', function() {
            Storage.should.throw('Need to provide dynamo dynamoRegion, ' +
            'dynamoAccessKey, dynamoAccessSecret');
        });

        it('should throw an error if dynamoRegion is missing', function() {
            config.dynamoRegion = null;
            (function() {Storage(config);}).should.throw('Need to provide dynamo dynamoRegion, ' +
            'dynamoAccessKey, dynamoAccessSecret');
        });

        it('should throw an error if dynamoAccessKey is missing', function() {
            config.dynamoAccessKey = null;
            (function() {Storage(config);}).should.throw('Need to provide dynamo dynamoRegion, ' +
            'dynamoAccessKey, dynamoAccessSecret');
        });

        it('should throw an error if dynamoAccessSecret is missing', function() {
            config.dynamoAccessSecret = null;
            (function() {Storage(config);}).should.throw('Need to provide dynamo dynamoRegion, ' +
            'dynamoAccessKey, dynamoAccessSecret');
        });

        it('should initialize dynasty with dynamoRegion, dynamoAccessKey, dynamoAccessSecret', function() {
            Storage(config);
            dynastyMock.callCount.should.equal(1);
            dynastyMock.args[0][0].should.deepEqual({
                region: 'region',
                accessKeyId: 'key',
                secretAccessKey: 'secret'
            });
        });
    });

    ['teams', 'channels', 'users'].forEach(function(method) {
        describe(method + '.get', function() {
            it('should call find with callback', function() {
                var cb = sinon.stub();

                Storage(config)[method].get('walterwhite', cb);
                collectionObj.find.should.be.calledWith({hash: method, range: 'walterwhite'}, cb);
            });
        });

        describe(method + '.save', function() {

            it('should call insert', function() {
                var data = {id: 'walterwhite', type: method},
                    cb = sinon.stub();

                Storage(config)[method].save(data, cb);
                collectionObj.insert.should.be.calledWith(
                    data,
                    cb
                );
            });
        });
    });
});

{'fraction_non_alphanumeric': 0.1317042208822596, 'fraction_numerical': 0.000952078705172961, 'mean_word_length': 2.0, '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': '5850715', 'n_tokens_mistral': 1671, 'n_tokens_neox': 1610, 'n_words': 354}