|
| 1 | +import { Test, TestingModule } from '@nestjs/testing'; |
| 2 | +import { createMock, DeepMocked } from '@golevelup/nestjs-testing'; |
| 3 | +import { NoticeOfIntentDecisionConditionCardController } from './notice-of-intent-decision-condition-card.controller'; |
| 4 | +import { NoticeOfIntentDecisionConditionCardService } from './notice-of-intent-decision-condition-card.service'; |
| 5 | +import { NoticeOfIntentModificationService } from '../../notice-of-intent-modification/notice-of-intent-modification.service'; |
| 6 | +import { NoticeOfIntentDecisionV2Service } from '../../notice-of-intent-decision-v2/notice-of-intent-decision-v2.service'; |
| 7 | +import { NoticeOfIntentDecisionConditionCard } from './notice-of-intent-decision-condition-card.entity'; |
| 8 | +import { classes } from 'automapper-classes'; |
| 9 | +import { ClsService } from 'nestjs-cls'; |
| 10 | +import { mockKeyCloakProviders } from '../../../../../test/mocks/mockTypes'; |
| 11 | +import { AutomapperModule } from 'automapper-nestjs'; |
| 12 | +import { NoticeOfIntentDecisionProfile } from '../../../../common/automapper/notice-of-intent-decision.automapper.profile'; |
| 13 | +import { |
| 14 | + CreateNoticeOfIntentDecisionConditionCardDto, |
| 15 | + NoticeOfIntentDecisionConditionCardBoardDto, |
| 16 | + NoticeOfIntentDecisionConditionCardDto, |
| 17 | + UpdateNoticeOfIntentDecisionConditionCardDto, |
| 18 | +} from './notice-of-intent-decision-condition-card.dto'; |
| 19 | + |
| 20 | +describe('NoticeOfIntentDecisionConditionCardController', () => { |
| 21 | + let controller: NoticeOfIntentDecisionConditionCardController; |
| 22 | + let mockService: DeepMocked<NoticeOfIntentDecisionConditionCardService>; |
| 23 | + let mockModificationService: DeepMocked<NoticeOfIntentModificationService>; |
| 24 | + let mockDecisionService: DeepMocked<NoticeOfIntentDecisionV2Service>; |
| 25 | + |
| 26 | + beforeEach(async () => { |
| 27 | + mockService = createMock(); |
| 28 | + mockModificationService = createMock(); |
| 29 | + mockDecisionService = createMock(); |
| 30 | + |
| 31 | + const module: TestingModule = await Test.createTestingModule({ |
| 32 | + imports: [ |
| 33 | + AutomapperModule.forRoot({ |
| 34 | + strategyInitializer: classes(), |
| 35 | + }), |
| 36 | + ], |
| 37 | + controllers: [NoticeOfIntentDecisionConditionCardController], |
| 38 | + providers: [ |
| 39 | + { |
| 40 | + provide: NoticeOfIntentDecisionConditionCardService, |
| 41 | + useValue: mockService, |
| 42 | + }, |
| 43 | + { |
| 44 | + provide: NoticeOfIntentModificationService, |
| 45 | + useValue: mockModificationService, |
| 46 | + }, |
| 47 | + { |
| 48 | + provide: NoticeOfIntentDecisionV2Service, |
| 49 | + useValue: mockDecisionService, |
| 50 | + }, |
| 51 | + { |
| 52 | + provide: ClsService, |
| 53 | + useValue: {}, |
| 54 | + }, |
| 55 | + NoticeOfIntentDecisionProfile, |
| 56 | + ...mockKeyCloakProviders, |
| 57 | + ], |
| 58 | + }).compile(); |
| 59 | + |
| 60 | + controller = module.get<NoticeOfIntentDecisionConditionCardController>( |
| 61 | + NoticeOfIntentDecisionConditionCardController, |
| 62 | + ); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should be defined', () => { |
| 66 | + expect(controller).toBeDefined(); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should return a condition card', async () => { |
| 70 | + const uuid = 'example-uuid'; |
| 71 | + const conditionCard = new NoticeOfIntentDecisionConditionCard(); |
| 72 | + conditionCard.decision = { uuid: 'decision-uuid' } as any; |
| 73 | + mockService.get.mockResolvedValue(conditionCard); |
| 74 | + |
| 75 | + const result = await controller.get(uuid); |
| 76 | + |
| 77 | + expect(mockService.get).toHaveBeenCalledWith(uuid); |
| 78 | + expect(result).toBeInstanceOf(NoticeOfIntentDecisionConditionCardDto); |
| 79 | + }); |
| 80 | + |
| 81 | + it('should create a new condition card', async () => { |
| 82 | + const dto: CreateNoticeOfIntentDecisionConditionCardDto = { |
| 83 | + conditionsUuids: ['condition-uuid-1', 'condition-uuid-2'], |
| 84 | + decisionUuid: 'decision-uuid', |
| 85 | + cardStatusCode: 'status-code', |
| 86 | + }; |
| 87 | + const conditionCard = new NoticeOfIntentDecisionConditionCard(); |
| 88 | + conditionCard.decision = { uuid: 'decision-uuid' } as any; |
| 89 | + mockService.create.mockResolvedValue(conditionCard); |
| 90 | + |
| 91 | + const result = await controller.create(dto); |
| 92 | + |
| 93 | + expect(mockService.create).toHaveBeenCalledWith(dto); |
| 94 | + expect(result).toBeInstanceOf(NoticeOfIntentDecisionConditionCardDto); |
| 95 | + }); |
| 96 | + |
| 97 | + it('should update the condition card and return updated card', async () => { |
| 98 | + const uuid = 'example-uuid'; |
| 99 | + const dto: UpdateNoticeOfIntentDecisionConditionCardDto = { |
| 100 | + conditionsUuids: ['condition-uuid-1', 'condition-uuid-2'], |
| 101 | + cardStatusCode: 'updated-status-code', |
| 102 | + }; |
| 103 | + const conditionCard = new NoticeOfIntentDecisionConditionCard(); |
| 104 | + conditionCard.decision = { uuid: 'decision-uuid' } as any; |
| 105 | + mockService.update.mockResolvedValue(conditionCard); |
| 106 | + |
| 107 | + const result = await controller.update(uuid, dto); |
| 108 | + |
| 109 | + expect(mockService.update).toHaveBeenCalledWith(uuid, dto); |
| 110 | + expect(result).toBeInstanceOf(NoticeOfIntentDecisionConditionCardDto); |
| 111 | + }); |
| 112 | + |
| 113 | + it('should return a condition card by board card uuid', async () => { |
| 114 | + const uuid = 'example-uuid'; |
| 115 | + const conditionCard = new NoticeOfIntentDecisionConditionCard(); |
| 116 | + conditionCard.decision = { uuid: 'decision-uuid', noticeOfIntent: { fileNumber: 'file-number' } } as any; |
| 117 | + |
| 118 | + mockService.getByBoardCard.mockResolvedValue(conditionCard); |
| 119 | + mockModificationService.getByNoticeOfIntentDecisionUuid.mockResolvedValue([]); |
| 120 | + mockDecisionService.getDecisionOrder.mockResolvedValue(1); |
| 121 | + |
| 122 | + const result = await controller.getByCardUuid(uuid); |
| 123 | + |
| 124 | + expect(mockService.getByBoardCard).toHaveBeenCalledWith(uuid); |
| 125 | + expect(result).toBeInstanceOf(NoticeOfIntentDecisionConditionCardBoardDto); |
| 126 | + expect(result.fileNumber).toEqual('file-number'); |
| 127 | + }); |
| 128 | + |
| 129 | + it('should return condition cards by application file number', async () => { |
| 130 | + const fileNumber = 'example-file-number'; |
| 131 | + const conditionCard = new NoticeOfIntentDecisionConditionCard(); |
| 132 | + conditionCard.decision = { uuid: 'decision-uuid' } as any; |
| 133 | + mockDecisionService.getForDecisionConditionCardsByFileNumber.mockResolvedValue([conditionCard]); |
| 134 | + |
| 135 | + const result = await controller.getByApplicationFileNumber(fileNumber); |
| 136 | + |
| 137 | + expect(mockDecisionService.getForDecisionConditionCardsByFileNumber).toHaveBeenCalledWith(fileNumber); |
| 138 | + expect(result).toBeInstanceOf(Array); |
| 139 | + expect(result[0]).toBeInstanceOf(NoticeOfIntentDecisionConditionCardDto); |
| 140 | + }); |
| 141 | +}); |
0 commit comments