-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(whale-api-client): new default url (#2178)
#### What this PR does / why we need it: - Updates the default URLs to point to `<network>.ocean.jellyfishsdk.com` - Adds the necessary test --------- Co-authored-by: canonbrother <[email protected]>
- Loading branch information
1 parent
e04c2b0
commit 26b8eb1
Showing
3 changed files
with
72 additions
and
41 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
76 changes: 46 additions & 30 deletions
76
packages/whale-api-client/__tests__/WhaleApiClient.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,42 +1,58 @@ | ||
import nock from 'nock' | ||
import { WhaleApiClient } from '@defichain/whale-api-client/dist/whale.api.client' | ||
import { NetworkName } from '@defichain/jellyfish-network' | ||
|
||
const client = new WhaleApiClient({ | ||
url: 'http://whale-api-test.internal', | ||
network: 'regtest', | ||
version: 'v0.0' | ||
describe('WhaleApiClient default url', () => { | ||
it.each<NetworkName>([ | ||
'mainnet', | ||
'testnet' | ||
])('should query default url successfully: %s', async (network: NetworkName) => { | ||
const client = new WhaleApiClient({ network }) | ||
const response = await client.stats.get() | ||
expect(response).toMatchObject({ | ||
blockchain: expect.any(Object) | ||
}) | ||
}) | ||
}) | ||
|
||
it('should requestData via GET', async () => { | ||
nock('http://whale-api-test.internal') | ||
.get('/v0.0/regtest/foo') | ||
.reply(200, function () { | ||
return { | ||
data: { | ||
bar: ['1', '2'] | ||
describe('WhaleApiClient HTTP', () => { | ||
const client = new WhaleApiClient({ | ||
url: 'http://whale-api-test.internal', | ||
network: 'regtest', | ||
version: 'v0.0' | ||
}) | ||
|
||
it('should requestData via GET', async () => { | ||
nock('http://whale-api-test.internal') | ||
.get('/v0.0/regtest/foo') | ||
.reply(200, function () { | ||
return { | ||
data: { | ||
bar: ['1', '2'] | ||
} | ||
} | ||
} | ||
}) | ||
}) | ||
|
||
const result = await client.requestData('GET', 'foo') | ||
await expect(result).toStrictEqual({ | ||
bar: ['1', '2'] | ||
const result = await client.requestData('GET', 'foo') | ||
await expect(result).toStrictEqual({ | ||
bar: ['1', '2'] | ||
}) | ||
}) | ||
}) | ||
|
||
it('should requestData via POST', async () => { | ||
nock('http://whale-api-test.internal') | ||
.post('/v0.0/regtest/bar') | ||
.reply(200, function (_, body: object) { | ||
return { | ||
data: body | ||
} | ||
}) | ||
it('should requestData via POST', async () => { | ||
nock('http://whale-api-test.internal') | ||
.post('/v0.0/regtest/bar') | ||
.reply(200, function (_, body: object) { | ||
return { | ||
data: body | ||
} | ||
}) | ||
|
||
const result = await client.requestData('POST', 'bar', { | ||
abc: ['a', 'b', 'c'] | ||
}) | ||
await expect(result).toStrictEqual({ | ||
abc: ['a', 'b', 'c'] | ||
const result = await client.requestData('POST', 'bar', { | ||
abc: ['a', 'b', 'c'] | ||
}) | ||
await expect(result).toStrictEqual({ | ||
abc: ['a', 'b', 'c'] | ||
}) | ||
}) | ||
}) |
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