From 0e87ffeef98efe05ea040eec6497ca835e41a438 Mon Sep 17 00:00:00 2001 From: anjdydhody Date: Mon, 2 Dec 2024 22:35:59 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test:=20=EC=A6=90=EA=B2=A8=EC=B0=BE?= =?UTF-8?q?=EA=B8=B0=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?API=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=20#237?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bookmark/stock-bookmark.service.spec.ts | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/BE/src/stock/bookmark/stock-bookmark.service.spec.ts b/BE/src/stock/bookmark/stock-bookmark.service.spec.ts index 22a4a2f..d0bb419 100644 --- a/BE/src/stock/bookmark/stock-bookmark.service.spec.ts +++ b/BE/src/stock/bookmark/stock-bookmark.service.spec.ts @@ -1,9 +1,9 @@ import { Test } from '@nestjs/testing'; 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'; +import { StockBookmarkResponseDto } from './dto/stock-bookmark-response,dto'; describe('stock bookmark test', () => { let stockBookmarkService: StockBookmarkService; @@ -17,6 +17,7 @@ describe('stock bookmark test', () => { insert: jest.fn(), findOneBy: jest.fn(), remove: jest.fn(), + findBookmarkWithNameByUserId: jest.fn(), }; const mockStockDetailService = { getInquirePrice: jest.fn() }; @@ -93,4 +94,46 @@ describe('stock bookmark test', () => { stockBookmarkService.unregisterBookmark(1, '005930'), ).rejects.toThrow(NotFoundException); }); + + it('즐겨찾기를 조회할 경우, 해당 종목들의 현재가를 포함한 데이터가 반환된다.', async () => { + jest + .spyOn(stockBookmarkRepository, 'findBookmarkWithNameByUserId') + .mockResolvedValue([ + { + b_id: 1, + b_user_id: 1, + b_stock_code: '005930', + s_code: '005930', + s_name: '삼성전자', + s_market: 'KOSPI', + }, + ]); + + jest.spyOn(stockDetailService, 'getInquirePrice').mockResolvedValue({ + hts_kor_isnm: '삼성전자', + stck_shrn_iscd: '005930', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + prdy_ctrt: '-1.11', + hts_avls: '3199803', + per: '25.15', + stck_mxpr: '70400', + stck_llam: '38000', + is_bookmarked: true, + }); + + const stockBookmarkResponse = new StockBookmarkResponseDto( + '삼성전자', + '005930', + '53600', + '-600', + '5', + '-1.11', + ); + + expect(await stockBookmarkService.getBookmarkList(1)).toEqual([ + stockBookmarkResponse, + ]); + }); });