Skip to content

Commit

Permalink
✅ test: 즐겨찾기 취소 API 테스트 코드 작성 #237
Browse files Browse the repository at this point in the history
  • Loading branch information
sieunie committed Dec 2, 2024
1 parent ffe39e2 commit 80752a2
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion BE/src/stock/bookmark/stock-bookmark.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Test } from '@nestjs/testing';
import { BadRequestException } from '@nestjs/common';
import { BadRequestException, NotFoundException } from '@nestjs/common';
import { Column, PrimaryGeneratedColumn } from 'typeorm';
import { StockBookmarkRepository } from './stock-bookmark.repository';
import { StockDetailService } from '../detail/stock-detail.service';
import { StockBookmarkService } from './stock-bookmark.service';
Expand All @@ -14,6 +15,8 @@ describe('stock bookmark test', () => {
existsBy: jest.fn(),
create: jest.fn(),
insert: jest.fn(),
findOneBy: jest.fn(),
remove: jest.fn(),
};
const mockStockDetailService = { getInquirePrice: jest.fn() };

Expand Down Expand Up @@ -63,4 +66,31 @@ describe('stock bookmark test', () => {
stockBookmarkService.registerBookmark(1, '005930'),
).rejects.toThrow(BadRequestException);
});

it('존재하는 즐겨찾기를 취소할 경우, DB에서 해당 즐겨찾기가 삭제된다.', async () => {
jest.spyOn(stockBookmarkRepository, 'findOneBy').mockResolvedValue({
id: 1,
stock_code: '005930',
user_id: 1,
});

const removeMock = jest.fn();
jest
.spyOn(stockBookmarkRepository, 'remove')
.mockImplementation(removeMock);

await stockBookmarkService.unregisterBookmark(1, '005930');

expect(removeMock).toHaveBeenCalled();
});

it('존재하지 않는 즐겨찾기를 취소할 경우, NotFound 예외가 발생한다.', async () => {
jest
.spyOn(stockBookmarkRepository, 'findOneBy')
.mockResolvedValue(undefined);

await expect(
stockBookmarkService.unregisterBookmark(1, '005930'),
).rejects.toThrow(NotFoundException);
});
});

0 comments on commit 80752a2

Please sign in to comment.