Skip to content

Fix the widget tests expecting undefined apiBaseUrl#618

Open
Fabcien wants to merge 1 commit intoPayButton:masterfrom
Fabcien:fix_tests
Open

Fix the widget tests expecting undefined apiBaseUrl#618
Fabcien wants to merge 1 commit intoPayButton:masterfrom
Fabcien:fix_tests

Conversation

@Fabcien
Copy link
Contributor

@Fabcien Fabcien commented Feb 19, 2026

The tests have been broken by 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 whatever is set in the config so we oblige.

Test Plan:
yarn test

Summary by CodeRabbit

  • Tests
    • Updated test expectations to verify that the configured API base URL is correctly passed to payment creation calls across multiple payment scenarios, including crypto and fiat pathways.

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
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 19, 2026

📝 Walkthrough

Walkthrough

Updates test assertions in Widget.test.tsx to expect config.apiBaseUrl as the third argument to createPayment calls instead of undefined across multiple test scenarios for crypto standalone, fiat pathways, and undefined amount handling.

Changes

Cohort / File(s) Summary
Test Assertions Update
react/lib/tests/components/Widget.test.tsx
Adds import of paybutton-config.json as config and updates test expectations to assert config.apiBaseUrl is passed as the third argument to createPayment in crypto standalone (initial and amount change), fiat pathway (initial and regeneration), and undefined amount test scenarios.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • chedieck
  • lissavxo

Poem

🐰 A config that hops into view,
Test cases now know what is true,
The API base URL,
Makes assertions brand new,
The widget works better on cue!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: fixing widget tests to expect the configured apiBaseUrl instead of undefined.
Description check ✅ Passed The description includes the related commit reference, explains the issue and fix rationale, and provides a test plan using yarn test.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
react/lib/tests/components/Widget.test.tsx (1)

267-270: Optional: extend lastCall[2] checks for consistency.

These regeneration tests verify lastCall[0] and lastCall[1] but skip the apiBaseUrl argument, while the initial-render tests at lines 66, 199, and 226 do check it. For uniform coverage, consider adding expect(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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 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 f

Repository: 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:

  1. Create react/lib/paybutton-config.json (likely by copying example-config.json), or
  2. Update the import on line 10 to reference ../../example-config.json instead

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments