Skip to content

Commit

Permalink
chore: fix test pipelines (#1379)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsimao authored Jul 11, 2023
1 parent a96dab8 commit aa9470e
Show file tree
Hide file tree
Showing 28 changed files with 480 additions and 397 deletions.
4 changes: 2 additions & 2 deletions src/components/AuthModal/AuthModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ describe('AuthModal', () => {

await render(<AuthModal isOpen onClose={jest.fn} />);

expect(screen.getByRole('heading', { name: /please install supported wallet/i })).toBeInTheDocument();
expect(screen.getByRole('heading', { name: /please install a supported wallet/i })).toBeInTheDocument();

const items = screen.getAllByRole('button', { name: /navigate/i, exact: false });

expect(items).toHaveLength(3);
expect(items).toHaveLength(4);

const [item] = items;

Expand Down
57 changes: 15 additions & 42 deletions src/test/mocks/@interlay/interbtc-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ import { Interlay, Polkadot } from '@interlay/monetary-js';
import { AddressOrPair } from '@polkadot/api/types';
import { Signer } from '@polkadot/types/types';

import { mockFaucet } from './faucet';
import {
MOCK_AMM,
MOCK_SYSTEM,
MOCK_TRANSACTION,
mockApiCreateType,
mockBtcRelayGetLatestBlockHeight,
mockChainType,
mockElectrsAPIGetLatestBlockHeight,
mockFeeGetIssueFee,
mockFeeGetIssueGriefingCollateralRate,
mockGetCurrentActiveBlockNumber,
mockGetCurrentBlockNumber,
mockGetFutureBlockNumber,
mockGetStableBitcoinConfirmations,
mockGetStableParachainConfirmations,
mockIssueGetDustValue,
Expand All @@ -31,7 +30,6 @@ import {
mockRedeemGetPremiumRedeemFeeRate,
mockRedeemRequest,
mockSystemChain,
mockSystemGetStatusCode,
mockTokensBalance,
mockTokensSubscribeToBalance,
mockTokensTotal,
Expand All @@ -40,17 +38,6 @@ import {
mockVaultsGetVaultsWithIssuableTokens,
mockVaultsGetVaultsWithRedeemableTokens
} from './parachain';
import {
mockAddLiquidity,
mockClaimFarmingRewards,
mockGetClaimableFarmingRewards,
mockGetLiquidityPools,
mockGetLiquidityProvidedByAccount,
mockGetLpTokens,
mockGetOptimalTrade,
mockRemoveLiquidity,
mockSwap
} from './parachain/amm';
import { mockGetForeignAssets } from './parachain/assetRegistry';
import { mockGetStakedBalance, mockVotingBalance } from './parachain/escrow';
import {
Expand All @@ -73,16 +60,12 @@ import {
} from './parachain/loans';
import { mockClaimVesting, mockVestingSchedules } from './parachain/vesting';

type RecursivePartial<T> = {
[P in keyof T]?: RecursivePartial<T[P]>;
};

const mockSetAccount = jest.fn((_account: AddressOrPair, _signer?: Signer) => undefined);

const mockCollateralCurrencies = [Polkadot, Interlay];

// To mock new lib methods extend this object.
const mockInterBtcApi: RecursivePartial<InterBtcApi> = {
const mockInterBtcApi: Partial<Record<keyof InterBtcApi, unknown>> = {
removeAccount: jest.fn(),
setAccount: mockSetAccount,
api: {
Expand All @@ -97,6 +80,11 @@ const mockInterBtcApi: RecursivePartial<InterBtcApi> = {
query: {
vesting: {
vestingSchedules: mockVestingSchedules as any
},
oracle: {
aggregate: {
keys: jest.fn().mockReturnValue([])
}
}
},
tx: {
Expand Down Expand Up @@ -154,12 +142,7 @@ const mockInterBtcApi: RecursivePartial<InterBtcApi> = {
getCurrentInclusionFee: mockRedeemGetCurrentInclusionFee,
request: mockRedeemRequest
},
system: {
getStatusCode: mockSystemGetStatusCode,
getFutureBlockNumber: mockGetFutureBlockNumber,
getCurrentActiveBlockNumber: mockGetCurrentActiveBlockNumber,
getCurrentBlockNumber: mockGetCurrentBlockNumber
},
system: MOCK_SYSTEM.MODULE,
tokens: {
balance: mockTokensBalance,
total: mockTokensTotal,
Expand All @@ -171,21 +154,12 @@ const mockInterBtcApi: RecursivePartial<InterBtcApi> = {
getPremiumRedeemVaults: mockVaultsGetPremiumRedeemVaults,
getVaultsWithRedeemableTokens: mockVaultsGetVaultsWithRedeemableTokens
},
amm: {
getLiquidityPools: mockGetLiquidityPools,
getLiquidityProvidedByAccount: mockGetLiquidityProvidedByAccount,
getClaimableFarmingRewards: mockGetClaimableFarmingRewards,
addLiquidity: mockAddLiquidity,
removeLiquidity: mockRemoveLiquidity,
getLpTokens: mockGetLpTokens,
getOptimalTrade: mockGetOptimalTrade,
swap: mockSwap,
claimFarmingRewards: mockClaimFarmingRewards
},
amm: MOCK_AMM.MODULE,
escrow: {
getStakedBalance: mockGetStakedBalance,
votingBalance: mockVotingBalance
}
},
transaction: MOCK_TRANSACTION.MODULE
};

jest.mock('@interlay/interbtc-api', () => {
Expand All @@ -196,12 +170,11 @@ jest.mock('@interlay/interbtc-api', () => {
currencyIdToMonetaryCurrency: jest.fn(),
newAccountId: jest.fn().mockReturnValue('a3aTRC4zs1djutYS9QuZSB3XmfRgNzFfyRtbZKaoQyv67Yzcc'),
getCollateralCurrencies: jest.fn(() => mockCollateralCurrencies),
createInterBtcApi: jest.fn((..._argv) => mockInterBtcApi as InterBtcApi),
FaucetClient: mockFaucet,
createInterBtcApi: jest.fn((..._argv) => mockInterBtcApi),
FaucetClient: jest.fn().mockImplementation(() => ({ fundAccount: jest.fn() })),
newExtrinsicStatus: jest.fn()
};
});

export * from './parachain';
export * from './parachain';
export { mockInterBtcApi, mockSetAccount };
Loading

2 comments on commit aa9470e

@vercel
Copy link

@vercel vercel bot commented on aa9470e Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on aa9470e Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.