Skip to content

Commit

Permalink
npm run test
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueHorn07 committed Sep 26, 2024
1 parent 1664af6 commit a986437
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/popo/noticeLike/noticeLike.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { NoticeLikeController } from './noticeLike.controller';
import { NoticeLikeService } from './noticeLike.service';
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { NoticeLike } from './noticeLike.entity';
import { JwtPayload } from 'src/auth/strategies/jwt.payload';

describe('NoticeLikeController', () => {
let controller: NoticeLikeController;
Expand Down Expand Up @@ -58,7 +59,9 @@ describe('NoticeLikeController', () => {
const noticeId = 1;
noticeLikeService.findByUserIdAndNoticeId.mockResolvedValue(null);

await expect(controller.delete(userId, noticeId)).rejects.toThrow();
const user = { uuid: '1' } as JwtPayload;

await expect(controller.delete(userId, noticeId, { user: user })).rejects.toThrow();

Check failure on line 64 in src/popo/noticeLike/noticeLike.controller.spec.ts

View workflow job for this annotation

GitHub Actions / Prettier and ESLint check

Replace `controller.delete(userId,·noticeId,·{·user:·user·})` with `⏎······controller.delete(userId,·noticeId,·{·user:·user·}),⏎····`
});

it('should delete like', async () => {
Expand All @@ -70,10 +73,13 @@ describe('NoticeLikeController', () => {
notice_id: 1,
created_at: new Date(),
};

const user = { uuid: '1' } as JwtPayload;

const mockedDeletedResult = { affected: 1, raw: null };
noticeLikeService.findByUserIdAndNoticeId.mockResolvedValue(like);
noticeLikeService.delete.mockResolvedValue(mockedDeletedResult);

expect(await controller.delete(userId, noticeId)).toBe(mockedDeletedResult);
expect(await controller.delete(userId, noticeId, { user: user })).toBe(mockedDeletedResult);

Check failure on line 83 in src/popo/noticeLike/noticeLike.controller.spec.ts

View workflow job for this annotation

GitHub Actions / Prettier and ESLint check

Replace `mockedDeletedResult` with `⏎······mockedDeletedResult,⏎····`
});
});
2 changes: 1 addition & 1 deletion src/popo/noticeLike/noticeLike.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class NoticeLikeController {
async delete(
@Param('user_id') user_id: string,
@Param('notice_id') notice_id: number,
@Req() req: Request,
@Req() req: Request | any,
) {
const user = req.user as JwtPayload;
if (user.uuid != user_id) {
Expand Down

0 comments on commit a986437

Please sign in to comment.