diff --git a/BE/src/stock/topfive/stock-topfive.service.spec.ts b/BE/src/stock/topfive/stock-topfive.service.spec.ts index a807fbf1..1365d13f 100644 --- a/BE/src/stock/topfive/stock-topfive.service.spec.ts +++ b/BE/src/stock/topfive/stock-topfive.service.spec.ts @@ -6,9 +6,7 @@ import { STOCK_TOP_FIVE_HIGH_MOCK } from './mockdata/stock-topfive-high.mockdata import { STOCK_TOP_FIVE_LOW_MOCK } from './mockdata/stock-topfive-low.mockdata'; import { MarketType } from '../enum/market-type'; -jest.mock('axios'); - -describe('stock index list test', () => { +describe('stock topfive test', () => { let stockTopfiveService: StockTopfiveService; let koreaInvestmentDomainService: KoreaInvestmentDomainService; let highResponse: StockRankingDataDto[]; diff --git a/BE/src/stock/trade/history/mockdata/stock-trade-history-daily.mockdata.ts b/BE/src/stock/trade/history/mockdata/stock-trade-history-daily.mockdata.ts new file mode 100644 index 00000000..4e80986e --- /dev/null +++ b/BE/src/stock/trade/history/mockdata/stock-trade-history-daily.mockdata.ts @@ -0,0 +1,487 @@ +export const STOCK_TRADE_HISTORY_DAILY_MOCK = { + output: [ + { + stck_bsop_date: '20241202', + stck_oprc: '54300', + stck_hgpr: '54400', + stck_lwpr: '53100', + stck_clpr: '53600', + acml_vol: '21924956', + prdy_vrss_vol_rate: '-10.56', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + prdy_ctrt: '-1.11', + hts_frgn_ehrt: '51.35', + frgn_ntby_qty: '0', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241129', + stck_oprc: '55100', + stck_hgpr: '55300', + stck_lwpr: '53800', + stck_clpr: '54200', + acml_vol: '24513532', + prdy_vrss_vol_rate: '22.56', + prdy_vrss: '-1300', + prdy_vrss_sign: '5', + prdy_ctrt: '-2.34', + hts_frgn_ehrt: '51.35', + frgn_ntby_qty: '-4579840', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241128', + stck_oprc: '56000', + stck_hgpr: '56400', + stck_lwpr: '55200', + stck_clpr: '55500', + acml_vol: '20001134', + prdy_vrss_vol_rate: '-8.29', + prdy_vrss: '-800', + prdy_vrss_sign: '5', + prdy_ctrt: '-1.42', + hts_frgn_ehrt: '51.43', + frgn_ntby_qty: '-3350753', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241127', + stck_oprc: '57700', + stck_hgpr: '57800', + stck_lwpr: '56000', + stck_clpr: '56300', + acml_vol: '21808388', + prdy_vrss_vol_rate: '-6.04', + prdy_vrss: '-2000', + prdy_vrss_sign: '5', + prdy_ctrt: '-3.43', + hts_frgn_ehrt: '51.49', + frgn_ntby_qty: '-5105259', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241126', + stck_oprc: '57900', + stck_hgpr: '58900', + stck_lwpr: '57500', + stck_clpr: '58300', + acml_vol: '23209404', + prdy_vrss_vol_rate: '-35.95', + prdy_vrss: '400', + prdy_vrss_sign: '2', + prdy_ctrt: '0.69', + hts_frgn_ehrt: '51.57', + frgn_ntby_qty: '764317', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241125', + stck_oprc: '57400', + stck_hgpr: '57900', + stck_lwpr: '56700', + stck_clpr: '57900', + acml_vol: '36237324', + prdy_vrss_vol_rate: '137.13', + prdy_vrss: '1900', + prdy_vrss_sign: '2', + prdy_ctrt: '3.39', + hts_frgn_ehrt: '51.56', + frgn_ntby_qty: '-266783', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241122', + stck_oprc: '56000', + stck_hgpr: '56700', + stck_lwpr: '55900', + stck_clpr: '56000', + acml_vol: '15281543', + prdy_vrss_vol_rate: '-19.98', + prdy_vrss: '-400', + prdy_vrss_sign: '5', + prdy_ctrt: '-0.71', + hts_frgn_ehrt: '51.56', + frgn_ntby_qty: '-3588929', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241121', + stck_oprc: '54900', + stck_hgpr: '56900', + stck_lwpr: '54700', + stck_clpr: '56400', + acml_vol: '19096850', + prdy_vrss_vol_rate: '-8.47', + prdy_vrss: '1100', + prdy_vrss_sign: '2', + prdy_ctrt: '1.99', + hts_frgn_ehrt: '51.62', + frgn_ntby_qty: '-782949', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241120', + stck_oprc: '56100', + stck_hgpr: '56500', + stck_lwpr: '54800', + stck_clpr: '55300', + acml_vol: '20864668', + prdy_vrss_vol_rate: '-33.85', + prdy_vrss: '-1000', + prdy_vrss_sign: '5', + prdy_ctrt: '-1.78', + hts_frgn_ehrt: '51.64', + frgn_ntby_qty: '-1459649', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241119', + stck_oprc: '56500', + stck_hgpr: '57500', + stck_lwpr: '55900', + stck_clpr: '56300', + acml_vol: '31539632', + prdy_vrss_vol_rate: '-34.42', + prdy_vrss: '-400', + prdy_vrss_sign: '5', + prdy_ctrt: '-0.71', + hts_frgn_ehrt: '51.66', + frgn_ntby_qty: '-2601113', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241118', + stck_oprc: '57000', + stck_hgpr: '57500', + stck_lwpr: '55900', + stck_clpr: '56700', + acml_vol: '48095232', + prdy_vrss_vol_rate: '2.82', + prdy_vrss: '3200', + prdy_vrss_sign: '2', + prdy_ctrt: '5.98', + hts_frgn_ehrt: '51.70', + frgn_ntby_qty: '-3242824', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241115', + stck_oprc: '50300', + stck_hgpr: '54200', + stck_lwpr: '50300', + stck_clpr: '53500', + acml_vol: '46774484', + prdy_vrss_vol_rate: '-3.58', + prdy_vrss: '3600', + prdy_vrss_sign: '2', + prdy_ctrt: '7.21', + hts_frgn_ehrt: '51.76', + frgn_ntby_qty: '2488066', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241114', + stck_oprc: '50200', + stck_hgpr: '51800', + stck_lwpr: '49900', + stck_clpr: '49900', + acml_vol: '48510716', + prdy_vrss_vol_rate: '-7.65', + prdy_vrss: '-700', + prdy_vrss_sign: '5', + prdy_ctrt: '-1.38', + hts_frgn_ehrt: '51.72', + frgn_ntby_qty: '-8853732', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241113', + stck_oprc: '52000', + stck_hgpr: '53000', + stck_lwpr: '50500', + stck_clpr: '50600', + acml_vol: '52527996', + prdy_vrss_vol_rate: '38.37', + prdy_vrss: '-2400', + prdy_vrss_sign: '5', + prdy_ctrt: '-4.53', + hts_frgn_ehrt: '51.87', + frgn_ntby_qty: '-13742684', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241112', + stck_oprc: '54600', + stck_hgpr: '54600', + stck_lwpr: '53000', + stck_clpr: '53000', + acml_vol: '37962880', + prdy_vrss_vol_rate: '27.34', + prdy_vrss: '-2000', + prdy_vrss_sign: '5', + prdy_ctrt: '-3.64', + hts_frgn_ehrt: '52.10', + frgn_ntby_qty: '-7461438', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241111', + stck_oprc: '56700', + stck_hgpr: '56800', + stck_lwpr: '55000', + stck_clpr: '55000', + acml_vol: '29811326', + prdy_vrss_vol_rate: '114.82', + prdy_vrss: '-2000', + prdy_vrss_sign: '5', + prdy_ctrt: '-3.51', + hts_frgn_ehrt: '52.22', + frgn_ntby_qty: '-9424701', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241108', + stck_oprc: '58000', + stck_hgpr: '58300', + stck_lwpr: '57000', + stck_clpr: '57000', + acml_vol: '13877396', + prdy_vrss_vol_rate: '-18.57', + prdy_vrss: '-500', + prdy_vrss_sign: '5', + prdy_ctrt: '-0.87', + hts_frgn_ehrt: '52.38', + frgn_ntby_qty: '-1480774', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241107', + stck_oprc: '56900', + stck_hgpr: '58100', + stck_lwpr: '56800', + stck_clpr: '57500', + acml_vol: '17043102', + prdy_vrss_vol_rate: '-22.85', + prdy_vrss: '200', + prdy_vrss_sign: '2', + prdy_ctrt: '0.35', + hts_frgn_ehrt: '52.40', + frgn_ntby_qty: '-321775', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241106', + stck_oprc: '57600', + stck_hgpr: '58000', + stck_lwpr: '56300', + stck_clpr: '57300', + acml_vol: '22092218', + prdy_vrss_vol_rate: '26.35', + prdy_vrss: '-300', + prdy_vrss_sign: '5', + prdy_ctrt: '-0.52', + hts_frgn_ehrt: '52.41', + frgn_ntby_qty: '-2611198', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241105', + stck_oprc: '57800', + stck_hgpr: '58100', + stck_lwpr: '57200', + stck_clpr: '57600', + acml_vol: '17484474', + prdy_vrss_vol_rate: '12.17', + prdy_vrss: '-1100', + prdy_vrss_sign: '5', + prdy_ctrt: '-1.87', + hts_frgn_ehrt: '52.45', + frgn_ntby_qty: '-2848671', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241104', + stck_oprc: '58600', + stck_hgpr: '59400', + stck_lwpr: '58400', + stck_clpr: '58700', + acml_vol: '15586947', + prdy_vrss_vol_rate: '-18.32', + prdy_vrss: '400', + prdy_vrss_sign: '2', + prdy_ctrt: '0.69', + hts_frgn_ehrt: '52.50', + frgn_ntby_qty: '-2093510', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241101', + stck_oprc: '59000', + stck_hgpr: '59600', + stck_lwpr: '58100', + stck_clpr: '58300', + acml_vol: '19083180', + prdy_vrss_vol_rate: '-46.71', + prdy_vrss: '-900', + prdy_vrss_sign: '5', + prdy_ctrt: '-1.52', + hts_frgn_ehrt: '52.53', + frgn_ntby_qty: '-2063620', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241031', + stck_oprc: '58500', + stck_hgpr: '61200', + stck_lwpr: '58300', + stck_clpr: '59200', + acml_vol: '35809196', + prdy_vrss_vol_rate: '80.50', + prdy_vrss: '100', + prdy_vrss_sign: '2', + prdy_ctrt: '0.17', + hts_frgn_ehrt: '52.57', + frgn_ntby_qty: '-2059308', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241030', + stck_oprc: '59100', + stck_hgpr: '59800', + stck_lwpr: '58600', + stck_clpr: '59100', + acml_vol: '19838512', + prdy_vrss_vol_rate: '-30.07', + prdy_vrss: '-500', + prdy_vrss_sign: '5', + prdy_ctrt: '-0.84', + hts_frgn_ehrt: '52.60', + frgn_ntby_qty: '-3054026', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241029', + stck_oprc: '58000', + stck_hgpr: '59600', + stck_lwpr: '57300', + stck_clpr: '59600', + acml_vol: '28369314', + prdy_vrss_vol_rate: '2.14', + prdy_vrss: '1500', + prdy_vrss_sign: '2', + prdy_ctrt: '2.58', + hts_frgn_ehrt: '52.66', + frgn_ntby_qty: '314269', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241028', + stck_oprc: '55700', + stck_hgpr: '58500', + stck_lwpr: '55700', + stck_clpr: '58100', + acml_vol: '27775008', + prdy_vrss_vol_rate: '7.53', + prdy_vrss: '2200', + prdy_vrss_sign: '2', + prdy_ctrt: '3.94', + hts_frgn_ehrt: '52.65', + frgn_ntby_qty: '370214', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241025', + stck_oprc: '56000', + stck_hgpr: '56900', + stck_lwpr: '55800', + stck_clpr: '55900', + acml_vol: '25829316', + prdy_vrss_vol_rate: '-18.00', + prdy_vrss: '-700', + prdy_vrss_sign: '5', + prdy_ctrt: '-1.24', + hts_frgn_ehrt: '52.64', + frgn_ntby_qty: '-5811796', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241024', + stck_oprc: '58200', + stck_hgpr: '58500', + stck_lwpr: '56600', + stck_clpr: '56600', + acml_vol: '31499922', + prdy_vrss_vol_rate: '15.38', + prdy_vrss: '-2500', + prdy_vrss_sign: '5', + prdy_ctrt: '-4.23', + hts_frgn_ehrt: '52.74', + frgn_ntby_qty: '-11444663', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241023', + stck_oprc: '57500', + stck_hgpr: '60000', + stck_lwpr: '57100', + stck_clpr: '59100', + acml_vol: '27300780', + prdy_vrss_vol_rate: '-1.02', + prdy_vrss: '1400', + prdy_vrss_sign: '2', + prdy_ctrt: '2.43', + hts_frgn_ehrt: '52.93', + frgn_ntby_qty: '69322', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + { + stck_bsop_date: '20241022', + stck_oprc: '58800', + stck_hgpr: '58900', + stck_lwpr: '57700', + stck_clpr: '57700', + acml_vol: '27582528', + prdy_vrss_vol_rate: '48.97', + prdy_vrss: '-1300', + prdy_vrss_sign: '5', + prdy_ctrt: '-2.20', + hts_frgn_ehrt: '52.93', + frgn_ntby_qty: '-4832158', + flng_cls_code: '00', + acml_prtt_rate: '1.00', + }, + ], + rt_cd: '0', + msg_cd: 'MCA00000', + msg1: '정상처리 되었습니다.', +}; diff --git a/BE/src/stock/trade/history/mockdata/stock-trade-history-today.mockdata.ts b/BE/src/stock/trade/history/mockdata/stock-trade-history-today.mockdata.ts new file mode 100644 index 00000000..a19c08ab --- /dev/null +++ b/BE/src/stock/trade/history/mockdata/stock-trade-history-today.mockdata.ts @@ -0,0 +1,277 @@ +export const STOCK_TRADE_HISTORY_TODAY_MOCK = { + output: [ + { + stck_cntg_hour: '155958', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '5', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155958', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '1', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155957', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '1', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155951', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '20', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155949', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '1', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155948', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '1', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155945', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '131', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155945', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '6', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155943', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '6', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155939', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '10', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155937', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '11', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155937', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '3', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155936', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '2', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155936', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '5', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155935', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '10', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155933', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '132', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155933', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '10', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155933', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '1', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155931', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '1', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155930', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '1', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155930', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '1', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155930', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '10', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155928', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '20', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155927', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '2', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155926', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '5', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155926', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '1', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155926', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '2', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155921', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '2', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155921', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '1', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + { + stck_cntg_hour: '155920', + stck_prpr: '53600', + prdy_vrss: '-600', + prdy_vrss_sign: '5', + cntg_vol: '5', + tday_rltv: '71.47', + prdy_ctrt: '-1.11', + }, + ], + rt_cd: '0', + msg_cd: 'MCA00000', + msg1: '정상처리 되었습니다.', +}; diff --git a/BE/src/stock/trade/history/stock-trade-history.service.spec.ts b/BE/src/stock/trade/history/stock-trade-history.service.spec.ts new file mode 100644 index 00000000..363ecc94 --- /dev/null +++ b/BE/src/stock/trade/history/stock-trade-history.service.spec.ts @@ -0,0 +1,82 @@ +import { Test } from '@nestjs/testing'; +import { KoreaInvestmentDomainService } from '../../../common/koreaInvestment/korea-investment.domain-service'; +import { StockTradeHistoryService } from './stock-trade-history.service'; +import { StockPriceSocketService } from '../../../stockSocket/stock-price-socket.service'; +import { STOCK_TRADE_HISTORY_TODAY_MOCK } from './mockdata/stock-trade-history-today.mockdata'; +import { STOCK_TRADE_HISTORY_DAILY_MOCK } from './mockdata/stock-trade-history-daily.mockdata'; + +describe('stock trade history test', () => { + let stockTradeHistoryService: StockTradeHistoryService; + let koreaInvestmentDomainService: KoreaInvestmentDomainService; + let stockPriceSocketService: StockPriceSocketService; + + beforeEach(async () => { + const module = await Test.createTestingModule({ + providers: [ + StockTradeHistoryService, + KoreaInvestmentDomainService, + { + provide: StockPriceSocketService, + useValue: { + subscribeByCode: jest.fn(), // 이 메서드만 모킹합니다. + }, + }, + ], + }).compile(); + + stockTradeHistoryService = module.get(StockTradeHistoryService); + koreaInvestmentDomainService = module.get(KoreaInvestmentDomainService); + stockPriceSocketService = module.get(StockPriceSocketService); + + jest + .spyOn(koreaInvestmentDomainService, 'getAccessToken') + .mockResolvedValue('accessToken'); + }); + + it('특정 주식의 현재가 체결 데이터를 반환한다.', async () => { + jest + .spyOn(koreaInvestmentDomainService, 'requestApi') + .mockResolvedValueOnce(STOCK_TRADE_HISTORY_TODAY_MOCK); + jest + .spyOn(stockPriceSocketService, 'subscribeByCode') + .mockImplementation(() => {}); + + const response = + await stockTradeHistoryService.getTodayStockTradeHistory('005930'); + + const expected = { + stck_cntg_hour: '155958', + stck_prpr: '53600', + prdy_vrss_sign: '5', + cntg_vol: '5', + prdy_ctrt: '-1.11', + }; + + expect(response[0]).toEqual(expected); + }); + + it('특정 주식의 일자별 체결 데이터를 반환한다.', async () => { + jest + .spyOn(koreaInvestmentDomainService, 'requestApi') + .mockResolvedValueOnce(STOCK_TRADE_HISTORY_DAILY_MOCK); + + const response = + await stockTradeHistoryService.getDailyStockTradeHistory('005930'); + + const expected = { + stck_bsop_date: '20241202', + stck_oprc: '54300', + stck_hgpr: '54400', + stck_lwpr: '53100', + stck_clpr: '53600', + acml_vol: '21924956', + prdy_vrss_sign: '5', + prdy_ctrt: '-1.11', + }; + + expect(response[0]).toEqual(expected); + expect(response[0].stck_bsop_date).toEqual('20241202'); + expect(response[1].stck_bsop_date).toEqual('20241129'); + expect(response[2].stck_bsop_date).toEqual('20241128'); + }); +});