From ddfabef9b76f1d20b28f57def8ab6027d1deebb2 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Sat, 29 Oct 2022 11:42:03 +0200 Subject: [PATCH] hs_office_sepamandate_rv: fix missing update column reference --- .../253-hs-office-sepamandate-rbac.sql | 1 + ...ceSepaMandateControllerAcceptanceTest.java | 47 ++++++++++++++++++- ...eSepaMandateRepositoryIntegrationTest.java | 21 +++++---- 3 files changed, 58 insertions(+), 11 deletions(-) diff --git a/src/main/resources/db/changelog/253-hs-office-sepamandate-rbac.sql b/src/main/resources/db/changelog/253-hs-office-sepamandate-rbac.sql index f63bf649..f09f2a4b 100644 --- a/src/main/resources/db/changelog/253-hs-office-sepamandate-rbac.sql +++ b/src/main/resources/db/changelog/253-hs-office-sepamandate-rbac.sql @@ -102,6 +102,7 @@ call generateRbacIdentityView('hs_office_sepamandate', idNameExpression => 'targ call generateRbacRestrictedView('hs_office_sepamandate', orderby => 'target.reference', columnUpdates => $updates$ + reference = new.reference, agreement = new.agreement, validity = new.validity $updates$); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateControllerAcceptanceTest.java index bbdfed5b..31832119 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateControllerAcceptanceTest.java @@ -341,7 +341,52 @@ class HsOfficeSepaMandateControllerAcceptanceTest { class PatchSepaMandate { @Test - void globalAdmin_canPatchValidToOfArbitrarySepaMandate() { + void globalAdmin_canPatchAllUpdatablePropertiesOfSepaMandate() { + + final var givenSepaMandate = givenSomeTemporarySepaMandate(); + + final var location = RestAssured // @formatter:off + .given() + .header("current-user", "superuser-alex@hostsharing.net") + .contentType(ContentType.JSON) + .body(""" + { + "reference": "temp ref CAT Z - patched", + "agreement": "2020-06-01", + "validFrom": "2020-06-05", + "validTo": "2022-12-31" + } + """) + .port(port) + .when() + .patch("http://localhost/api/hs/office/sepamandates/" + givenSepaMandate.getUuid()) + .then().log().all().assertThat() + .statusCode(200) + .contentType(ContentType.JSON) + .body("uuid", isUuidValid()) + .body("debitor.partner.person.tradeName", is("First GmbH")) + .body("bankAccount.iban", is("DE02120300000000202051")) + .body("reference", is("temp ref CAT Z - patched")) + .body("agreement", is("2020-06-01")) + .body("validFrom", is("2020-06-05")) + .body("validTo", is("2022-12-31")); + // @formatter:on + + // finally, the sepaMandate is actually updated + context.define("superuser-alex@hostsharing.net"); + assertThat(sepaMandateRepo.findByUuid(givenSepaMandate.getUuid())).isPresent().get() + .matches(mandate -> { + assertThat(mandate.getDebitor().toString()).isEqualTo("debitor(10001: First GmbH)"); + assertThat(mandate.getBankAccount().toShortString()).isEqualTo("First GmbH"); + assertThat(mandate.getReference()).isEqualTo("temp ref CAT Z - patched"); + assertThat(mandate.getValidFrom()).isEqualTo("2020-06-05"); + assertThat(mandate.getValidTo()).isEqualTo("2022-12-31"); + return true; + }); + } + + @Test + void globalAdmin_canPatchJustValidToOfArbitrarySepaMandate() { context.define("superuser-alex@hostsharing.net"); final var givenSepaMandate = givenSomeTemporarySepaMandate(); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateRepositoryIntegrationTest.java index 241be448..cbc8bfbc 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateRepositoryIntegrationTest.java @@ -78,7 +78,7 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTest { .debitor(givenDebitor) .bankAccount(givenBankAccount) .reference("temp ref A") - .agreement(LocalDate.parse( "2020-01-02")) + .agreement(LocalDate.parse("2020-01-02")) .validity(Range.closedOpen( LocalDate.parse("2020-01-01"), LocalDate.parse("2023-01-01"))) .build(); @@ -238,29 +238,30 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTest { class UpdateSepaMandate { @Test - public void hostsharingAdmin_canUpdateValidityOfArbitrarySepaMandate() { + public void hostsharingAdmin_canUpdateArbitrarySepaMandate() { // given - context("superuser-alex@hostsharing.net"); final var givenSepaMandate = givenSomeTemporarySepaMandateBessler("Peter Smith"); assertThatSepaMandateIsVisibleForUserWithRole( givenSepaMandate, "hs_office_bankaccount#PeterSmith.admin"); - assertThatSepaMandateActuallyInDatabase(givenSepaMandate); - final var newValidityEnd = LocalDate.now(); // when - context("superuser-alex@hostsharing.net"); final var result = jpaAttempt.transacted(() -> { context("superuser-alex@hostsharing.net"); + givenSepaMandate.setReference("temp ref X - updated"); + givenSepaMandate.setAgreement(LocalDate.parse("2019-05-13")); givenSepaMandate.setValidity(Range.closedOpen( - givenSepaMandate.getValidity().lower(), newValidityEnd)); + LocalDate.parse("2019-05-17"), LocalDate.parse("2023-01-01"))); return sepaMandateRepo.save(givenSepaMandate); }); // then result.assertSuccessful(); - - sepaMandateRepo.deleteByUuid(givenSepaMandate.getUuid()); + jpaAttempt.transacted(() -> { + context("superuser-alex@hostsharing.net"); + assertThat(sepaMandateRepo.findByUuid(givenSepaMandate.getUuid())).isNotEmpty().get() + .usingRecursiveComparison().isEqualTo(givenSepaMandate); + }).assertSuccessful(); } @Test @@ -422,7 +423,7 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTest { .debitor(givenDebitor) .bankAccount(givenBankAccount) .reference("temp ref X") - .agreement(LocalDate.parse( "2020-01-02")) + .agreement(LocalDate.parse("2020-01-02")) .validity(Range.closedOpen( LocalDate.parse("2020-01-01"), LocalDate.parse("2023-01-01"))) .build();