hs_office_sepamandate_rv: fix missing update column reference

This commit is contained in:
Michael Hoennig 2022-10-29 11:42:03 +02:00
parent 6df93bfbb6
commit ddfabef9b7
3 changed files with 58 additions and 11 deletions

View File

@ -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$);

View File

@ -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();

View File

@ -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();