Skip to content

Commit d6f454e

Browse files
test: address review feedback on Tier 1 test suite
- Fix env.test.ts test names that incorrectly claimed to test defaults while .env.test was setting those vars explicitly - Assert exact value for PUBLIC_WALLETCONNECT_PROJECT_ID (was typeof check) - Fix createMockWeb3Status shape to match actual Web3Status interface (was using isConnected/chainId/publicClient; hook uses isWalletConnected/ walletChainId/readOnlyClient) - Hardcode expected explorer URL in getExplorerLink assertions instead of deriving from mock chain (prevents false positives if mock misconfigured)
1 parent bc9c7bd commit d6f454e

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

src/env.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ describe('env', () => {
1111
expect(env.PUBLIC_APP_NAME).toBe('dAppBooster Test')
1212
})
1313

14-
it('defaults PUBLIC_NATIVE_TOKEN_ADDRESS to zero address when not set', () => {
15-
// .env.test sets it to the zero address explicitly
14+
it('reads and normalizes PUBLIC_NATIVE_TOKEN_ADDRESS from env', () => {
15+
// .env.test sets it to the zero address; the schema lowercases the value
1616
expect(env.PUBLIC_NATIVE_TOKEN_ADDRESS).toBe(zeroAddress.toLowerCase())
1717
})
1818

@@ -32,17 +32,18 @@ describe('env', () => {
3232
expect(env.PUBLIC_INCLUDE_TESTNETS).toBe(true)
3333
})
3434

35-
it('defaults PUBLIC_SUBGRAPHS_ENVIRONMENT to production', () => {
35+
it('reads PUBLIC_SUBGRAPHS_ENVIRONMENT from test env', () => {
36+
// .env.test sets it to 'production'; to test the schema default use vi.resetModules()
3637
expect(env.PUBLIC_SUBGRAPHS_ENVIRONMENT).toBe('production')
3738
})
3839

3940
it('exposes PUBLIC_SUBGRAPHS_API_KEY from test env', () => {
4041
expect(env.PUBLIC_SUBGRAPHS_API_KEY).toBe('test-api-key')
4142
})
4243

43-
it('exposes PUBLIC_WALLETCONNECT_PROJECT_ID with empty string default', () => {
44+
it('exposes PUBLIC_WALLETCONNECT_PROJECT_ID from test env', () => {
4445
// .env.test sets it to 'test-project-id'
45-
expect(typeof env.PUBLIC_WALLETCONNECT_PROJECT_ID).toBe('string')
46+
expect(env.PUBLIC_WALLETCONNECT_PROJECT_ID).toBe('test-project-id')
4647
})
4748

4849
it('optional RPC vars are undefined when not set in test env', () => {

src/test-utils.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,21 @@ export function createMockWeb3Status(overrides?: Partial<ReturnType<typeof _mock
2222

2323
function _mockShape() {
2424
return {
25+
// AppWeb3Status
26+
readOnlyClient: undefined,
27+
appChainId: 1 as number,
28+
// WalletWeb3Status
2529
address: undefined as `0x${string}` | undefined,
26-
isConnected: false,
27-
isConnecting: false,
28-
isDisconnected: true,
29-
chainId: undefined as number | undefined,
3030
balance: undefined,
31-
publicClient: undefined,
31+
connectingWallet: false,
32+
switchingChain: false,
33+
isWalletConnected: false,
3234
walletClient: undefined,
35+
isWalletSynced: false,
36+
walletChainId: undefined as number | undefined,
37+
// Web3Actions
3338
disconnect: () => {},
34-
switchChain: undefined,
39+
switchChain: (_chainId?: number) => {},
3540
}
3641
}
3742

src/utils/getExplorerLink.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ const txHash = '0xd85ef8c70dc31a4f8d5bf0331e1eac886935905f15d32e71b348df745cd38e
1212
describe('getExplorerLink', () => {
1313
it('returns address URL using chain block explorer', () => {
1414
const url = getExplorerLink({ chain, hashOrAddress: address })
15-
expect(url).toBe(`${chain.blockExplorers?.default.url}/address/${address}`)
15+
expect(url).toBe(`https://mock.explorer.url/address/${address}`)
1616
})
1717

1818
it('returns tx URL using chain block explorer for a hash', () => {
1919
const url = getExplorerLink({ chain, hashOrAddress: txHash })
20-
expect(url).toBe(`${chain.blockExplorers?.default.url}/tx/${txHash}`)
20+
expect(url).toBe(`https://mock.explorer.url/tx/${txHash}`)
2121
})
2222

2323
it('uses custom explorerUrl for an address', () => {

0 commit comments

Comments
 (0)