-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #239 from boostcampwm-2024/revert-236-test/stockIndex
Revert "[BE] 주가 지수 서비스 테스트 코드 작성"
- Loading branch information
Showing
9 changed files
with
107 additions
and
127 deletions.
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
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
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('데이터를 정상적으로 조회하지 못했습니다.'); | ||
}); | ||
}); |
Binary file not shown.
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