test: adds msw (#3913)
## Problem solved
Short description of the bug fixed or feature added
<!-- start pr-codex -->
---
## PR-Codex overview
The focus of this PR is to add `msw` for network call mocking, update dependencies, and enhance wallet integration tests.
### Detailed summary
- Added `msw` for network call mocking in tests
- Updated dependencies
- Improved wallet integration tests with new functions
> The following files were skipped due to too many changes: `pnpm-lock.yaml`
> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`
<!-- end pr-codex -->
This commit is contained in:
@@ -77,6 +77,21 @@ Many of the tests use forked versions of live chains like mainnet. We fork these
|
||||
|
||||
If you need to use accounts in your tests, use the predefined accounts in `test/src/test-wallets.ts`. These are the default anvil accounts that are pre-funded on the local test forks.
|
||||
|
||||
##### Mocking Network Calls
|
||||
|
||||
If your test depends on a downstream network call, you must mock the call using `msw`. You can use one of the existing mocks in `test/src/mocks` or create your own. Once you've created a mock request, setup the server and add all your mocks like so:
|
||||
|
||||
```ts
|
||||
import { setupServer } from "msw/node";
|
||||
import { downloadMock, uploadMock } from "../../../test/src/mocks/storage.js";
|
||||
|
||||
const server = setupServer(uploadMock("HASH"), downloadMock({ name: "Test NFT" }));
|
||||
|
||||
beforeAll(() => server.listen());
|
||||
afterEach(() => server.resetHandlers());
|
||||
afterAll(() => server.close());
|
||||
```
|
||||
|
||||
#### Linting
|
||||
|
||||
We use a linter to maintain best practices across projects. Once your changes are complete (or periodically while making changes), run the linter with the following command from the repo root:
|
||||
|
||||
@@ -323,11 +323,12 @@
|
||||
"expo-linking": "6.3.1",
|
||||
"expo-web-browser": "13.0.3",
|
||||
"happy-dom": "^14.12.0",
|
||||
"msw": "^2.3.4",
|
||||
"react-native": "0.74.2",
|
||||
"react-native-aes-gcm-crypto": "0.2.2",
|
||||
"react-native-quick-crypto": "0.7.0-rc.6",
|
||||
"react-native-svg": "15.3.0",
|
||||
"vitest": "1.6.0",
|
||||
"typescript": "5.5.2"
|
||||
"typescript": "5.5.2",
|
||||
"vitest": "1.6.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import { setContractURI } from "../../extensions/marketplace/__generated__/IMark
|
||||
import { estimateGasCost } from "../../transaction/actions/estimate-gas-cost.js";
|
||||
import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
|
||||
import { sendBatchTransaction } from "../../transaction/actions/send-batch-transaction.js";
|
||||
import { waitForReceipt } from "../../transaction/actions/wait-for-tx-receipt.js";
|
||||
import { isContractDeployed } from "../../utils/bytecode/is-contract-deployed.js";
|
||||
import type { Account, Wallet } from "../interfaces/wallet.js";
|
||||
import { generateAccount } from "../utils/generateAccount.js";
|
||||
@@ -139,6 +140,11 @@ describe.runIf(process.env.TW_SECRET_KEY)(
|
||||
],
|
||||
});
|
||||
expect(tx.transactionHash).toHaveLength(66);
|
||||
await waitForReceipt({
|
||||
client,
|
||||
transactionHash: tx.transactionHash,
|
||||
chain,
|
||||
});
|
||||
const balance = await balanceOf({
|
||||
contract,
|
||||
owner: smartWalletAddress,
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import { getThirdwebDomains } from '../../../src/utils/domains.js';
|
||||
|
||||
export const uploadMock = (mockHash: string) => http.post(`https://${getThirdwebDomains().storage}/ipfs/upload`, async () => {
|
||||
return HttpResponse.json({
|
||||
IpfsHash: mockHash
|
||||
})
|
||||
});
|
||||
|
||||
export const downloadMock = (mockData: unknown) => http.get(`https://*.ipfscdn.io/ipfs/:hash/:id`, async () => {
|
||||
return HttpResponse.json(mockData ?? {});
|
||||
});
|
||||
|
||||
Generated
+684
-186
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user