Skip to content

Commit 0573c26

Browse files
authored
Merge pull request #2014 from bcgov/feature/ALCS-2404-2
QA Fix: Fix Admin Condition Type Code Check on Deleted Items
2 parents 4ae5c7f + dd29074 commit 0573c26

10 files changed

+98
-27
lines changed

alcs-frontend/src/app/features/admin/decision-condition-types/decision-condition-types.component.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class DecisionConditionTypesComponent implements OnInit {
2929
destroy = new Subject<void>();
3030

3131
decisionConditionTypeDtos: ApplicationDecisionConditionTypeDto[] | NoticeOfIntentDecisionConditionTypeDto[] = [];
32+
decisionConditionTypeCodeDtos: string[] = [];
3233
displayedColumns: string[] = ['label', 'description', 'code', 'isActive', 'actions'];
3334

3435
constructor(
@@ -43,6 +44,7 @@ export class DecisionConditionTypesComponent implements OnInit {
4344
async fetch() {
4445
if (!this.service) return;
4546
this.decisionConditionTypeDtos = await this.service.fetch();
47+
this.decisionConditionTypeCodeDtos = await this.service.fetchCodesWithDeleted();
4648
}
4749

4850
async onCreate() {
@@ -53,7 +55,7 @@ export class DecisionConditionTypesComponent implements OnInit {
5355
data: {
5456
service: this.service,
5557
conditionService: this.conditionService,
56-
existingCodes: this.decisionConditionTypeDtos.map((dct) => dct.code),
58+
existingCodes: this.decisionConditionTypeCodeDtos,
5759
},
5860
});
5961
dialog.beforeClosed().subscribe(async (result) => {
@@ -72,7 +74,7 @@ export class DecisionConditionTypesComponent implements OnInit {
7274
service: this.service,
7375
conditionService: this.conditionService,
7476
content: dto,
75-
existingCodes: this.decisionConditionTypeDtos.map((dct) => dct.code),
77+
existingCodes: this.decisionConditionTypeCodeDtos,
7678
},
7779
});
7880
dialog.beforeClosed().subscribe(async (result) => {

alcs-frontend/src/app/services/application/application-decision-condition-types/application-decision-condition-types.service.ts

+10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ export class ApplicationDecisionConditionTypesService {
2626
return [];
2727
}
2828

29+
async fetchCodesWithDeleted() {
30+
try {
31+
return await firstValueFrom(this.http.get<string[]>(`${this.url}/codes`));
32+
} catch (err) {
33+
console.error(err);
34+
this.toastService.showErrorToast('Failed to fetch decision condition type codes');
35+
}
36+
return [];
37+
}
38+
2939
async create(createDto: ApplicationDecisionConditionTypeDto) {
3040
try {
3141
return await firstValueFrom(this.http.post<ApplicationDecisionConditionTypeDto>(`${this.url}`, createDto));

alcs-frontend/src/app/services/notice-of-intent/notice-of-intent-decision-condition-types/notice-of-intent-decision-condition-types.service.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import { NoticeOfIntentDecisionConditionTypeDto } from '../decision-v2/notice-of
1111
export class NoticeofIntentDecisionConditionTypesService {
1212
private url = `${environment.apiUrl}/noi-decision-condition-types`;
1313

14-
constructor(private http: HttpClient, private toastService: ToastService) {}
14+
constructor(
15+
private http: HttpClient,
16+
private toastService: ToastService,
17+
) {}
1518

1619
async fetch() {
1720
try {
@@ -23,6 +26,16 @@ export class NoticeofIntentDecisionConditionTypesService {
2326
return [];
2427
}
2528

29+
async fetchCodesWithDeleted() {
30+
try {
31+
return await firstValueFrom(this.http.get<string[]>(`${this.url}/codes`));
32+
} catch (err) {
33+
console.error(err);
34+
this.toastService.showErrorToast('Failed to fetch decision condition type codes');
35+
}
36+
return [];
37+
}
38+
2639
async create(createDto: NoticeOfIntentDecisionConditionTypeDto) {
2740
try {
2841
return await firstValueFrom(this.http.post<NoticeOfIntentDecisionConditionTypeDto>(`${this.url}`, createDto));
@@ -36,7 +49,7 @@ export class NoticeofIntentDecisionConditionTypesService {
3649
async update(code: string, updateDto: NoticeOfIntentDecisionConditionTypeDto) {
3750
try {
3851
return await firstValueFrom(
39-
this.http.patch<NoticeOfIntentDecisionConditionTypeDto>(`${this.url}/${code}`, updateDto)
52+
this.http.patch<NoticeOfIntentDecisionConditionTypeDto>(`${this.url}/${code}`, updateDto),
4053
);
4154
} catch (e) {
4255
this.toastService.showErrorToast('Failed to update decision condition type');

services/apps/alcs/src/alcs/admin/application-decision-condition-types/application-decision-condition-types.controller.spec.ts

+14-16
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ describe('ApplicationDecisionConditionTypesController', () => {
3030
imports: [ConfigModule],
3131
}).compile();
3232

33-
controller = module.get<ApplicationDecisionConditionTypesController>(
34-
ApplicationDecisionConditionTypesController,
35-
);
33+
controller = module.get<ApplicationDecisionConditionTypesController>(ApplicationDecisionConditionTypesController);
3634
});
3735

3836
it('should be defined', () => {
@@ -48,28 +46,28 @@ describe('ApplicationDecisionConditionTypesController', () => {
4846
expect(mockDecTypesService.fetch).toHaveBeenCalledTimes(1);
4947
});
5048

49+
it('should call out to service when fetching decision condition type codes', async () => {
50+
mockDecTypesService.fetchCodesWithDeleted.mockResolvedValue([]);
51+
52+
const applicationDecisionConditionTypeCodes = await controller.fetchCodesWithDeleted();
53+
54+
expect(applicationDecisionConditionTypeCodes).toBeDefined();
55+
expect(mockDecTypesService.fetchCodesWithDeleted).toHaveBeenCalledTimes(1);
56+
});
57+
5158
it('should call out to service when updating decision condition type', async () => {
52-
mockDecTypesService.update.mockResolvedValue(
53-
new ApplicationDecisionConditionType(),
54-
);
59+
mockDecTypesService.update.mockResolvedValue(new ApplicationDecisionConditionType());
5560

56-
const applicationDecisionConditionType = await controller.update(
57-
'fake',
58-
new ApplicationDecisionConditionType(),
59-
);
61+
const applicationDecisionConditionType = await controller.update('fake', new ApplicationDecisionConditionType());
6062

6163
expect(applicationDecisionConditionType).toBeDefined();
6264
expect(mockDecTypesService.update).toHaveBeenCalledTimes(1);
6365
});
6466

6567
it('should call out to service when creating decision condition type', async () => {
66-
mockDecTypesService.create.mockResolvedValue(
67-
new ApplicationDecisionConditionType(),
68-
);
68+
mockDecTypesService.create.mockResolvedValue(new ApplicationDecisionConditionType());
6969

70-
const applicationDecisionConditionType = await controller.create(
71-
new ApplicationDecisionConditionType(),
72-
);
70+
const applicationDecisionConditionType = await controller.create(new ApplicationDecisionConditionType());
7371

7472
expect(applicationDecisionConditionType).toBeDefined();
7573
expect(mockDecTypesService.create).toHaveBeenCalledTimes(1);

services/apps/alcs/src/alcs/admin/application-decision-condition-types/application-decision-condition-types.controller.ts

+6
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@ export class ApplicationDecisionConditionTypesController {
3636
async create(@Body() createDto: ApplicationDecisionConditionTypeDto) {
3737
return await this.applicationDecisionConditionTypesService.create(createDto);
3838
}
39+
40+
@Get('/codes')
41+
@UserRoles(AUTH_ROLE.ADMIN)
42+
async fetchCodesWithDeleted() {
43+
return (await this.applicationDecisionConditionTypesService.fetchCodesWithDeleted()).map((adct) => adct.code);
44+
}
3945
}

services/apps/alcs/src/alcs/admin/application-decision-condition-types/application-decision-condition-types.service.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,13 @@ describe('ApplicationDecisionConditionTypesService', () => {
131131
expect(mockRepository.find).toBeCalledTimes(1);
132132
expect(result).toBeDefined();
133133
});
134+
135+
it('should successfully fetch decision condition type code', async () => {
136+
mockRepository.find.mockResolvedValue([type]);
137+
138+
const result = await service.fetchCodesWithDeleted();
139+
140+
expect(mockRepository.find).toHaveBeenCalledTimes(1);
141+
expect(result).toBeDefined();
142+
});
134143
});

services/apps/alcs/src/alcs/admin/application-decision-condition-types/application-decision-condition-types.service.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class ApplicationDecisionConditionTypesService {
2020
private applicationDecisionConditionTypeRepository: Repository<ApplicationDecisionConditionType>,
2121
) {}
2222

23-
async fetch() {
23+
async fetch(includeDeleted: boolean = false) {
2424
return await this.applicationDecisionConditionTypeRepository.find({
2525
order: { label: 'ASC' },
2626
select: {
@@ -43,6 +43,15 @@ export class ApplicationDecisionConditionTypesService {
4343
});
4444
}
4545

46+
async fetchCodesWithDeleted() {
47+
return await this.applicationDecisionConditionTypeRepository.find({
48+
select: {
49+
code: true,
50+
},
51+
withDeleted: true,
52+
});
53+
}
54+
4655
async getOneOrFail(code: string) {
4756
return await this.applicationDecisionConditionTypeRepository.findOneOrFail({
4857
where: { code },

services/apps/alcs/src/alcs/admin/notice-of-intent-decision-condition-types/notice-of-intent-decision-condition-types.controller.spec.ts

+15-6
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,36 @@ describe('NoticeofIntentDecisionConditionTypesController', () => {
4242
it('should call out to service when fetching decision condition type', async () => {
4343
mockDecTypesService.fetch.mockResolvedValue([]);
4444

45-
const applicationDecisionConditionTypes = await controller.fetch();
45+
const noiDecisionConditionTypes = await controller.fetch();
4646

47-
expect(applicationDecisionConditionTypes).toBeDefined();
47+
expect(noiDecisionConditionTypes).toBeDefined();
4848
expect(mockDecTypesService.fetch).toHaveBeenCalledTimes(1);
4949
});
5050

51+
it('should call out to service when fetching decision condition type codes', async () => {
52+
mockDecTypesService.fetchCodesWithDeleted.mockResolvedValue([]);
53+
54+
const noiDecisionConditionTypeCodes = await controller.fetchCodesWithDeleted();
55+
56+
expect(noiDecisionConditionTypeCodes).toBeDefined();
57+
expect(mockDecTypesService.fetchCodesWithDeleted).toHaveBeenCalledTimes(1);
58+
});
59+
5160
it('should call out to service when updating decision condition type', async () => {
5261
mockDecTypesService.update.mockResolvedValue(new NoticeOfIntentDecisionConditionType());
5362

54-
const applicationDecisionConditionType = await controller.update('fake', new NoticeOfIntentDecisionConditionType());
63+
const noiDecisionConditionType = await controller.update('fake', new NoticeOfIntentDecisionConditionType());
5564

56-
expect(applicationDecisionConditionType).toBeDefined();
65+
expect(noiDecisionConditionType).toBeDefined();
5766
expect(mockDecTypesService.update).toHaveBeenCalledTimes(1);
5867
});
5968

6069
it('should call out to service when creating decision condition type', async () => {
6170
mockDecTypesService.create.mockResolvedValue(new NoticeOfIntentDecisionConditionType());
6271

63-
const applicationDecisionConditionType = await controller.create(new NoticeOfIntentDecisionConditionType());
72+
const noiDecisionConditionType = await controller.create(new NoticeOfIntentDecisionConditionType());
6473

65-
expect(applicationDecisionConditionType).toBeDefined();
74+
expect(noiDecisionConditionType).toBeDefined();
6675
expect(mockDecTypesService.create).toHaveBeenCalledTimes(1);
6776
});
6877
});

services/apps/alcs/src/alcs/admin/notice-of-intent-decision-condition-types/notice-of-intent-decision-condition-types.controller.ts

+6
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@ export class NoticeofIntentDecisionConditionTypesController {
3636
async create(@Body() createDto: NoticeOfIntentDecisionConditionTypeDto) {
3737
return await this.noiDecisionConditionTypesService.create(createDto);
3838
}
39+
40+
@Get('/codes')
41+
@UserRoles(AUTH_ROLE.ADMIN)
42+
async fetchCodesWithDeleted() {
43+
return (await this.noiDecisionConditionTypesService.fetchCodesWithDeleted()).map((ndct) => ndct.code);
44+
}
3945
}

services/apps/alcs/src/alcs/admin/notice-of-intent-decision-condition-types/notice-of-intent-decision-condition-types.service.ts

+9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ export class NoticeofIntentDecisionConditionTypesService {
4141
});
4242
}
4343

44+
async fetchCodesWithDeleted() {
45+
return await this.noiDecisionConditionTypeRepository.find({
46+
select: {
47+
code: true,
48+
},
49+
withDeleted: true,
50+
});
51+
}
52+
4453
async getOneOrFail(code: string) {
4554
return await this.noiDecisionConditionTypeRepository.findOneOrFail({
4655
where: { code },

0 commit comments

Comments
 (0)