Skip to content

Commit

Permalink
feat: mock nfts and txs hiro requests
Browse files Browse the repository at this point in the history
  • Loading branch information
alter-eggo committed Aug 23, 2024
1 parent ea76352 commit 318378d
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/mocks/mock-apis.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Page } from '@playwright/test';
import { json } from '@tests/utils';

import { mockMainnetTestAccountStacksBnsNameRequest } from './mock-stacks-bns';
import { mockStacksFeeRequests } from './mock-stacks-fees';
import { mockMainnetTestAccountStacksNFTsRequest } from './mock-stacks-nfts';
import { mockMainnetTestAccountStacksTxsRequests } from './mock-stacks-txs';
import { mockMainnetTestAccountBitcoinRequests } from './mock-utxos';

export async function setupMockApis(page: Page) {
Expand All @@ -12,5 +15,8 @@ export async function setupMockApis(page: Page) {
page.route('https://api.testnet.hiro.so/', route => route.fulfill()),
mockMainnetTestAccountBitcoinRequests(page),
mockStacksFeeRequests(page),
mockMainnetTestAccountStacksBnsNameRequest(page),
mockMainnetTestAccountStacksTxsRequests(page),
mockMainnetTestAccountStacksNFTsRequest(page),
]);
}
13 changes: 13 additions & 0 deletions tests/mocks/mock-stacks-bns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Page } from '@playwright/test';

import { TEST_ACCOUNT_1_STX_ADDRESS } from './constants';

export async function mockMainnetTestAccountStacksBnsNameRequest(page: Page) {
await page.route(`**/api.hiro.so/v1/addresses/stacks/${TEST_ACCOUNT_1_STX_ADDRESS}`, route =>
route.fulfill({
json: {
names: [],
},
})
);
}
18 changes: 18 additions & 0 deletions tests/mocks/mock-stacks-nfts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { Page } from '@playwright/test';

import { TEST_ACCOUNT_1_STX_ADDRESS } from './constants';

export async function mockMainnetTestAccountStacksNFTsRequest(page: Page) {
await page.route(
`**/api.hiro.so/extended/v1/tokens/nft/holdings?principal=${TEST_ACCOUNT_1_STX_ADDRESS}&limit=50`,
route =>
route.fulfill({
json: {
limit: 50,
offset: 0,
total: 0,
results: [],
},
})
);
}
33 changes: 33 additions & 0 deletions tests/mocks/mock-stacks-txs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { Page } from '@playwright/test';

import { TEST_ACCOUNT_1_STX_ADDRESS } from './constants';

export async function mockMainnetTestAccountStacksTxsRequests(page: Page) {
await Promise.all([
page.route(
`**/api.hiro.so/extended/v1/address/${TEST_ACCOUNT_1_STX_ADDRESS}/transactions_with_transfers?limit=50`,
route =>
route.fulfill({
json: {
limit: 50,
offset: 0,
total: 0,
results: [],
},
})
),

page.route(
`**/api.hiro.so/extended/v1/tx/mempool?address=${TEST_ACCOUNT_1_STX_ADDRESS}&limit=50`,
route =>
route.fulfill({
json: {
limit: 50,
offset: 0,
total: 0,
results: [],
},
})
),
]);
}

0 comments on commit 318378d

Please sign in to comment.