<commit_before>/* global describe, beforeEach, spyOn, expect, it, $, */

describe("Testing the AccountsCtrl.", function () {

    var scope, createController, httpBackend, loadingService, alertService, accountsService;

    beforeEach(function(){

        angular.mock.module('trevor');
        angular.mock.module('templates');

        inject(function ($injector, LoadingService, AlertService, AccountsService) {

            scope = $injector.get('$rootScope');
            controller = $injector.get('$controller');
            httpBackend = $injector.get('$httpBackend');
            alertService = AlertService;
            loadingService = LoadingService;
            accountsService = AccountsService;

            createController = function() {
                return controller('AccountsCtrl', {
                    '$scope' : $injector.get('$rootScope'),
                    'LoadingService' : loadingService,
                    'AlertService' : alertService,
                    'AccountsService' : accountsService,
                });
            };

        });

    });

    it("Should get the accounts for Travis CI Open Source.", function () {

        data = {
            "accounts": [
                {
                    "id": 82677,
                    "name": "<NAME>",
                    "login": "johndoe",
                    "type": "user",
                    "repos_count": 19,
                    "avatar_url": null
                },
                {
                    "id": 2195,
                    "name": "DabApps",
                    "login": "dabapps",
                    "type": "organization",
                    "repos_count": 13,
                    "avatar_url": "https://avatars.githubusercontent.com/u/445568"
                }
            ]
        };

        accountsService.setPro(false);

        spyOn(loadingService, 'show');
        spyOn(loadingService, 'hide');

        httpBackend.expectGET("https://api.travis-ci.org/accounts?all=true").respond(data);

        var controller = createController();

        expect(loadingService.show).toHaveBeenCalled();

        httpBackend.flush();

        expect(scope.accounts[0].type).toBe("user");
        expect(scope.accounts[1].name).toBe("DabApps");
        expect(scope.accounts[1].repos_count).toEqual(13);
        expect(accountsService.getPro()).toBeFalsy();
        expect(loadingService.hide).toHaveBeenCalled();
        expect(scope.greeting).toBe("<NAME>");
    });

    it("Should get the accounts for Travis CI PRO.", function () {

        var data = {
            "accounts": [
                {
                    "id": 24446,
                    "name": "<NAME>",
                    "login": "johndoe",
                    "type": "user",
                    "repos_count": 6,
                    "subscribed": false,
                    "education": true
                },
                {
                    "id": 34,
                    "name": "Travis CI GmbH",
                    "login": "travis-pro",
                    "type": "organization",
                    "repos_count": 90,
                    "subscribed": true,
                    "education": false
                }
            ]
        };

        accountsService.setPro(true);

        httpBackend.expectGET("https://api.travis-ci.com/accounts?all=true").respond(data);

        var controller = createController();

        httpBackend.flush();

        expect(accountsService.getPro()).toBeTruthy();
        expect(scope.greeting).toBe("<NAME>");
    });


    it("Should FAIL to get the accounts from Travis CI PRO.", function () {

        accountsService.setPro(true);
        spyOn(alertService, 'raiseAlert');
        spyOn(loadingService, 'hide');

        httpBackend.expectGET("https://api.travis-ci.com/accounts?all=true").respond(400, "ERROR.");

        var controller = createController();

        httpBackend.flush();

        expect(alertService.raiseAlert).toHaveBeenCalledWith("Oops! We couldn't get your accounts from Travis CI. Please try again.");
        expect(loadingService.hide).toHaveBeenCalled();
    });


    it("Should logout a logged in user.", function () {

        accountsService.setPro(true);

        var controller = createController();

        scope.logOut();

        expect(accountsService.isLoggedIn()).toBeFalsy();
    });


    it("Should DISABLE if pro and NOT subscribed and NOT education.", function () {

        accountsService.setPro(true);

        var controller = createController();

        var disable = scope.shouldDisable(false, false);
        expect(disable).toBeTruthy();
    });


    it("Should not disable if pro and subscribed.", function () {

        accountsService.setPro(true);

        var controller = createController();

        var disable = scope.shouldDisable(true, false);
        expect(disable).toBeFalsy();
    });


});


describe("Testing the LogoutCtrl.", function () {

    var scope, state, createController, accountsService;

    beforeEach(function(){

        angular.mock.module('trevor');
        angular.mock.module('templates');

        inject(function ($injector, LoadingService, AccountsService) {

            scope = $injector.get('$rootScope');
            controller = $injector.get('$controller');
            state = $injector.get('$state');
            accountsService = AccountsService;

            createController = function() {
                return controller('LogoutCtrl', {
                    '$scope' : $injector.get('$rootScope'),
                    '$state' : $injector.get('$state'),
                    'AccountsService' : accountsService,
                });
            };

        });

    });


    it("Should logout a logged in user.", function () {

        spyOn(accountsService, 'logOut');
        spyOn(state, 'go');

        var controller = createController();

        expect(accountsService.logOut).toHaveBeenCalled();
        expect(state.go).toHaveBeenCalledWith("welcome");

    });

});<commit_msg>Complete accounts tests<commit_after>/* global describe, beforeEach, spyOn, expect, it, $, */

describe("Testing the AccountsCtrl.", function () {

    var scope, createController, httpBackend, loadingService, alertService, accountsService;

    beforeEach(function(){

        angular.mock.module('trevor');
        angular.mock.module('templates');

        inject(function ($injector, LoadingService, AlertService, AccountsService) {

            scope = $injector.get('$rootScope');
            controller = $injector.get('$controller');
            httpBackend = $injector.get('$httpBackend');
            alertService = AlertService;
            loadingService = LoadingService;
            accountsService = AccountsService;

            createController = function() {
                return controller('AccountsCtrl', {
                    '$scope' : $injector.get('$rootScope'),
                    'LoadingService' : loadingService,
                    'AlertService' : alertService,
                    'AccountsService' : accountsService,
                });
            };

        });

    });

    it("Should get the accounts for Travis CI Open Source.", function () {

        data = {
            "accounts": [
                {
                    "id": 82677,
                    "name": "<NAME>",
                    "login": "johndoe",
                    "type": "user",
                    "repos_count": 19,
                    "avatar_url": null
                },
                {
                    "id": 2195,
                    "name": "DabApps",
                    "login": "dabapps",
                    "type": "organization",
                    "repos_count": 13,
                    "avatar_url": "https://avatars.githubusercontent.com/u/445568"
                }
            ]
        };

        accountsService.setPro(false);

        spyOn(loadingService, 'show');
        spyOn(loadingService, 'hide');

        httpBackend.expectGET("https://api.travis-ci.org/accounts?all=true").respond(data);

        var controller = createController();

        expect(loadingService.show).toHaveBeenCalled();

        httpBackend.flush();

        expect(scope.accounts[0].type).toBe("user");
        expect(scope.accounts[1].name).toBe("DabApps");
        expect(scope.accounts[1].repos_count).toEqual(13);
        expect(accountsService.getPro()).toBeFalsy();
        expect(loadingService.hide).toHaveBeenCalled();
        expect(scope.greeting).toBe("<NAME>");
    });

    it("Should get the accounts for Travis CI PRO.", function () {

        var data = {
            "accounts": [
                {
                    "id": 24446,
                    "name": "",
                    "login": "johndoe",
                    "type": "user",
                    "repos_count": 6,
                    "subscribed": false,
                    "education": true
                },
                {
                    "id": 34,
                    "name": "Travis CI GmbH",
                    "login": "travis-pro",
                    "type": "organization",
                    "repos_count": 90,
                    "subscribed": true,
                    "education": false
                }
            ]
        };

        accountsService.setPro(true);

        httpBackend.expectGET("https://api.travis-ci.com/accounts?all=true").respond(data);

        var controller = createController();

        httpBackend.flush();

        expect(accountsService.getPro()).toBeTruthy();
        expect(scope.greeting).toBe("johndoe");
    });


    it("Should FAIL to get the accounts from Travis CI PRO.", function () {

        accountsService.setPro(true);
        spyOn(alertService, 'raiseAlert');
        spyOn(loadingService, 'hide');

        httpBackend.expectGET("https://api.travis-ci.com/accounts?all=true").respond(400, "ERROR.");

        var controller = createController();

        httpBackend.flush();

        expect(alertService.raiseAlert).toHaveBeenCalledWith("Oops! We couldn't get your accounts from Travis CI. Please try again.");
        expect(loadingService.hide).toHaveBeenCalled();
    });


    it("Should logout a logged in user.", function () {

        accountsService.setPro(true);

        var controller = createController();

        scope.logOut();

        expect(accountsService.isLoggedIn()).toBeFalsy();
    });


    it("Should DISABLE if pro and NOT subscribed and NOT education.", function () {

        var controller = createController();

        accountsService.setPro(true);
        var disable = scope.shouldDisable(false, false);
        expect(disable).toBeTruthy();

        accountsService.setPro(false);
        var disable = scope.shouldDisable(false, false);
        expect(disable).toBeFalsy();
    });


    it("Should not disable if pro and subscribed.", function () {

        accountsService.setPro(true);

        var controller = createController();

        var disable = scope.shouldDisable(true, false);
        expect(disable).toBeFalsy();
    });


});


describe("Testing the LogoutCtrl.", function () {

    var scope, state, createController, accountsService;

    beforeEach(function(){

        angular.mock.module('trevor');
        angular.mock.module('templates');

        inject(function ($injector, LoadingService, AccountsService) {

            scope = $injector.get('$rootScope');
            controller = $injector.get('$controller');
            state = $injector.get('$state');
            accountsService = AccountsService;

            createController = function() {
                return controller('LogoutCtrl', {
                    '$scope' : $injector.get('$rootScope'),
                    '$state' : $injector.get('$state'),
                    'AccountsService' : accountsService,
                });
            };

        });

    });


    it("Should logout a logged in user.", function () {

        spyOn(accountsService, 'logOut');
        spyOn(state, 'go');

        var controller = createController();

        expect(accountsService.logOut).toHaveBeenCalled();
        expect(state.go).toHaveBeenCalledWith("welcome");

    });

});
{'fraction_non_alphanumeric': 0.13397677081629314, 'fraction_numerical': 0.006052674627842303, 'mean_word_length': 1.8244398244398243, 'pattern_counts': {'":': 56, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 8, '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': '4913232', 'n_tokens_mistral': 3338, 'n_tokens_neox': 3086, 'n_words': 583}