<commit_before>﻿/// <reference path="../../_references.js" />
/// <reference path="../../app/services/modal.js"/>
/// <reference path="../../app/controllers/login.js" />

'use strict';

describe('Controllers: LoginCtrl', function () {

    beforeEach(module('app.controllers'));

    describe('Default', function() {        
        var scope, ctrl;

        beforeEach(inject(function ($rootScope, $controller) {
            scope = $rootScope.$new();
            ctrl = $controller('LoginCtrl', { $scope: scope });
        }));

        it('should not be logged in yet', function() {
            expect(scope.$root.loggedIn).toBe(false);
        });

        it('should not set a page title', function() {
            expect(scope.$root.title).toBe(undefined);
        });
    });

    describe('Login: Success', function () {
        var scope, rootScope, ctrl, httpBackend, http;
        var loginConfirmedCalled = false;
        
        beforeEach(inject(function ($rootScope, $controller, $httpBackend, $http) {
            rootScope = $rootScope;
            scope = $rootScope.$new();
            httpBackend = $httpBackend;
            http = $http;
            
            httpBackend.when("POST", "/Token").respond({ access_token: 'token' });

            var fakeAuthService = {
                loginConfirmed: function() {
                    loginConfirmedCalled = true;
                }
            };
            
            ctrl = $controller('LoginCtrl', {
                $scope: scope,
                $http: $http,
                $rootScope: $rootScope,
                authService: fakeAuthService
            });

            scope.login({});
            httpBackend.flush();
        }));

        it('should set bearer token', function () {
            expect(http.defaults.headers.common["Authorization"]).toBe('Bearer token');
        });

        it('should call auth contoroller loginConfirmed', function() {
            expect(loginConfirmedCalled).toBe(true);
        });

        it('should set logged in flag', function() {
            expect(rootScope.loggedIn).toBe(true);
        });

        it('should turn off invalid login flag', function () {
            expect(rootScope.invalidLogin).toBe(false);
        });

    });

    describe('Login: Failure', function () {
        var scope, rootScope, ctrl, httpBackend, http;
        var loginCanceledCalled = false;

        beforeEach(inject(function ($rootScope, $controller, $httpBackend, $http) {
            rootScope = $rootScope;
            scope = $rootScope.$new();
            httpBackend = $httpBackend;
            http = $http;

            httpBackend.when("POST", "/Token").respond(400, {});

            var fakeAuthService = {
                loginCanceled: function () {
                    loginCanceledCalled = true;
                }
            };

            ctrl = $controller('LoginCtrl', {
                $scope: scope,
                $http: $http,
                $rootScope: $rootScope,
                authService: fakeAuthService
            });

            scope.login({});
            httpBackend.flush();
        }));

        it('should call auth contoroller loginCanceled', function () {
            expect(loginCanceledCalled).toBe(true);
        });

        it('should turn off logged in flag', function () {
            expect(rootScope.loggedIn).toBe(false);
        });

        it('should set invalid login flag', function() {
            expect(rootScope.invalidLogin).toBe(true);
        });

    });
});<commit_msg>added tests to login controller for opening login modal<commit_after>﻿/// <reference path="../../_references.js" />
/// <reference path="../../app/services/modal.js"/>
/// <reference path="../../app/controllers/login.js" />

'use strict';

describe('Controllers: LoginCtrl', function () {

    beforeEach(module('app.controllers'));

    describe('Default', function() {        
        var scope, ctrl;

        beforeEach(inject(function ($rootScope, $controller) {
            scope = $rootScope.$new();
            ctrl = $controller('LoginCtrl', { $scope: scope });
        }));

        it('should not be logged in yet', function() {
            expect(scope.$root.loggedIn).toBe(false);
        });

        it('should not set a page title', function() {
            expect(scope.$root.title).toBe(undefined);
        });
    });

    describe('Login: Success', function () {
        var scope, rootScope, ctrl, httpBackend, http;
        var loginConfirmedCalled = false;
        
        beforeEach(inject(function ($rootScope, $controller, $httpBackend, $http) {
            rootScope = $rootScope;
            scope = $rootScope.$new();
            httpBackend = $httpBackend;
            http = $http;
            
            httpBackend.when("POST", "/Token").respond({ access_token: 'token' });

            var fakeAuthService = {
                loginConfirmed: function() {
                    loginConfirmedCalled = true;
                }
            };
            
            ctrl = $controller('LoginCtrl', {
                $scope: scope,
                $http: $http,
                $rootScope: $rootScope,
                authService: fakeAuthService
            });

            scope.login({});
            httpBackend.flush();
        }));

        it('should set bearer token', function () {
            expect(http.defaults.headers.common["Authorization"]).toBe('Bearer token');
        });

        it('should call auth contoroller loginConfirmed', function() {
            expect(loginConfirmedCalled).toBe(true);
        });

        it('should set logged in flag', function() {
            expect(rootScope.loggedIn).toBe(true);
        });

        it('should turn off invalid login flag', function () {
            expect(rootScope.invalidLogin).toBe(false);
        });

    });

    describe('Login: Failure', function () {
        var scope, rootScope, ctrl, httpBackend, http;
        var loginCanceledCalled = false;

        beforeEach(inject(function ($rootScope, $controller, $httpBackend, $http) {
            rootScope = $rootScope;
            scope = $rootScope.$new();
            httpBackend = $httpBackend;
            http = $http;

            httpBackend.when("POST", "/Token").respond(400, {});

            var fakeAuthService = {
                loginCanceled: function () {
                    loginCanceledCalled = true;
                }
            };

            ctrl = $controller('LoginCtrl', {
                $scope: scope,
                $http: $http,
                $rootScope: $rootScope,
                authService: fakeAuthService
            });

            scope.login({});
            httpBackend.flush();
        }));

        it('should call auth contoroller loginCanceled', function () {
            expect(loginCanceledCalled).toBe(true);
        });

        it('should turn off logged in flag', function () {
            expect(rootScope.loggedIn).toBe(false);
        });

        it('should set invalid login flag', function() {
            expect(rootScope.invalidLogin).toBe(true);
        });

    });

    describe('Open login modal', function() {
        var scope, ctrl;
        var calledLogin = false;

        beforeEach(inject(function($rootScope, $controller) {
            scope = $rootScope.$new();

            var fakeModalService = {
                login: function () { calledLogin = true; }
            };

            ctrl = $controller('LoginCtrl', {
                $scope: scope,
                modalService: fakeModalService
            });

            scope.openLogin();
        }));

        it('Should call the modal servie login method', function() {
            expect(calledLogin).toBe(true);
        });
    });
});
{'fraction_non_alphanumeric': 0.13935583215706404, 'fraction_numerical': 0.0007699217246246631, 'mean_word_length': 1.7443661971830986, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '1088129', 'n_tokens_mistral': 1998, 'n_tokens_neox': 1961, 'n_words': 416}