-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid hitting real API in test (#1047)
- Loading branch information
1 parent
c46c967
commit 5f70919
Showing
2 changed files
with
59 additions
and
23 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
21 changes: 19 additions & 2 deletions
21
packages/internal/generated-clients/src/imx-api-clents.test.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 |
---|---|---|
@@ -1,26 +1,43 @@ | ||
import { AxiosRequestConfig } from 'axios'; | ||
import { ImxApiClients } from './imx-api-clients'; | ||
import { imxApiConfig } from './config'; | ||
|
||
describe('ImxApiClients', () => { | ||
it('should instantiate a SANDBOX ImxApiClients', async () => { | ||
const config = imxApiConfig.getSandbox(); | ||
|
||
let axiosRequest: AxiosRequestConfig = {}; | ||
config.baseOptions.adapter = jest.fn().mockImplementation(async (request: AxiosRequestConfig) => { | ||
axiosRequest = request; | ||
return { status: 200 }; | ||
}); | ||
|
||
const { assetApi } = new ImxApiClients(config); | ||
const assetsResponse = await assetApi.listAssets(); | ||
|
||
expect(assetsResponse.status).toEqual(200); | ||
expect(assetsResponse.config.headers?.['x-sdk-version']).toContain( | ||
expect(axiosRequest.headers?.['x-sdk-version']).toContain( | ||
'ts-immutable-sdk', | ||
); | ||
expect(axiosRequest.url).toEqual('https://api.sandbox.x.immutable.com/v1/assets'); | ||
}); | ||
|
||
it('should instantiate a PRODUCTION ImxApiClients', async () => { | ||
const config = imxApiConfig.getProduction(); | ||
|
||
let axiosRequest: AxiosRequestConfig = {}; | ||
config.baseOptions.adapter = jest.fn().mockImplementation(async (request: AxiosRequestConfig) => { | ||
axiosRequest = request; | ||
return { status: 200 }; | ||
}); | ||
|
||
const { assetApi } = new ImxApiClients(config); | ||
const assetsResponse = await assetApi.listAssets(); | ||
|
||
expect(assetsResponse.status).toEqual(200); | ||
expect(assetsResponse.config.headers?.['x-sdk-version']).toContain( | ||
expect(axiosRequest.headers?.['x-sdk-version']).toContain( | ||
'ts-immutable-sdk', | ||
); | ||
expect(axiosRequest.url).toEqual('https://api.x.immutable.com/v1/assets'); | ||
}); | ||
}); |