Skip to content

feat(s3): infrastructure persistence tests — 21 adapter ITs (STA-123)#125

Merged
Puneethkumarck merged 1 commit into
mainfrom
feature/STA-123-s3-persistence-tests
Mar 8, 2026
Merged

feat(s3): infrastructure persistence tests — 21 adapter ITs (STA-123)#125
Puneethkumarck merged 1 commit into
mainfrom
feature/STA-123-s3-persistence-tests

Conversation

@Puneethkumarck

@Puneethkumarck Puneethkumarck commented Mar 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • CollectionOrderPersistenceAdapterIT (10 tests): CRUD, findByPaymentId, unique constraint enforcement, full happy path (PENDING→COLLECTED), refund path (COLLECTED→REFUNDED), failure path, amount mismatch + manual review, nullable fields
  • RefundPersistenceAdapterIT (6 tests): CRUD, findByCollectionId, completion path (PENDING→COMPLETED), failure path (PENDING→FAILED)
  • PspTransactionPersistenceAdapterIT (5 tests): CRUD, append-only pattern, multiple txns per collection, JSONB round-trip, direction enum values

Total: 235 tests (214 unit + 21 IT)

Test plan

  • All 21 integration tests pass with TestContainers PostgreSQL
  • Spotless formatting verified
  • Single-assert pattern used throughout (recursive comparison)

Closes STA-123

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added integration tests for collection order persistence, covering save/retrieve operations, state transitions, and constraint enforcement
    • Added integration tests for transaction persistence, validating data storage and state management
    • Added integration tests for refund persistence, covering state transitions and multi-record retrieval

CollectionOrderPersistenceAdapterIT (10 tests): CRUD, findByPaymentId,
unique constraint, full happy path, refund path, failure path, amount
mismatch + manual review, nullable fields.

RefundPersistenceAdapterIT (6 tests): CRUD, findByCollectionId,
completion path, failure path.

PspTransactionPersistenceAdapterIT (5 tests): CRUD, append-only,
multiple txns, JSONB round-trip, direction enum values.

Closes STA-123

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Puneethkumarck Puneethkumarck added the phase-3 Value Movement MVP label Mar 8, 2026
@coderabbitai

coderabbitai Bot commented Mar 8, 2026

Copy link
Copy Markdown

Walkthrough

Three new integration test classes are added to verify persistence layer behavior for CollectionOrder, PspTransaction, and Refund domain models. Tests validate CRUD operations, state machine transitions, constraint enforcement (unique paymentId), JSON/enum serialization round-trips, and null field handling using Spring repositories and AssertJ assertions.

Changes

Cohort / File(s) Summary
Persistence Adapter Integration Tests
CollectionOrderPersistenceAdapterIT, PspTransactionPersistenceAdapterIT, RefundPersistenceAdapterIT
Add comprehensive integration test suites for repository persistence adapters. Tests cover save/retrieve operations, state transitions (COLLECTED, refund, failure paths), constraint validation (unique paymentId), JSON round-trips for rawResponse, enum serialization, and nullable field handling. All use Spring-wired repositories, fixtures, and recursive equality assertions ignoring temporal fields.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • PR #121: Introduced CollectionOrder and Refund domain model fixtures and baseline coverage that these integration tests directly depend on and expand.

Suggested labels

test, service-s3

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 56.52% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed Title directly describes the main change: adding 21 integration tests for persistence adapters with clear scope and ticket reference.
Description check ✅ Passed Description covers test counts, adapter scope, test plan verification, and issue closure; matches template structure with populated Summary, Related Issue, Type of Change, and How Was It Tested sections.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/STA-123-s3-persistence-tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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/integration-test/java/com/stablecoin/payments/onramp/infrastructure/persistence/PspTransactionPersistenceAdapterIT.java`:
- Around line 101-115: The test shouldPersistAllDirectionEnumValues currently
only checks row count; update it to verify the persisted direction values
round-trip correctly by fetching transactions via
adapter.findByCollectionId(order.collectionId()), mapping each returned
PspTransaction's direction (e.g., txn.direction() or getDirection()) into a set,
and asserting that this set equals EnumSet.allOf(PspTransactionDirection.class)
(or the list of PspTransactionDirection.values()), ensuring every enum constant
was persisted distinctly; use the existing PspTransaction.create and
PspTransactionDirection symbols to build the expected values and compare against
the persisted directions.

In
`@fiat-on-ramp/fiat-on-ramp/src/integration-test/java/com/stablecoin/payments/onramp/infrastructure/persistence/RefundPersistenceAdapterIT.java`:
- Around line 49-63: The test should verify the actual refunds returned by
adapter.findByCollectionId(...) rather than only the count: after saving
refund1/refund2 (saved1, saved2) in shouldFindByCollectionId, assert that
results contains those saved entities (e.g., compare IDs from
saved1.getId()/saved2.getId() or use object equality) and optionally validate
key fields (collectionId/paymentId/amount) to prove proper filtering; update the
assertion on results to check presence/equality of saved1 and saved2 instead of
only hasSize(2).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 76830086-cb62-4a59-a2bc-d2db27240ba3

📥 Commits

Reviewing files that changed from the base of the PR and between a6ac620 and cef7443.

📒 Files selected for processing (3)
  • fiat-on-ramp/fiat-on-ramp/src/integration-test/java/com/stablecoin/payments/onramp/infrastructure/persistence/CollectionOrderPersistenceAdapterIT.java
  • fiat-on-ramp/fiat-on-ramp/src/integration-test/java/com/stablecoin/payments/onramp/infrastructure/persistence/PspTransactionPersistenceAdapterIT.java
  • fiat-on-ramp/fiat-on-ramp/src/integration-test/java/com/stablecoin/payments/onramp/infrastructure/persistence/RefundPersistenceAdapterIT.java

Comment on lines +101 to +115
@Test
@DisplayName("should persist all direction enum values")
void shouldPersistAllDirectionEnumValues() {
var order = saveCollectionOrder();

for (var direction : PspTransactionDirection.values()) {
var txn = PspTransaction.create(
order.collectionId(), "Stripe", "ref_" + direction.name(),
direction, "event_" + direction.name(), aMoney(),
"completed", "{}");
adapter.save(txn);
}

assertThat(adapter.findByCollectionId(order.collectionId()))
.hasSize(PspTransactionDirection.values().length);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Assert persisted directions, not only row count.

Line 114 only proves inserts happened. If the enum mapping collapses every value to the same persisted value, this test still passes. Extract the direction field so the round-trip is actually covered.

Patch
-        assertThat(adapter.findByCollectionId(order.collectionId()))
-                .hasSize(PspTransactionDirection.values().length);
+        assertThat(adapter.findByCollectionId(order.collectionId()))
+                .extracting(PspTransaction::direction)
+                .containsExactlyInAnyOrder(PspTransactionDirection.values());
🤖 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/integration-test/java/com/stablecoin/payments/onramp/infrastructure/persistence/PspTransactionPersistenceAdapterIT.java`
around lines 101 - 115, The test shouldPersistAllDirectionEnumValues currently
only checks row count; update it to verify the persisted direction values
round-trip correctly by fetching transactions via
adapter.findByCollectionId(order.collectionId()), mapping each returned
PspTransaction's direction (e.g., txn.direction() or getDirection()) into a set,
and asserting that this set equals EnumSet.allOf(PspTransactionDirection.class)
(or the list of PspTransactionDirection.values()), ensuring every enum constant
was persisted distinctly; use the existing PspTransaction.create and
PspTransactionDirection symbols to build the expected values and compare against
the persisted directions.

Comment on lines +49 to +63
@Test
@DisplayName("should find by collection id")
void shouldFindByCollectionId() {
var order = saveCollectionOrder();
var refund1 = Refund.initiate(order.collectionId(), order.paymentId(), aRefundAmount(), REFUND_REASON);
var saved1 = adapter.save(refund1);

var refund2 = Refund.initiate(
order.collectionId(), order.paymentId(),
new Money(new BigDecimal("500.00"), "USD"), "Partial refund");
var saved2 = adapter.save(refund2);

var results = adapter.findByCollectionId(order.collectionId());
assertThat(results).hasSize(2);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Assert the returned refunds, not just the count.

Line 62 only validates cardinality. A broken repository predicate that returns any two refunds would still pass. Use the saved IDs or full object comparison so this test proves findByCollectionId(...) is filtering correctly.

Patch
-        var results = adapter.findByCollectionId(order.collectionId());
-        assertThat(results).hasSize(2);
+        assertThat(adapter.findByCollectionId(order.collectionId()))
+                .extracting(Refund::refundId)
+                .containsExactlyInAnyOrder(saved1.refundId(), saved2.refundId());
🤖 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/integration-test/java/com/stablecoin/payments/onramp/infrastructure/persistence/RefundPersistenceAdapterIT.java`
around lines 49 - 63, The test should verify the actual refunds returned by
adapter.findByCollectionId(...) rather than only the count: after saving
refund1/refund2 (saved1, saved2) in shouldFindByCollectionId, assert that
results contains those saved entities (e.g., compare IDs from
saved1.getId()/saved2.getId() or use object equality) and optionally validate
key fields (collectionId/paymentId/amount) to prove proper filtering; update the
assertion on results to check presence/equality of saved1 and saved2 instead of
only hasSize(2).

@Puneethkumarck Puneethkumarck merged commit 893c2a3 into main Mar 8, 2026
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

phase-3 Value Movement MVP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant