Michael Hoennig
2022-10-29 ddfabef9b76f1d20b28f57def8ab6027d1deebb2
hs_office_sepamandate_rv: fix missing update column reference
3 files modified
69 ■■■■ changed files
src/main/resources/db/changelog/253-hs-office-sepamandate-rbac.sql 1 ●●●● patch | view | raw | blame | history
src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateControllerAcceptanceTest.java 47 ●●●●● patch | view | raw | blame | history
src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateRepositoryIntegrationTest.java 21 ●●●● patch | view | raw | blame | history
src/main/resources/db/changelog/253-hs-office-sepamandate-rbac.sql
@@ -102,6 +102,7 @@
call generateRbacRestrictedView('hs_office_sepamandate',
    orderby => 'target.reference',
    columnUpdates => $updates$
        reference = new.reference,
        agreement = new.agreement,
        validity = new.validity
    $updates$);
src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateControllerAcceptanceTest.java
@@ -341,7 +341,52 @@
    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();
src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateRepositoryIntegrationTest.java
@@ -78,7 +78,7 @@
                        .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 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 @@
                    .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();