import { Injectable } from '@angular/core'; import { CLIENT_SETTINGS_SERVICE_MOCK } from '@core/mocks/client-settings.service.mock'; import { GCMockModule } from '@core/mocks/gc-module.mock'; import { User } from '@core/typings/client-user.typing'; import { UserService } from '@features/users/user.service'; import { BeforeEach, Spec, TestCase } from '@yourcause/test-decorators'; import { DescribeAngularService } from '@yourcause/test-decorators/angular'; import { expect } from 'chai'; import { CardPageTypes, CardsService } from './cards.service'; @Injectable({ providedIn: 'root' }) @DescribeAngularService(CardsService, { imports: [ GCMockModule ], providers: [ CLIENT_SETTINGS_SERVICE_MOCK ] }) export class CardsServiceSpec implements Spec { noRolesUser: User = { roles: [] } as User; settingsRoleUser: User = { roles: [{ policies: [{ allow: true, clientRoleId: 2043, permissionSetType: 1, permissionType: 3 }], clientRoleId: 1, clientRoleName: 'client settings manager', clientRoleDescription: 'can manage client settings' }] } as User; programUser: User = { roles: [{ policies: [{ allow: true, clientRoleId: 13, permissionSetType: 2, permissionType: 2 }], clientRoleId: 1, clientRoleName: 'program settings manager', clientRoleDescription: 'can manage program settings' }] } as User; insightsUser: User = { roles: [{ policies: [{ allow: true, clientRoleId: 13, permissionSetType: 6, permissionType: 2 }], clientRoleId: 1, clientRoleName: 'insights', clientRoleDescription: 'can see insights' }] } as User; constructor ( private userService: UserService ) { } @BeforeEach() mock (service: CardsService) { service['userService'] = this.userService; } @TestCase('should be able to get can see page - settings - fail') canSeePageSettingsFail (service: CardsService) { this.userService.setUser(this.noRolesUser); const canSee = service.canSeePage(CardPageTypes.SETTINGS); expect(canSee).to.be.false; } @TestCase('should be able to get can see page - settings - pass') canSeePageSettingsPass (service: CardsService) { this.userService.setUser(this.settingsRoleUser); const canSee = service.canSeePage(CardPageTypes.SETTINGS); expect(canSee).to.be.true; } @TestCase('should be able to get can see page - programs - fail') canSeePageProgramsFail (service: CardsService) { this.userService.setUser(this.noRolesUser); const canSee = service.canSeePage(CardPageTypes.PROGRAM); expect(canSee).to.be.false; } @TestCase('should be able to get can see page - programs - pass') canSeePageProgramsPass (service: CardsService) { this.userService.setUser(this.programUser); const canSee = service.canSeePage(CardPageTypes.PROGRAM); expect(canSee).to.be.true; } @TestCase('should be able to get can see page - insights - fail') canSeePageInsightsFail (service: CardsService) { this.userService.setUser(this.noRolesUser); const canSee = service.canSeePage(CardPageTypes.INSIGHTS); expect(canSee).to.be.false; } @TestCase('should be able to get can see page - insights - pass') canSeePageInsightsPass (service: CardsService) { this.userService.setUser(this.insightsUser); const canSee = service.canSeePage(CardPageTypes.INSIGHTS); expect(canSee).to.be.true; } }