test: add unit tests for env validation, middleware CSP, and wallet connectors - #979
Merged
nanaf6203-bit merged 2 commits intoAug 31, 2026
Merged
Conversation
…onnectors Add comprehensive test coverage for three untested modules assigned to eulami (issues MettaChain#935, MettaChain#936, MettaChain#937): - src/config/env/__tests__/schema.test.ts: Tests for validateEnv and validateEnvRequirements covering defaults, type coercion, enum validation, and environment-specific requirements (dev/staging/prod). - src/__tests__/middleware.test.ts: Tests for CSP header generation, nonce uniqueness, dev-vs-prod directive differences, API path skipping, and x-nonce request header injection. - src/lib/walletConnectors/__tests__/walletConnectors.test.ts: Tests for MetaMask, Coinbase, and WalletConnect adapter mappings covering success paths, missing wallet, wrong provider, user rejection, pending request errors, and availability checks. Also renames jest.config.js → jest.config.cjs to fix ESM/CJS conflict with "type": "module" in package.json, and removes the global @walletconnect/web3-provider mock from jest.setup.js (now per-test). Closes MettaChain#935, closes MettaChain#936, closes MettaChain#937 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
nanaf6203-bit
approved these changes
Aug 31, 2026
🔒 Preview Environment DestroyedThe preview environment for this PR has been torn down. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds comprehensive unit test coverage for three untested modules assigned to eulami, closing all three issues in a single PR. Also fixes a Jest configuration issue that prevented tests from running.
Closes #935 —
requireEnv(env validation) testsNew file:
src/config/env/__tests__/schema.test.tsTests
validateEnvandvalidateEnvRequirementscovering:NEXT_PUBLIC_APP_NAME,NODE_ENV, etc.)CSP_ENFORCE,NEXT_PUBLIC_DEBUG_MODE)NODE_ENVrejectionCloses #936 — Middleware CSP tests
New file:
src/__tests__/middleware.test.tsTests CSP header generation covering:
CSP_ENFORCEis nottruedefault-src 'self',script-srcwith nonce)/api/*) bypass CSP entirelyAcceptheaders bypass CSPupgrade-insecure-requestsdirective present in production onlyunsafe-evalpresent in development, excluded in productionx-nonceheader injected into outgoing requestsCloses #937 — Wallet connector adapter tests
New file:
src/lib/walletConnectors/__tests__/walletConnectors.test.ts23 tests covering all three adapter modules:
Infrastructure
jest.config.js→jest.config.cjs— fixesrequire()in ESM context ("type": "module"inpackage.json)@walletconnect/web3-providermock fromjest.setup.js— now controlled per-test for WalletConnect-specific behaviorTest results