-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BE] 3.03 주식 차트 정보 기능 테스트 #9 #42
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface SocketConnectTokenInterface { | ||
approval_key: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export const STOCK_INDEX_LIST_MOCK = { | ||
VALID_DATA: { | ||
data: { | ||
output: [ | ||
{ | ||
bsop_hour: '100600', | ||
bstp_nmix_prpr: '916.77', | ||
bstp_nmix_prdy_vrss: '11.27', | ||
prdy_vrss_sign: '2', | ||
bstp_nmix_prdy_ctrt: '1.24', | ||
acml_tr_pbmn: '3839797', | ||
acml_vol: '313374', | ||
cntg_vol: '870', | ||
}, | ||
], | ||
rt_cd: '0', | ||
msg_cd: 'MCA00000', | ||
msg1: '정상처리 되었습니다.', | ||
}, | ||
}, | ||
INVALID_DATA: { | ||
data: { | ||
output: [], | ||
rt_cd: '1', | ||
msg_cd: 'MCA00000', | ||
msg1: '유효하지 않은 토큰입니다.', | ||
}, | ||
}, | ||
}; |
55 changes: 55 additions & 0 deletions
55
BE/test/stock/index/mockdata/stock.index.value.mockdata.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
export const STOCK_INDEX_VALUE_MOCK = { | ||
VALID_DATA: { | ||
data: { | ||
output: { | ||
bstp_nmix_prpr: '857.60', | ||
bstp_nmix_prdy_vrss: '-1.61', | ||
prdy_vrss_sign: '5', | ||
bstp_nmix_prdy_ctrt: '-0.19', | ||
acml_vol: '1312496', | ||
prdy_vol: '1222188', | ||
acml_tr_pbmn: '11507962', | ||
prdy_tr_pbmn: '11203385', | ||
bstp_nmix_oprc: '863.69', | ||
prdy_nmix_vrss_nmix_oprc: '4.48', | ||
oprc_vrss_prpr_sign: '2', | ||
bstp_nmix_oprc_prdy_ctrt: '0.52', | ||
bstp_nmix_hgpr: '864.24', | ||
prdy_nmix_vrss_nmix_hgpr: '5.03', | ||
hgpr_vrss_prpr_sign: '2', | ||
bstp_nmix_hgpr_prdy_ctrt: '0.59', | ||
bstp_nmix_lwpr: '854.72', | ||
prdy_clpr_vrss_lwpr: '-4.49', | ||
lwpr_vrss_prpr_sign: '5', | ||
prdy_clpr_vrss_lwpr_rate: '-0.52', | ||
ascn_issu_cnt: '828', | ||
uplm_issu_cnt: '5', | ||
stnr_issu_cnt: '94', | ||
down_issu_cnt: '716', | ||
lslm_issu_cnt: '1', | ||
dryy_bstp_nmix_hgpr: '890.06', | ||
dryy_hgpr_vrss_prpr_rate: '3.65', | ||
dryy_bstp_nmix_hgpr_date: '20240109', | ||
dryy_bstp_nmix_lwpr: '786.28', | ||
dryy_lwpr_vrss_prpr_rate: '-9.07', | ||
dryy_bstp_nmix_lwpr_date: '20240201', | ||
total_askp_rsqn: '24146999', | ||
total_bidp_rsqn: '40450437', | ||
seln_rsqn_rate: '37.38', | ||
shnu_rsqn_rate: '62.62', | ||
ntby_rsqn: '16303438', | ||
}, | ||
rt_cd: '0', | ||
msg_cd: 'MCA00000', | ||
msg1: '정상처리 되었습니다.', | ||
}, | ||
}, | ||
INVALID_DATA: { | ||
data: { | ||
output: {}, | ||
rt_cd: '1', | ||
msg_cd: 'MCA00000', | ||
msg1: '유효하지 않은 토큰입니다.', | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Test } from '@nestjs/testing'; | ||
import axios from 'axios'; | ||
import { StockIndexService } from '../../../src/stock/index/stock.index.service'; | ||
import { STOCK_INDEX_LIST_MOCK } from './mockdata/stock.index.list.mockdata'; | ||
|
||
jest.mock('axios'); | ||
|
||
describe('stock index list test', () => { | ||
let stockIndexService: StockIndexService; | ||
|
||
beforeEach(async () => { | ||
const module = await Test.createTestingModule({ | ||
providers: [StockIndexService], | ||
}).compile(); | ||
|
||
stockIndexService = module.get(StockIndexService); | ||
}); | ||
|
||
it('주가 지수 차트 조회 API에서 정상적인 데이터를 조회한 경우, 형식에 맞춰 정상적으로 반환한다.', async () => { | ||
(axios.get as jest.Mock).mockResolvedValue( | ||
STOCK_INDEX_LIST_MOCK.VALID_DATA, | ||
); | ||
|
||
expect( | ||
await stockIndexService.getDomesticStockIndexListByCode( | ||
'code', | ||
'accessToken', | ||
), | ||
).toEqual({ | ||
code: 'code', | ||
chart: [ | ||
{ | ||
time: STOCK_INDEX_LIST_MOCK.VALID_DATA.data.output[0].bsop_hour, | ||
value: STOCK_INDEX_LIST_MOCK.VALID_DATA.data.output[0].bstp_nmix_prpr, | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it('주가 지수 차트 조회 API에서 데이터를 조회하지 못한 경우, 에러를 발생시킨다.', async () => { | ||
(axios.get as jest.Mock).mockResolvedValue( | ||
STOCK_INDEX_LIST_MOCK.INVALID_DATA, | ||
); | ||
|
||
await expect( | ||
stockIndexService.getDomesticStockIndexListByCode('code', 'accessToken'), | ||
).rejects.toThrow('데이터를 정상적으로 조회하지 못했습니다.'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Test } from '@nestjs/testing'; | ||
import axios from 'axios'; | ||
import { StockIndexService } from '../../../src/stock/index/stock.index.service'; | ||
import { STOCK_INDEX_VALUE_MOCK } from './mockdata/stock.index.value.mockdata'; | ||
|
||
jest.mock('axios'); | ||
|
||
describe('stock index list test', () => { | ||
let stockIndexService: StockIndexService; | ||
|
||
beforeEach(async () => { | ||
const module = await Test.createTestingModule({ | ||
providers: [StockIndexService], | ||
}).compile(); | ||
|
||
stockIndexService = module.get(StockIndexService); | ||
}); | ||
|
||
it('주가 지수 값 조회 API에서 정상적인 데이터를 조회한 경우, 형식에 맞춰 정상적으로 반환한다.', async () => { | ||
(axios.get as jest.Mock).mockResolvedValue( | ||
STOCK_INDEX_VALUE_MOCK.VALID_DATA, | ||
); | ||
|
||
expect( | ||
await stockIndexService.getDomesticStockIndexValueByCode( | ||
'code', | ||
'accessToken', | ||
), | ||
).toEqual({ | ||
code: 'code', | ||
value: STOCK_INDEX_VALUE_MOCK.VALID_DATA.data.output.bstp_nmix_prpr, | ||
diff: STOCK_INDEX_VALUE_MOCK.VALID_DATA.data.output.bstp_nmix_prdy_vrss, | ||
diffRate: | ||
STOCK_INDEX_VALUE_MOCK.VALID_DATA.data.output.bstp_nmix_prdy_ctrt, | ||
sign: STOCK_INDEX_VALUE_MOCK.VALID_DATA.data.output.prdy_vrss_sign, | ||
}); | ||
}); | ||
|
||
it('주가 지수 값 조회 API에서 데이터를 조회하지 못한 경우, 에러를 발생시킨다.', async () => { | ||
(axios.get as jest.Mock).mockResolvedValue( | ||
STOCK_INDEX_VALUE_MOCK.INVALID_DATA, | ||
); | ||
|
||
await expect( | ||
stockIndexService.getDomesticStockIndexValueByCode('code', 'accessToken'), | ||
).rejects.toThrow('데이터를 정상적으로 조회하지 못했습니다.'); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟢 axios 적용 좋습니다! 고생하셨습니다