import { Injectable } from '@angular/core'; import { GCMockModule } from '@core/mocks/gc-module.mock'; import { Workflow, WorkflowDetail, WorkflowLevelPermissions } from '@core/typings/workflow.typing'; import { BeforeEach, Spec, TestCase } from '@yourcause/test-decorators'; import { DescribeAngularService } from '@yourcause/test-decorators/angular'; import { expect } from 'chai'; import { WorkflowResources } from './workflow.resources'; import { WorkflowService } from './workflow.service'; @Injectable({ providedIn: 'root' }) @DescribeAngularService(WorkflowService, { imports: [GCMockModule] }) export class WorkflowServiceSpec implements Spec { constructor ( private workflowResources: WorkflowResources ) { } workflowId = 25571; workflows: Workflow[] = [{ hasAutomationRules: false, levels: [{ subLevels: [], id: 25571, name: 'Workflow Level 1 - East', reviewRuleType: 0, description: 'Workflow Level 1 - East', allowDeclination: true, allowApproval: true, allowAward: false, allowUserToRequestRevision: true, allowUserToArchiveAndUnarchive: false, allowFormDueDateExtension: false, allowUserToViewAwardsAndPayments: true, allowRecommendedFunding: true, showMaskedApplicantInfo: false, showBudgetSummaryInfo: false, workflowLevelUsers: [{ clientUserId: 658941, firstName: 'Lori', lastName: 'Smith', email: 'lori+qa2@gdg.do', profileImage: '', workflowLevelAccessType: WorkflowLevelPermissions.PASSTHROUGH }], routes: [] }, { subLevels: [], id: 31071, name: 'Workflow Level 3 - North', reviewRuleType: 0, description: 'Workflow Level 3 - North', allowDeclination: true, allowApproval: true, allowUserToArchiveAndUnarchive: false, allowAward: true, allowUserToRequestRevision: true, allowFormDueDateExtension: false, allowUserToViewAwardsAndPayments: true, allowRecommendedFunding: true, showMaskedApplicantInfo: true, showBudgetSummaryInfo: false, workflowLevelUsers: [{ clientUserId: 658941, firstName: 'Lori', lastName: 'Smith', email: 'lori+qa2@gdg.do', profileImage: '', workflowLevelAccessType: WorkflowLevelPermissions.PASSTHROUGH }, { clientUserId: 660611, firstName: 'Dwight', lastName: 'Schrute', email: 'dwightjohnson2@mailinator.com', profileImage: '', workflowLevelAccessType: WorkflowLevelPermissions.PASSTHROUGH }], routes: [] }], id: 19726, name: 'Workflow with 2 Levels', description: 'Workflow with 2 Levels', active: true, hasApplications: true, workflowLevelManagers: [] }, { hasAutomationRules: false, levels: [{ subLevels: [{ id: 31918, name: 'Final Decision', reviewRuleType: 0, description: 'Final Decision', allowDeclination: true, allowApproval: true, allowAward: true, allowUserToRequestRevision: true, allowUserToViewAwardsAndPayments: true, showMaskedApplicantInfo: true, allowFormDueDateExtension: false, allowUserToArchiveAndUnarchive: false, allowRecommendedFunding: true, showBudgetSummaryInfo: false, workflowLevelUsers: [{ clientUserId: 660610, firstName: 'Michael', lastName: 'Scott', email: 'michaelscott2@mailinator.com', profileImage: '', workflowLevelAccessType: WorkflowLevelPermissions.PASSTHROUGH }, { clientUserId: 658941, firstName: 'Lori', lastName: 'Smith', email: 'lori+qa2@gdg.do', profileImage: '', workflowLevelAccessType: WorkflowLevelPermissions.PASSTHROUGH }, { clientUserId: 660608, firstName: 'Ben', lastName: 'Affleck', email: 'batman2@mailinator.com', profileImage: '', workflowLevelAccessType: WorkflowLevelPermissions.PASSTHROUGH }], routes: [] }], id: 31917, name: 'Review 1', reviewRuleType: 0, description: 'Review 1', allowDeclination: false, allowApproval: false, allowAward: false, allowUserToViewAwardsAndPayments: true, allowUserToArchiveAndUnarchive: false, allowUserToRequestRevision: true, allowFormDueDateExtension: false, allowRecommendedFunding: true, showMaskedApplicantInfo: false, showBudgetSummaryInfo: false, workflowLevelUsers: [{ clientUserId: 660609, firstName: 'Vince', lastName: 'Williams', email: 'vince.williams2@mailinator.com', profileImage: '', workflowLevelAccessType: WorkflowLevelPermissions.PASSTHROUGH }, { clientUserId: 658941, firstName: 'Lori', lastName: 'Smith', email: 'lori+qa2@gdg.do', profileImage: '', workflowLevelAccessType: WorkflowLevelPermissions.PASSTHROUGH }, { clientUserId: 660603, firstName: 'Meghan', lastName: 'Miles', email: 'meghanmiles2@mailinator.com', profileImage: '', workflowLevelAccessType: WorkflowLevelPermissions.PASSTHROUGH }, { clientUserId: 660608, firstName: 'Ben', lastName: 'Affleck', email: 'batman2@mailinator.com', profileImage: '', workflowLevelAccessType: WorkflowLevelPermissions.PASSTHROUGH }], routes: [] }], id: 24590, name: 'Community Grant Nomination Workflow w/sublevel', description: 'Community Grant Nomination Workflow', active: true, hasApplications: true, workflowLevelManagers: [] }]; workflowMap: { [w: string]: WorkflowDetail; } = { [this.workflowId]: { ...this.workflows[0], workflowLevelManagers: [] } }; @BeforeEach() async mock (service: WorkflowService) { (service as any).workflowResources = this.workflowResources; this.workflowResources.getWorkflows = async () => { return this.workflows; }; this.workflowResources.saveWorkflow = async () => { return 1; }; this.workflowResources.getWorkflow = async () => { return this.workflowMap[this.workflowId]; }; this.workflowResources.getMyWorkflowLevels = async () => { return []; }; } @TestCase('should be able to set workflows') async setWorkflowsTest (service: WorkflowService) { await service.getWorkflows(); const workflows = service.workflows; expect(workflows[0].id).to.be.equal(this.workflows[0].id); expect(workflows[1].levels[0].name).to.be.equal( this.workflows[1].levels[0].name ); } @TestCase('should be able to set workflow map') async setWorkflowMapTest (service: WorkflowService) { service.setWorkflowMap(this.workflowMap); const detail = service.get('workflowMap')[this.workflowId]; expect(detail.name).to.be.equal(this.workflowMap[this.workflowId].name); } @TestCase('should be able to reset workflow detail') async resetWorkflowDetailTest (service: WorkflowService) { await service.resetWorkflowDetail(this.workflowId); const detail = service.get('workflowMap')[this.workflowId]; expect(detail.active).to.be.equal(this.workflowMap[this.workflowId].active); expect(detail.name).to.be.equal(this.workflowMap[this.workflowId].name); } @TestCase('should be able to find WFL') async findWorkflowLevel (service: WorkflowService) { const found = service.findWorkflowLevel( service.workflowMap[this.workflowId], 31071 ); expect(found.name).to.be.equal('Workflow Level 3 - North'); } @TestCase('should be able to get workflow') async getAndSetWorkflow (service: WorkflowService) { await service.getAndSetWorkflow(this.workflowId); const hasWorkflow = !!service.workflowMap[this.workflowId]; expect(hasWorkflow).to.be.true; } }