feat(s3): business tests — 7 E2E collection lifecycle flows (STA-130)#144
Conversation
Add business tests exercising full collection lifecycle through real Spring context with TestContainers PostgreSQL + Kafka: - Happy path: POST collection -> Stripe webhook -> COLLECTED + outbox - Collection failure: webhook with failure -> COLLECTION_FAILED - Amount mismatch: webhook with wrong amount -> AMOUNT_MISMATCH - Refund compensation: COLLECTED -> POST refund -> REFUNDED + outbox - Idempotency: same paymentId -> 200 OK with same collectionId - Expired collection: past expiresAt -> COLLECTION_FAILED via handler - Webhook idempotency: duplicate webhook ignored for collected order Closes STA-130 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
WalkthroughAdds two new test classes to establish a business test framework for the fiat-on-ramp module: AbstractBusinessTest serves as a semantic base for end-to-end tests running within the full Spring context, while CollectionLifecycleTest provides comprehensive test coverage for collection order lifecycle operations including creation, webhooks, refunds, and idempotency scenarios. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@fiat-on-ramp/fiat-on-ramp/src/business-test/java/com/stablecoin/payments/onramp/CollectionLifecycleTest.java`:
- Around line 116-121: The current extractField helper uses fragile string
parsing; replace its implementation to use a JSON parser such as JsonPath or
Jackson to safely extract the field value. Locate the extractField method and
change it to call JsonPath.read(jsonResponse, "$." + fieldName) (or parse with
ObjectMapper.readTree(jsonResponse).get(fieldName).asText()) so extraction
handles nested objects, escaped characters and ordering; ensure you handle
missing fields/nulls consistently and update any tests that rely on the old
behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: d4cbe481-73cf-4775-b7b8-6e10f125126d
📒 Files selected for processing (2)
fiat-on-ramp/fiat-on-ramp/src/business-test/java/com/stablecoin/payments/onramp/AbstractBusinessTest.javafiat-on-ramp/fiat-on-ramp/src/business-test/java/com/stablecoin/payments/onramp/CollectionLifecycleTest.java
| private static String extractField(String jsonResponse, String fieldName) { | ||
| var pattern = "\"" + fieldName + "\":\""; | ||
| var start = jsonResponse.indexOf(pattern) + pattern.length(); | ||
| var end = jsonResponse.indexOf("\"", start); | ||
| return jsonResponse.substring(start, end); | ||
| } |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Consider using JsonPath for JSON extraction.
The extractField helper uses naive string parsing that breaks with nested objects, escaped quotes, or field reordering. Since MockMvc already provides JsonPath integration, consider:
JsonPath.read(jsonResponse, "$." + fieldName)Alternatively, use ObjectMapper.readTree() for type-safe extraction.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@fiat-on-ramp/fiat-on-ramp/src/business-test/java/com/stablecoin/payments/onramp/CollectionLifecycleTest.java`
around lines 116 - 121, The current extractField helper uses fragile string
parsing; replace its implementation to use a JSON parser such as JsonPath or
Jackson to safely extract the field value. Locate the extractField method and
change it to call JsonPath.read(jsonResponse, "$." + fieldName) (or parse with
ObjectMapper.readTree(jsonResponse).get(fieldName).asText()) so extraction
handles nested objects, escaped characters and ordering; ensure you handle
missing fields/nulls consistently and update any tests that rely on the old
behavior.
Summary
@PrimaryPspGateway with predictable pspReferences so webhook tests can match the PSP reference from collection creationTest plan
./gradlew :fiat-on-ramp:fiat-on-ramp:businessTest— 7 tests pass./gradlew :fiat-on-ramp:fiat-on-ramp:check— full check (unit + IT + business + JaCoCo) passesCloses STA-130
🤖 Generated with Claude Code
Summary by CodeRabbit