Skip to content

Commit

Permalink
Merge pull request #2014 from bcgov/feature/ALCS-2404-2
Browse files Browse the repository at this point in the history
QA Fix: Fix Admin Condition Type Code Check on Deleted Items
  • Loading branch information
Abradat authored Dec 12, 2024
2 parents 4ae5c7f + dd29074 commit 0573c26
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class DecisionConditionTypesComponent implements OnInit {
destroy = new Subject<void>();

decisionConditionTypeDtos: ApplicationDecisionConditionTypeDto[] | NoticeOfIntentDecisionConditionTypeDto[] = [];
decisionConditionTypeCodeDtos: string[] = [];
displayedColumns: string[] = ['label', 'description', 'code', 'isActive', 'actions'];

constructor(
Expand All @@ -43,6 +44,7 @@ export class DecisionConditionTypesComponent implements OnInit {
async fetch() {
if (!this.service) return;
this.decisionConditionTypeDtos = await this.service.fetch();
this.decisionConditionTypeCodeDtos = await this.service.fetchCodesWithDeleted();
}

async onCreate() {
Expand All @@ -53,7 +55,7 @@ export class DecisionConditionTypesComponent implements OnInit {
data: {
service: this.service,
conditionService: this.conditionService,
existingCodes: this.decisionConditionTypeDtos.map((dct) => dct.code),
existingCodes: this.decisionConditionTypeCodeDtos,
},
});
dialog.beforeClosed().subscribe(async (result) => {
Expand All @@ -72,7 +74,7 @@ export class DecisionConditionTypesComponent implements OnInit {
service: this.service,
conditionService: this.conditionService,
content: dto,
existingCodes: this.decisionConditionTypeDtos.map((dct) => dct.code),
existingCodes: this.decisionConditionTypeCodeDtos,
},
});
dialog.beforeClosed().subscribe(async (result) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ export class ApplicationDecisionConditionTypesService {
return [];
}

async fetchCodesWithDeleted() {
try {
return await firstValueFrom(this.http.get<string[]>(`${this.url}/codes`));
} catch (err) {
console.error(err);
this.toastService.showErrorToast('Failed to fetch decision condition type codes');
}
return [];
}

async create(createDto: ApplicationDecisionConditionTypeDto) {
try {
return await firstValueFrom(this.http.post<ApplicationDecisionConditionTypeDto>(`${this.url}`, createDto));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import { NoticeOfIntentDecisionConditionTypeDto } from '../decision-v2/notice-of
export class NoticeofIntentDecisionConditionTypesService {
private url = `${environment.apiUrl}/noi-decision-condition-types`;

constructor(private http: HttpClient, private toastService: ToastService) {}
constructor(
private http: HttpClient,
private toastService: ToastService,
) {}

async fetch() {
try {
Expand All @@ -23,6 +26,16 @@ export class NoticeofIntentDecisionConditionTypesService {
return [];
}

async fetchCodesWithDeleted() {
try {
return await firstValueFrom(this.http.get<string[]>(`${this.url}/codes`));
} catch (err) {
console.error(err);
this.toastService.showErrorToast('Failed to fetch decision condition type codes');
}
return [];
}

async create(createDto: NoticeOfIntentDecisionConditionTypeDto) {
try {
return await firstValueFrom(this.http.post<NoticeOfIntentDecisionConditionTypeDto>(`${this.url}`, createDto));
Expand All @@ -36,7 +49,7 @@ export class NoticeofIntentDecisionConditionTypesService {
async update(code: string, updateDto: NoticeOfIntentDecisionConditionTypeDto) {
try {
return await firstValueFrom(
this.http.patch<NoticeOfIntentDecisionConditionTypeDto>(`${this.url}/${code}`, updateDto)
this.http.patch<NoticeOfIntentDecisionConditionTypeDto>(`${this.url}/${code}`, updateDto),
);
} catch (e) {
this.toastService.showErrorToast('Failed to update decision condition type');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ describe('ApplicationDecisionConditionTypesController', () => {
imports: [ConfigModule],
}).compile();

controller = module.get<ApplicationDecisionConditionTypesController>(
ApplicationDecisionConditionTypesController,
);
controller = module.get<ApplicationDecisionConditionTypesController>(ApplicationDecisionConditionTypesController);
});

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

it('should call out to service when fetching decision condition type codes', async () => {
mockDecTypesService.fetchCodesWithDeleted.mockResolvedValue([]);

const applicationDecisionConditionTypeCodes = await controller.fetchCodesWithDeleted();

expect(applicationDecisionConditionTypeCodes).toBeDefined();
expect(mockDecTypesService.fetchCodesWithDeleted).toHaveBeenCalledTimes(1);
});

it('should call out to service when updating decision condition type', async () => {
mockDecTypesService.update.mockResolvedValue(
new ApplicationDecisionConditionType(),
);
mockDecTypesService.update.mockResolvedValue(new ApplicationDecisionConditionType());

const applicationDecisionConditionType = await controller.update(
'fake',
new ApplicationDecisionConditionType(),
);
const applicationDecisionConditionType = await controller.update('fake', new ApplicationDecisionConditionType());

expect(applicationDecisionConditionType).toBeDefined();
expect(mockDecTypesService.update).toHaveBeenCalledTimes(1);
});

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

const applicationDecisionConditionType = await controller.create(
new ApplicationDecisionConditionType(),
);
const applicationDecisionConditionType = await controller.create(new ApplicationDecisionConditionType());

expect(applicationDecisionConditionType).toBeDefined();
expect(mockDecTypesService.create).toHaveBeenCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ export class ApplicationDecisionConditionTypesController {
async create(@Body() createDto: ApplicationDecisionConditionTypeDto) {
return await this.applicationDecisionConditionTypesService.create(createDto);
}

@Get('/codes')
@UserRoles(AUTH_ROLE.ADMIN)
async fetchCodesWithDeleted() {
return (await this.applicationDecisionConditionTypesService.fetchCodesWithDeleted()).map((adct) => adct.code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,13 @@ describe('ApplicationDecisionConditionTypesService', () => {
expect(mockRepository.find).toBeCalledTimes(1);
expect(result).toBeDefined();
});

it('should successfully fetch decision condition type code', async () => {
mockRepository.find.mockResolvedValue([type]);

const result = await service.fetchCodesWithDeleted();

expect(mockRepository.find).toHaveBeenCalledTimes(1);
expect(result).toBeDefined();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class ApplicationDecisionConditionTypesService {
private applicationDecisionConditionTypeRepository: Repository<ApplicationDecisionConditionType>,
) {}

async fetch() {
async fetch(includeDeleted: boolean = false) {
return await this.applicationDecisionConditionTypeRepository.find({
order: { label: 'ASC' },
select: {
Expand All @@ -43,6 +43,15 @@ export class ApplicationDecisionConditionTypesService {
});
}

async fetchCodesWithDeleted() {
return await this.applicationDecisionConditionTypeRepository.find({
select: {
code: true,
},
withDeleted: true,
});
}

async getOneOrFail(code: string) {
return await this.applicationDecisionConditionTypeRepository.findOneOrFail({
where: { code },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,36 @@ describe('NoticeofIntentDecisionConditionTypesController', () => {
it('should call out to service when fetching decision condition type', async () => {
mockDecTypesService.fetch.mockResolvedValue([]);

const applicationDecisionConditionTypes = await controller.fetch();
const noiDecisionConditionTypes = await controller.fetch();

expect(applicationDecisionConditionTypes).toBeDefined();
expect(noiDecisionConditionTypes).toBeDefined();
expect(mockDecTypesService.fetch).toHaveBeenCalledTimes(1);
});

it('should call out to service when fetching decision condition type codes', async () => {
mockDecTypesService.fetchCodesWithDeleted.mockResolvedValue([]);

const noiDecisionConditionTypeCodes = await controller.fetchCodesWithDeleted();

expect(noiDecisionConditionTypeCodes).toBeDefined();
expect(mockDecTypesService.fetchCodesWithDeleted).toHaveBeenCalledTimes(1);
});

it('should call out to service when updating decision condition type', async () => {
mockDecTypesService.update.mockResolvedValue(new NoticeOfIntentDecisionConditionType());

const applicationDecisionConditionType = await controller.update('fake', new NoticeOfIntentDecisionConditionType());
const noiDecisionConditionType = await controller.update('fake', new NoticeOfIntentDecisionConditionType());

expect(applicationDecisionConditionType).toBeDefined();
expect(noiDecisionConditionType).toBeDefined();
expect(mockDecTypesService.update).toHaveBeenCalledTimes(1);
});

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

const applicationDecisionConditionType = await controller.create(new NoticeOfIntentDecisionConditionType());
const noiDecisionConditionType = await controller.create(new NoticeOfIntentDecisionConditionType());

expect(applicationDecisionConditionType).toBeDefined();
expect(noiDecisionConditionType).toBeDefined();
expect(mockDecTypesService.create).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ export class NoticeofIntentDecisionConditionTypesController {
async create(@Body() createDto: NoticeOfIntentDecisionConditionTypeDto) {
return await this.noiDecisionConditionTypesService.create(createDto);
}

@Get('/codes')
@UserRoles(AUTH_ROLE.ADMIN)
async fetchCodesWithDeleted() {
return (await this.noiDecisionConditionTypesService.fetchCodesWithDeleted()).map((ndct) => ndct.code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ export class NoticeofIntentDecisionConditionTypesService {
});
}

async fetchCodesWithDeleted() {
return await this.noiDecisionConditionTypeRepository.find({
select: {
code: true,
},
withDeleted: true,
});
}

async getOneOrFail(code: string) {
return await this.noiDecisionConditionTypeRepository.findOneOrFail({
where: { code },
Expand Down

0 comments on commit 0573c26

Please sign in to comment.