Sha256: e1ecf3bed0d957a4a9e5c68d36b7e806b5c060bdd4e5ede36dea8dd42c64e6b9

Contents?: true

Size: 1.95 KB

Versions: 55

Compression:

Stored size: 1.95 KB

Contents

describe('Service:Authorization', function() {
    var Authorization, CurrentUser, Permissions;

    beforeEach(module('Bastion.auth', 'Bastion.test-mocks'));

    beforeEach(module(function($provide) {
        CurrentUser = {};
        Permissions = [{permission: {name: 'view_tests'}}];

        $provide.value('CurrentUser', CurrentUser);
        $provide.value('Permissions', Permissions);
    }));

    beforeEach(inject(function(_Permissions_, _Authorization_) {
        Permissions = _Permissions_;
        Authorization = _Authorization_;
    }));

    describe("provides a function determines if the user has permission to perform an action", function () {
        it("which returns true if the user is an admin", function () {
            CurrentUser.admin = true;
            expect(Authorization.permitted('randomPermission')).toBe(true);
        });

        describe("which checks for the permission in the provided model", function () {
            var model = {permissions: {}};

            it("and succeeds", function () {
                model.permissions.view_tests = true;
                expect(Authorization.permitted('view_tests', model)).toBe(true);
            });

            it("and fails", function () {
                model.permissions.view_tests = false;
                expect(Authorization.permitted('view_tests', model)).toBe(false);
                expect(Authorization.permitted('view_results', model)).toBe(false);
            });
        });

        describe("which checks if the permission name is in the Permissions list", function () {
            it("and succeeds", function () {
                expect(Authorization.permitted('view_tests')).toBe(true);
            });

            it("and fails", function () {
                expect(Authorization.permitted('view_results')).toBe(false);
            });
        });
    });

    it("returns the current user", function () {
        expect(Authorization.getCurrentUser()).toBe(CurrentUser);
    });
});

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
bastion-6.1.23 test/auth/authorization.service.test.js
bastion-6.1.22 test/auth/authorization.service.test.js
bastion-6.1.21 test/auth/authorization.service.test.js
bastion-6.1.20 test/auth/authorization.service.test.js
bastion-6.1.19 test/auth/authorization.service.test.js
bastion-6.1.18 test/auth/authorization.service.test.js
bastion-6.1.17 test/auth/authorization.service.test.js
bastion-6.1.16 test/auth/authorization.service.test.js
bastion-6.1.15 test/auth/authorization.service.test.js
bastion-6.1.14 test/auth/authorization.service.test.js
bastion-6.1.13 test/auth/authorization.service.test.js
bastion-6.1.12 test/auth/authorization.service.test.js
bastion-6.1.11 test/auth/authorization.service.test.js
bastion-6.1.10 test/auth/authorization.service.test.js
bastion-6.1.9 test/auth/authorization.service.test.js
bastion-6.1.8 test/auth/authorization.service.test.js
bastion-6.1.7 test/auth/authorization.service.test.js
bastion-6.1.6 test/auth/authorization.service.test.js
bastion-6.1.5 test/auth/authorization.service.test.js
bastion-6.1.4 test/auth/authorization.service.test.js