<commit_before>define(function(require) {
    'use strict';

    var controller = require('js/app-controller'),
        EmailDAO = require('js/dao/email-dao'),
        $ = require('jquery'),
        expect = chai.expect;

    var appControllerTest = {
        user: '<EMAIL>',
        passphrase: '<PASSWORD>'
    };

    describe('App Controller unit tests', function() {

        beforeEach(function() {
            sinon.stub(controller, 'login', function(userId, password, token, callback) {
                controller._emailDao = sinon.createStubInstance(EmailDAO);
                callback();
            });

            sinon.stub($, 'get');
            sinon.stub($, 'ajax').yieldsTo('success', {
                email: appControllerTest.user
            });

            window.chrome = window.chrome || {};
            window.chrome.identity = window.chrome.identity || {};
            if (typeof window.chrome.identity.getAuthToken !== 'function') {
                window.chrome.identity.getAuthToken = function() {};
            }
            sinon.stub(window.chrome.identity, 'getAuthToken');
            window.chrome.identity.getAuthToken.yields('token42');
        });

        afterEach(function() {
            controller.login.restore();
            $.get.restore();
            $.ajax.restore();
            window.chrome.identity.getAuthToken.restore();
        });

        describe('start', function() {
            it('should not explode', function(done) {
                $.get.yields('<div></div>');
                controller.start(function(err) {
                    expect($.get.called).to.be.true;
                    expect(err).to.not.exist;
                    done();
                });
            });
        });

        describe('execute', function() {

            describe('login', function() {
                it('should work', function(done) {
                    controller.execute('login', {
                        password: appControllerTest.passphrase
                    }, function(resArgs) {
                        expect(resArgs.err).to.not.exist;
                        expect(resArgs.userId).to.equal(appControllerTest.user);
                        expect($.ajax.called).to.be.true;
                        expect(window.chrome.identity.getAuthToken.called).to.be.true;
                        done();
                    });
                });
            });

            describe('sendEmail', function() {
                it('should work', function(done) {
                    controller._emailDao.smtpSend.yields();
                    controller.execute('sendEmail', {
                        password: <PASSWORD>
                    }, function(resArgs) {
                        expect(resArgs.err).to.not.exist;
                        expect(controller._emailDao.smtpSend.called).to.be.true;
                        done();
                    });
                });
            });

        });

    });

});<commit_msg>started testing app controller<commit_after>define(function(require) {
    'use strict';

    var controller = require('js/app-controller'),
        EmailDAO = require('js/dao/email-dao'),
        $ = require('jquery'),
        expect = chai.expect;

    var appControllerTest = {
        user: '<EMAIL>',
        passphrase: '<PASSWORD>'
    };

    describe('App Controller unit tests', function() {

        beforeEach(function() {
            sinon.stub(controller, 'login', function(userId, password, token, callback) {
                controller._emailDao = sinon.createStubInstance(EmailDAO);
                callback();
            });

            sinon.stub($, 'get');
            sinon.stub($, 'ajax').yieldsTo('success', {
                email: appControllerTest.user
            });

            window.chrome = window.chrome || {};
            window.chrome.identity = window.chrome.identity || {};
            if (typeof window.chrome.identity.getAuthToken !== 'function') {
                window.chrome.identity.getAuthToken = function() {};
            }
            sinon.stub(window.chrome.identity, 'getAuthToken');
            window.chrome.identity.getAuthToken.yields('token42');
        });

        afterEach(function() {
            controller.login.restore();
            $.get.restore();
            $.ajax.restore();
            window.chrome.identity.getAuthToken.restore();
        });

        describe('start', function() {
            it('should not explode', function(done) {
                $.get.yields('<div></div>');
                controller.start(function(err) {
                    expect($.get.called).to.be.true;
                    expect(err).to.not.exist;
                    done();
                });
            });
        });

        describe('execute', function() {
            describe('login', function() {
                it('should work', function(done) {
                    controller.execute('login', {
                        password: <PASSWORD>
                    }, function(resArgs) {
                        expect(resArgs.err).to.not.exist;
                        expect(resArgs.userId).to.equal(appControllerTest.user);
                        expect($.ajax.called).to.be.true;
                        expect(window.chrome.identity.getAuthToken.called).to.be.true;
                        done();
                    });
                });
            });

            describe('sendEmail', function() {
                it('should work', function(done) {
                    controller._emailDao.smtpSend.yields();
                    controller.execute('sendEmail', {
                        password: <PASSWORD>
                    }, function(resArgs) {
                        expect(resArgs.err).to.not.exist;
                        expect(controller._emailDao.smtpSend.called).to.be.true;
                        done();
                    });
                });
            });
        });

    });

});
{'fraction_non_alphanumeric': 0.13893997659254306, 'fraction_numerical': 0.0006687844841999665, 'mean_word_length': 1.3899320815021974, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '6596518', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1431, 'n_words': 195}