Fix the widget tests expecting undefined apiBaseUrl#618
Fix the widget tests expecting undefined apiBaseUrl#618Fabcien wants to merge 1 commit intoPayButton:masterfrom
Conversation
The tests have been broken by PayButton@bf800cc. The tests expects `createPayment` to be called; the apiBaseUrl is irrelevant for the tests but the params needs to be checked including this one. The above commit changed the default from undefined to https://paybutton.org so we oblige. Test Plan: yarn test
📝 WalkthroughWalkthroughUpdates test assertions in Widget.test.tsx to expect Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
react/lib/tests/components/Widget.test.tsx (1)
267-270: Optional: extendlastCall[2]checks for consistency.These regeneration tests verify
lastCall[0]andlastCall[1]but skip theapiBaseUrlargument, while the initial-render tests at lines 66, 199, and 226 do check it. For uniform coverage, consider addingexpect(lastCall[2]).toBe(config.apiBaseUrl)to both blocks.♻️ Proposed consistency fix
const lastCall = (createPayment as jest.Mock).mock.calls[1] expect(lastCall[0]).toBe(90 / price) expect(lastCall[1]).toBe(to) + expect(lastCall[2]).toBe(config.apiBaseUrl)const lastCall = (createPayment as jest.Mock).mock.calls[1] expect(lastCall[0]).toBe(8) expect(lastCall[1]).toBe(to) + expect(lastCall[2]).toBe(config.apiBaseUrl)Also applies to: 307-308
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@react/lib/tests/components/Widget.test.tsx` around lines 267 - 270, Add an assertion that the third argument passed to the mocked createPayment is the API base URL for consistency: after grabbing lastCall from (createPayment as jest.Mock).mock.calls, add expect(lastCall[2]).toBe(config.apiBaseUrl). Apply this change to the shown regeneration test block (where lastCall[0] and lastCall[1] are asserted) and the similar block around the other occurrence (the one at the other failing assertions), referencing the same createPayment mock and config.apiBaseUrl symbols.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@react/lib/tests/components/Widget.test.tsx`:
- Line 10: The failing import in Widget.test.tsx uses
'../../paybutton-config.json' which doesn't exist; update the import to use
'../../example-config.json' (or add a new paybutton-config.json copied from
example-config.json) and apply the same fix in WidgetContainer.tsx so both the
test (Widget.test.tsx) and the component (WidgetContainer.tsx) load the valid
config (look for the import statements referencing paybutton-config.json and
replace them or add the missing file).
---
Nitpick comments:
In `@react/lib/tests/components/Widget.test.tsx`:
- Around line 267-270: Add an assertion that the third argument passed to the
mocked createPayment is the API base URL for consistency: after grabbing
lastCall from (createPayment as jest.Mock).mock.calls, add
expect(lastCall[2]).toBe(config.apiBaseUrl). Apply this change to the shown
regeneration test block (where lastCall[0] and lastCall[1] are asserted) and the
similar block around the other occurrence (the one at the other failing
assertions), referencing the same createPayment mock and config.apiBaseUrl
symbols.
| import copyToClipboard from 'copy-to-clipboard' | ||
| import type { Currency } from '../../util' | ||
| import { isFiat } from '../../util'; | ||
| import config from '../../paybutton-config.json' |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# 1. Confirm paybutton-config.json exists at the expected path
echo "=== Searching for paybutton-config.json ==="
fd -e json "paybutton-config.json" 2>/dev/null || echo "No matches found"
# 2. Print its contents to verify apiBaseUrl is present
echo -e "\n=== Contents of paybutton-config.json ==="
fd -e json "paybutton-config.json" -x cat {} 2>/dev/null || echo "File not found"
# 3. Verify Jest config handles JSON imports
echo -e "\n=== Jest configuration ==="
fd "jest.config" -type f | head -5 | xargs -I {} sh -c 'echo "File: {}"; cat {}' 2>/dev/null || echo "Jest config not found"
# 4. Check package.json for Jest config inline
echo -e "\n=== Jest config in package.json ==="
fd "package.json" -type f | head -1 | xargs -I {} sh -c 'cat {} | grep -A 20 "jest"' 2>/dev/null || echo "No Jest config in package.json"Repository: PayButton/paybutton
Length of output: 573
🏁 Script executed:
#!/bin/bash
# 1. List all JSON files in the repo
echo "=== All JSON files in repo ==="
find . -name "*.json" -type f | grep -E "(paybutton|jest|package)" | head -20
# 2. Check directory structure of react/lib
echo -e "\n=== Files in react/lib ==="
find react/lib -maxdepth 2 -type f -name "*.json" 2>/dev/null | head -20
# 3. Check if Widget.test.tsx exists
echo -e "\n=== Widget.test.tsx location ==="
find . -name "Widget.test.tsx" -type f 2>/dev/null
# 4. Look for any jest.config file
echo -e "\n=== Jest config files ==="
find . -name "jest.config*" -type f 2>/dev/null | head -10
# 5. Check package.json for jest config
echo -e "\n=== Package.json with jest section ==="
find . -name "package.json" -type f | head -1 | xargs grep -A 15 '"jest"' 2>/dev/null || echo "No jest in package.json"Repository: PayButton/paybutton
Length of output: 573
🏁 Script executed:
#!/bin/bash
# 1. Read Widget.test.tsx around line 10 to see the actual import
echo "=== Widget.test.tsx lines 1-30 ==="
head -30 "./react/lib/tests/components/Widget.test.tsx"
# 2. Check jest.config.js to see JSON handling config
echo -e "\n=== Jest config (react/jest.config.js) ==="
cat "./react/jest.config.js"
# 3. Look for WidgetContainer or Widget component definition
echo -e "\n=== WidgetContainer location ==="
find ./react -name "WidgetContainer*" -o -name "Widget.tsx" -o -name "Widget.jsx" | head -10
# 4. Check what config files actually exist in react directory
echo -e "\n=== All config files in react/lib ==="
find ./react/lib -name "*config*" -type fRepository: PayButton/paybutton
Length of output: 2592
🏁 Script executed:
#!/bin/bash
# 1. Check example-config.json to see if it has apiBaseUrl
echo "=== example-config.json contents ==="
cat "./react/lib/example-config.json"
# 2. Read WidgetContainer.tsx to check how createPayment is called
echo -e "\n=== WidgetContainer.tsx first 100 lines ==="
head -100 "./react/lib/components/Widget/WidgetContainer.tsx"
# 3. Search for createPayment calls in WidgetContainer
echo -e "\n=== All createPayment calls in WidgetContainer ==="
grep -n "createPayment" "./react/lib/components/Widget/WidgetContainer.tsx"
# 4. Check git log for recent changes to paybutton-config files
echo -e "\n=== Git log for config files ==="
git log --oneline -20 -- "*paybutton-config*" "*example-config*" 2>/dev/null || echo "No git history"Repository: PayButton/paybutton
Length of output: 3308
🏁 Script executed:
#!/bin/bash
# 1. Check git history for paybutton-config.json (was it deleted?)
echo "=== Git history showing paybutton-config.json ==="
git log --all --full-history -- "react/lib/paybutton-config.json" 2>/dev/null | head -30 || echo "No history"
# 2. Check if paybutton-config.json was ever committed
echo -e "\n=== Check git ls-files for paybutton-config.json ==="
git ls-files "react/lib/paybutton-config.json" 2>/dev/null || echo "Not in git index"
# 3. Look at the recent commit that mentioned undefined apiBaseUrl
echo -e "\n=== Git show for commit a354dfc ==="
git show a354dfc --stat 2>/dev/null | head -50
# 4. Check if there's a build script that generates paybutton-config.json
echo -e "\n=== Build/generate scripts in package.json ==="
cat "./react/package.json" | grep -A 20 '"scripts"'
# 5. Look at the actual test to see what it expects
echo -e "\n=== Widget.test.tsx around assertions (lines 60-70) ==="
sed -n '60,70p' "./react/lib/tests/components/Widget.test.tsx"Repository: PayButton/paybutton
Length of output: 4474
The import on line 10 references a non-existent file that will cause tests to fail at load time.
The file react/lib/paybutton-config.json does not exist in the repository. This import will throw a MODULE_NOT_FOUND error when Jest tries to load the test file, preventing any tests from running.
The existing react/lib/example-config.json contains the required apiBaseUrl key. Either:
- Create
react/lib/paybutton-config.json(likely by copyingexample-config.json), or - Update the import on line 10 to reference
../../example-config.jsoninstead
Note: WidgetContainer.tsx has the same broken import and will need the same fix.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@react/lib/tests/components/Widget.test.tsx` at line 10, The failing import in
Widget.test.tsx uses '../../paybutton-config.json' which doesn't exist; update
the import to use '../../example-config.json' (or add a new
paybutton-config.json copied from example-config.json) and apply the same fix in
WidgetContainer.tsx so both the test (Widget.test.tsx) and the component
(WidgetContainer.tsx) load the valid config (look for the import statements
referencing paybutton-config.json and replace them or add the missing file).
The tests have been broken by bf800cc. The tests expects
createPaymentto be called; the apiBaseUrl is irrelevant for the tests but the params needs to be checked including this one. The above commit changed the default from undefined to whatever is set in the config so we oblige.Test Plan:
yarn test
Summary by CodeRabbit