fix(payment): project wallet prerequisites on refresh

chore/issuance-comments-zh
chenyuan 4 weeks ago
parent 2289aa94a1
commit 5e66219d26

@ -49,14 +49,14 @@ public class JdbcPaymentResourceRepository implements PaymentResourceRepository
@Override
public PaymentParticipant loadPayer(PaymentActor actor) {
WalletPrerequisiteReference reference = walletProjection.referenceForSubject(
WalletPrerequisiteReference reference = walletProjection.ensureForSubject(
new InstitutionKeySubject(actor.getUserId(), actor.getSchoolId(), actor.getClassId()));
return loadParticipant(reference);
}
@Override
public PaymentParticipant loadPayee(String payeeWalletId) {
return loadParticipant(walletProjection.referenceForWallet(payeeWalletId));
return loadParticipant(walletProjection.ensureForWallet(payeeWalletId));
}
@Override

@ -198,6 +198,39 @@ class PaymentControllerTest {
String.class)).isEqualTo("TRANSFERRED");
}
@Test
void refreshActionsProjectCompletedModuleThreeWalletsWhenSharedRowsAreMissing() throws Exception {
clearSharedWalletProjection();
assertThat(jdbc.queryForObject("SELECT COUNT(*) FROM digital_wallet WHERE wallet_id IN (?,?)",
Integer.class, PAYER_WALLET, PAYEE_WALLET)).isZero();
String created = mockMvc.perform(post("/api/v1/payment/attempts").with(payer()))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
String attemptId = JsonPath.read(created, "$.data.attemptId");
mockMvc.perform(post("/api/v1/payment/attempts/{id}/steps/01/actions/refresh-payer", attemptId)
.with(payer()).contentType(MediaType.APPLICATION_JSON).content("{}"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.actionStatus").value("COMPLETED"))
.andExpect(jsonPath("$.data.output.walletId").value(PAYER_WALLET));
mockMvc.perform(post("/api/v1/payment/attempts/{id}/steps/01/actions/refresh-payee", attemptId)
.with(payer()).contentType(MediaType.APPLICATION_JSON)
.content("{\"payeeWalletId\":\"" + PAYEE_WALLET + "\"}"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.actionStatus").value("COMPLETED"))
.andExpect(jsonPath("$.data.output.walletId").value(PAYEE_WALLET));
assertThat(jdbc.queryForObject("SELECT COUNT(*) FROM digital_wallet WHERE wallet_id IN (?,?)",
Integer.class, PAYER_WALLET, PAYEE_WALLET)).isEqualTo(2);
assertThat(jdbc.queryForObject("SELECT COUNT(*) FROM wallet_certificate WHERE wallet_id IN (?,?)",
Integer.class, PAYER_WALLET, PAYEE_WALLET)).isEqualTo(2);
assertThat(jdbc.queryForObject("SELECT COUNT(*) FROM wallet_contract WHERE wallet_id IN (?,?)",
Integer.class, PAYER_WALLET, PAYEE_WALLET)).isEqualTo(2);
assertThat(jdbc.queryForObject("SELECT COUNT(*) FROM wallet_bank_binding WHERE wallet_id IN (?,?)",
Integer.class, PAYER_WALLET, PAYEE_WALLET)).isEqualTo(2);
}
@Test
void rejectsPaymentWhenPayerHasNoWalletOwnedCoins() throws Exception {
String created = mockMvc.perform(post("/api/v1/payments").with(payer()).contentType(MediaType.APPLICATION_JSON)
@ -387,13 +420,17 @@ class PaymentControllerTest {
}
private void cleanWalletState() {
clearSharedWalletProjection();
WalletOpeningTestData.deleteWalletFacts(jdbc, PAYER_USER);
WalletOpeningTestData.deleteWalletFacts(jdbc, PAYEE_USER);
}
private void clearSharedWalletProjection() {
jdbc.update("DELETE FROM wallet_bank_binding WHERE wallet_id IN (?,?)", PAYER_WALLET, PAYEE_WALLET);
jdbc.update("DELETE FROM wallet_contract WHERE wallet_id IN (?,?)", PAYER_WALLET, PAYEE_WALLET);
jdbc.update("DELETE FROM wallet_certificate WHERE wallet_id IN (?,?)", PAYER_WALLET, PAYEE_WALLET);
jdbc.update("DELETE FROM simulated_bank_account WHERE user_id IN (?,?)", PAYER_USER, PAYEE_USER);
jdbc.update("DELETE FROM digital_wallet WHERE wallet_id IN (?,?)", PAYER_WALLET, PAYEE_WALLET);
WalletOpeningTestData.deleteWalletFacts(jdbc, PAYER_USER);
WalletOpeningTestData.deleteWalletFacts(jdbc, PAYEE_USER);
}
private void cleanPaymentData() {

Loading…
Cancel
Save