Skip to content

Commit

Permalink
Merge pull request #881 from bcgov/feature/ALCS-964-2
Browse files Browse the repository at this point in the history
Unlink card status from boards before deleting
  • Loading branch information
dhaselhan authored Aug 16, 2023
2 parents 8b74184 + a12a87c commit d1c4f08
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,14 @@ describe('CardStatusController', () => {
expect(mockBoardService.getBoardsWithStatus).toHaveBeenCalledTimes(1);
});

it('should call the service for delete', async () => {
it('should unlink statuses and then call the service for delete', async () => {
mockCardStatusService.delete.mockResolvedValue({} as any);
mockBoardService.unlinkStatus.mockResolvedValue();

const res = await controller.delete('FAKE-CODE');

expect(res).toBeDefined();
expect(mockCardStatusService.delete).toHaveBeenCalledTimes(1);
expect(mockBoardService.unlinkStatus).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ export class CardStatusController {
@Delete('/:code')
@UserRoles(AUTH_ROLE.ADMIN)
async delete(@Param('code') code: string) {
//Delete from boards first
await this.boardService.unlinkStatus(code);
return await this.cardStatusService.delete(code);
}

Expand Down
9 changes: 8 additions & 1 deletion services/apps/alcs/src/alcs/board/board.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ApplicationService } from '../application/application.service';
import { Card } from '../card/card.entity';
import { CardService } from '../card/card.service';
import { BoardStatus } from './board-status.entity';
import { BoardStatusDto } from './board.dto';
import { Board } from './board.entity';
import { BoardService } from './board.service';

Expand Down Expand Up @@ -114,4 +113,12 @@ describe('BoardsService', () => {
new ServiceNotFoundException(`Failed to find Board with code board-code`),
);
});

it('should call through for unlink status', async () => {
mockBoardStatusRepository.delete.mockResolvedValue({} as any);

await service.unlinkStatus('code');

expect(mockBoardStatusRepository.delete).toHaveBeenCalledTimes(1);
});
});
8 changes: 8 additions & 0 deletions services/apps/alcs/src/alcs/board/board.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ export class BoardService {
});
}

async unlinkStatus(code: string) {
await this.boardStatusRepository.delete({
status: {
code,
},
});
}

async delete(code: string) {
const board = await this.getOneOrFail({
code,
Expand Down

0 comments on commit d1c4f08

Please sign in to comment.