2017-04-14 19:10:00 +00:00
|
|
|
import { ManageTriggerGithostComponent } from './manage-trigger-githost.component';
|
|
|
|
import { Local, Trigger, Repository } from '../../../types/common.types';
|
|
|
|
import { Mock } from 'ts-mocks';
|
|
|
|
import Spy = jasmine.Spy;
|
2017-02-18 09:45:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe("ManageTriggerGithostComponent", () => {
|
|
|
|
var component: ManageTriggerGithostComponent;
|
2017-04-14 19:10:00 +00:00
|
|
|
var apiServiceMock: Mock<any>;
|
|
|
|
var tableServiceMock: Mock<any>;
|
|
|
|
var triggerServiceMock: Mock<any>;
|
|
|
|
var rolesServiceMock: Mock<any>;
|
2017-02-18 09:45:00 +00:00
|
|
|
var repository: any;
|
|
|
|
var trigger: Trigger;
|
2017-04-14 19:10:00 +00:00
|
|
|
var $scopeMock: Mock<ng.IScope>;
|
2017-02-18 09:45:00 +00:00
|
|
|
|
2017-02-20 02:17:12 +00:00
|
|
|
beforeEach(inject(($injector: ng.auto.IInjectorService) => {
|
2017-04-14 19:10:00 +00:00
|
|
|
apiServiceMock = new Mock<any>();
|
|
|
|
tableServiceMock = new Mock<any>();
|
|
|
|
triggerServiceMock = new Mock<any>();
|
|
|
|
rolesServiceMock = new Mock<any>();
|
|
|
|
$scopeMock = new Mock<ng.IScope>();
|
|
|
|
component = new ManageTriggerGithostComponent(apiServiceMock.Object,
|
|
|
|
tableServiceMock.Object,
|
|
|
|
triggerServiceMock.Object,
|
|
|
|
rolesServiceMock.Object,
|
|
|
|
$scopeMock.Object);
|
2017-02-18 09:45:00 +00:00
|
|
|
trigger = {service: "serviceMock", id: 1};
|
|
|
|
component.trigger = trigger;
|
2017-02-20 02:17:12 +00:00
|
|
|
}));
|
2017-02-18 09:45:00 +00:00
|
|
|
|
|
|
|
describe("constructor", () => {
|
2017-02-23 01:22:34 +00:00
|
|
|
// TODO
|
2017-02-18 09:45:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("$onInit", () => {
|
2017-02-23 01:22:34 +00:00
|
|
|
// TODO
|
2017-02-18 09:45:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("getTriggerIcon", () => {
|
|
|
|
|
2017-04-14 19:10:00 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
triggerServiceMock.setup(mock => mock.getIcon).is((service: any) => null);
|
|
|
|
});
|
|
|
|
|
2017-02-18 09:45:00 +00:00
|
|
|
it("calls trigger service to get icon", () => {
|
2017-04-14 19:10:00 +00:00
|
|
|
const icon: any = component.getTriggerIcon();
|
2017-02-18 09:45:00 +00:00
|
|
|
|
2017-04-14 19:10:00 +00:00
|
|
|
expect((<Spy>triggerServiceMock.Object.getIcon).calls.argsFor(0)[0]).toEqual(component.trigger.service);
|
2017-02-18 09:45:00 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("createTrigger", () => {
|
2017-04-14 19:10:00 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
component.local.selectedRepository = new Mock<Repository>().Object;
|
|
|
|
component.local.selectedRepository.full_name = "someorg/some-repository";
|
|
|
|
component.local.dockerfilePath = "/Dockerfile";
|
|
|
|
component.local.dockerContext = "/";
|
|
|
|
component.local.triggerOptions = {};
|
|
|
|
component.local.triggerAnalysis = {};
|
|
|
|
rolesServiceMock.setup(mock => mock.setRepositoryRole).is((repo, role, entityKind, entityName, callback) => {
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("calls roles service to grant read access to selected robot if robot is required and cannot read", (done) => {
|
|
|
|
component.local.triggerAnalysis = {status: 'requiresrobot', name: 'privatebase', namespace: 'someorg'};
|
|
|
|
component.local.robotAccount = {can_read: false, is_robot: true, kind: 'user', name: 'test-robot'};
|
|
|
|
component.activateTrigger.subscribe((event: {config: any, pull_robot: any}) => {
|
|
|
|
expect((<Spy>rolesServiceMock.Object.setRepositoryRole).calls.argsFor(0)[0]).toEqual({
|
|
|
|
name: component.local.triggerAnalysis.name,
|
|
|
|
namespace: component.local.triggerAnalysis.namespace,
|
|
|
|
});
|
|
|
|
expect((<Spy>rolesServiceMock.Object.setRepositoryRole).calls.argsFor(0)[1]).toEqual('read');
|
|
|
|
expect((<Spy>rolesServiceMock.Object.setRepositoryRole).calls.argsFor(0)[2]).toEqual('robot');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
component.createTrigger();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not call roles service if robot is required but already has read access", (done) => {
|
|
|
|
component.local.robotAccount = {can_read: true, is_robot: true, kind: 'user', name: 'test-robot'};
|
|
|
|
component.activateTrigger.subscribe((event: {config: any, pull_robot: any}) => {
|
|
|
|
expect((<Spy>rolesServiceMock.Object.setRepositoryRole)).not.toHaveBeenCalled();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
component.createTrigger();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not call roles service if robot is not required", (done) => {
|
|
|
|
component.activateTrigger.subscribe((event: {config: any, pull_robot: any}) => {
|
|
|
|
expect((<Spy>rolesServiceMock.Object.setRepositoryRole)).not.toHaveBeenCalled();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
component.createTrigger();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("emits output event with config and pull robot", (done) => {
|
|
|
|
component.activateTrigger.subscribe((event: {config: any, pull_robot: any}) => {
|
|
|
|
expect(event.config.build_source).toEqual(component.local.selectedRepository.full_name);
|
|
|
|
expect(event.config.dockerfile_path).toEqual(component.local.dockerfilePath);
|
|
|
|
expect(event.config.context).toEqual(component.local.dockerContext);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
component.createTrigger();
|
|
|
|
});
|
2017-02-18 09:45:00 +00:00
|
|
|
});
|
|
|
|
});
|