Skip to content

Commit

Permalink
fix(client): clear mock after tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marslavish committed Mar 20, 2024
1 parent 9f414e6 commit c6dc7f3
Showing 1 changed file with 17 additions and 53 deletions.
70 changes: 17 additions & 53 deletions packages/client/__tests__/client-mock.test.ts
Original file line number Diff line number Diff line change
@@ -1,80 +1,44 @@
import nock from 'nock';

import assets from '../../../__fixtures__/assets.json';
import chains from '../../../__fixtures__/chains.json';
import { ChainRegistryClient } from '../src/registry';

const osmosisChainData = {
$schema: '../chain.schema.json',
chain_name: 'osmosis',
status: 'live',
network_type: 'mainnet',
website: 'https://osmosis.zone/',
update_link:
'https://raw.githubusercontent.com/osmosis-labs/osmosis/main/chain.schema.json',
pretty_name: 'Osmosis',
chain_id: 'osmosis-1',
bech32_prefix: 'osmo',
daemon_name: 'osmosisd',
node_home: '$HOME/.osmosisd',
key_algos: ['secp256k1'],
slip44: 118
};

const osmosisAssetlistData = {
$schema: '../assetlist.schema.json',
chain_name: 'osmosis',
assets: [
{
description: 'The native token of Osmosis',
denom_units: [
{
denom: 'uosmo',
exponent: 0
},
{
denom: 'osmo',
exponent: 6
}
],
base: 'uosmo',
name: 'Osmosis',
display: 'osmo',
symbol: 'OSMO',
logo_URIs: {
png: 'https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/osmo.png',
svg: 'https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/osmo.svg'
},
coingecko_id: 'osmosis',
keywords: ['dex', 'staking']
}
]
};

const baseUrl = 'https://raw.githubusercontent.com';

function nockByChainName(chainName: string, chainData, assetlistData) {
function nockByChainName(chainName: string) {
const chainDataPath = `/cosmos/chain-registry/master/${chainName}/chain.json`;
const assetlistDataPath = `/cosmos/chain-registry/master/${chainName}/assetlist.json`;

const chainData = chains.find((chain) => chain.chain_name === chainName);
const assetlistData = assets.find((asset) => asset.chain_name === chainName);

nock(baseUrl).get(chainDataPath).reply(200, chainData);
nock(baseUrl).get(assetlistDataPath).reply(200, assetlistData);
}

describe('Test client', () => {
let client;

beforeAll(async () => {
nockByChainName('osmosis', osmosisChainData, osmosisAssetlistData);
nockByChainName('stargaze');
client = new ChainRegistryClient({
chainNames: ['osmosis']
chainNames: ['stargaze']
});
await client.fetchUrls();
});

afterAll(() => {
nock.restore();
});

it('Test mock fetching chain data', () => {
const chainInfo = client.getChainInfo('osmosis');
expect(chainInfo.chainName).toEqual('osmosis');
const chainInfo = client.getChainInfo('stargaze');
expect(chainInfo.chainName).toEqual('stargaze');
});

it('Test mock fetching asset list', () => {
const chainInfo = client.getChainInfo('osmosis');
const chainInfo = client.getChainInfo('stargaze');
expect(chainInfo.nativeAssetList.assets.length).toEqual(1);
});
});

0 comments on commit c6dc7f3

Please sign in to comment.