fix sepa mandate tests

This commit is contained in:
Michael Hoennig 2024-03-22 09:24:38 +01:00
parent 6052cd7b9c
commit 0680b25ecf
2 changed files with 40 additions and 51 deletions

View File

@ -24,6 +24,7 @@ import jakarta.persistence.PersistenceContext;
import java.time.LocalDate;
import java.util.UUID;
import static java.util.Optional.ofNullable;
import static net.hostsharing.test.IsValidUuidMatcher.isUuidValid;
import static net.hostsharing.test.JsonMatcher.lenientlyEquals;
import static org.assertj.core.api.Assertions.assertThat;
@ -70,35 +71,27 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
.then().log().all().assertThat()
.statusCode(200)
.contentType("application/json")
.log().all()
.body("", lenientlyEquals("""
[
{
"debitor": {
"debitorNumber": 1000212,
"billingContact": { "label": "second contact" }
},
"bankAccount": { "holder": "Second e.K." },
"reference": "refSeconde.K.",
"validFrom": "2022-10-01",
"validTo": "2026-12-31"
},
{
"debitor": {
"debitorNumber": 1000111,
"billingContact": { "label": "first contact" }
},
"debitor": { "debitorNumber": 1000111 },
"bankAccount": { "holder": "First GmbH" },
"reference": "refFirstGmbH",
"reference": "ref-10001-11",
"validFrom": "2022-10-01",
"validTo": "2026-12-31"
},
{
"debitor": {
"debitorNumber": 1000313,
"billingContact": { "label": "third contact" }
},
"debitor": { "debitorNumber": 1000212 },
"bankAccount": { "holder": "Second e.K." },
"reference": "ref-10002-12",
"validFrom": "2022-10-01",
"validTo": "2026-12-31"
},
{
"debitor": { "debitorNumber": 1000313 },
"bankAccount": { "holder": "Third OHG" },
"reference": "refThirdOHG",
"reference": "ref-10003-13",
"validFrom": "2022-10-01",
"validTo": "2026-12-31"
}
@ -139,7 +132,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
.statusCode(201)
.contentType(ContentType.JSON)
.body("uuid", isUuidValid())
.body("debitor.partner.person.tradeName", is("Third OHG"))
.body("debitor.partner.partnerNumber", is(10003))
.body("bankAccount.iban", is("DE02200505501015871393"))
.body("reference", is("temp ref CAT A"))
.body("validFrom", is("2022-10-13"))
@ -262,10 +255,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
.contentType("application/json")
.body("", lenientlyEquals("""
{
"debitor": {
"debitorNumber": 1000111,
"billingContact": { "label": "first contact" }
},
"debitor": { "debitorNumber": 1000111 },
"bankAccount": {
"holder": "First GmbH",
"iban": "DE02120300000000202051"
@ -314,10 +304,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
.contentType("application/json")
.body("", lenientlyEquals("""
{
"debitor": {
"debitorNumber": 1000111,
"billingContact": { "label": "first contact" }
},
"debitor": { "debitorNumber": 1000111 },
"bankAccount": {
"holder": "First GmbH",
"iban": "DE02120300000000202051"
@ -337,7 +324,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
@Test
void globalAdmin_canPatchAllUpdatablePropertiesOfSepaMandate() {
final var givenSepaMandate = givenSomeTemporarySepaMandate();
final var givenSepaMandate = givenSomeTemporarySepaMandateForDebitorNumber(1000111);
final var location = RestAssured // @formatter:off
.given()
@ -358,7 +345,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
.statusCode(200)
.contentType(ContentType.JSON)
.body("uuid", isUuidValid())
.body("debitor.partner.person.tradeName", is("First GmbH"))
.body("debitor.debitorNumber", is(1000111))
.body("bankAccount.iban", is("DE02120300000000202051"))
.body("reference", is("temp ref CAT Z - patched"))
.body("agreement", is("2020-06-01"))
@ -370,7 +357,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
context.define("superuser-alex@hostsharing.net");
assertThat(sepaMandateRepo.findByUuid(givenSepaMandate.getUuid())).isPresent().get()
.matches(mandate -> {
assertThat(mandate.getDebitor().toString()).isEqualTo("debitor(D-1000111: P-10001, fir)");
assertThat(mandate.getDebitor().toString()).isEqualTo("debitor(D-1000111: rel(relAnchor='LP First GmbH', relType='ACCOUNTING', relHolder='LP First GmbH'), fir)");
assertThat(mandate.getBankAccount().toShortString()).isEqualTo("First GmbH");
assertThat(mandate.getReference()).isEqualTo("temp ref CAT Z - patched");
assertThat(mandate.getValidFrom()).isEqualTo("2020-06-05");
@ -383,7 +370,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
void globalAdmin_canPatchJustValidToOfArbitrarySepaMandate() {
context.define("superuser-alex@hostsharing.net");
final var givenSepaMandate = givenSomeTemporarySepaMandate();
final var givenSepaMandate = givenSomeTemporarySepaMandateForDebitorNumber(1000111);
final var location = RestAssured // @formatter:off
.given()
@ -401,7 +388,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
.statusCode(200)
.contentType(ContentType.JSON)
.body("uuid", isUuidValid())
.body("debitor.partner.person.tradeName", is("First GmbH"))
.body("debitor.debitorNumber", is(1000111))
.body("bankAccount.iban", is("DE02120300000000202051"))
.body("reference", is("temp ref CAT Z"))
.body("validFrom", is("2022-11-01"))
@ -411,7 +398,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
// finally, the sepaMandate is actually updated
assertThat(sepaMandateRepo.findByUuid(givenSepaMandate.getUuid())).isPresent().get()
.matches(mandate -> {
assertThat(mandate.getDebitor().toString()).isEqualTo("debitor(D-1000111: P-10001, fir)");
assertThat(mandate.getDebitor().toString()).isEqualTo("debitor(D-1000111: rel(relAnchor='LP First GmbH', relType='ACCOUNTING', relHolder='LP First GmbH'), fir)");
assertThat(mandate.getBankAccount().toShortString()).isEqualTo("First GmbH");
assertThat(mandate.getReference()).isEqualTo("temp ref CAT Z");
assertThat(mandate.getValidity().asString()).isEqualTo("[2022-11-01,2023-01-01)");
@ -423,7 +410,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
void globalAdmin_canNotPatchReferenceOfArbitrarySepaMandate() {
context.define("superuser-alex@hostsharing.net");
final var givenSepaMandate = givenSomeTemporarySepaMandate();
final var givenSepaMandate = givenSomeTemporarySepaMandateForDebitorNumber(1000111);
final var location = RestAssured // @formatter:off
.given()
@ -458,7 +445,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
@Test
void globalAdmin_canDeleteArbitrarySepaMandate() {
context.define("superuser-alex@hostsharing.net");
final var givenSepaMandate = givenSomeTemporarySepaMandate();
final var givenSepaMandate = givenSomeTemporarySepaMandateForDebitorNumber(1000111);
RestAssured // @formatter:off
.given()
@ -477,7 +464,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
@Accepts({ "SepaMandate:X(Access Control)" })
void bankAccountAdminUser_canNotDeleteRelatedSepaMandate() {
context.define("superuser-alex@hostsharing.net");
final var givenSepaMandate = givenSomeTemporarySepaMandate();
final var givenSepaMandate = givenSomeTemporarySepaMandateForDebitorNumber(1000111);
RestAssured // @formatter:off
.given()
@ -496,7 +483,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
@Accepts({ "SepaMandate:X(Access Control)" })
void normalUser_canNotDeleteUnrelatedSepaMandate() {
context.define("superuser-alex@hostsharing.net");
final var givenSepaMandate = givenSomeTemporarySepaMandate();
final var givenSepaMandate = givenSomeTemporarySepaMandateForDebitorNumber(1000111);
RestAssured // @formatter:off
.given()
@ -512,11 +499,13 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
}
}
private HsOfficeSepaMandateEntity givenSomeTemporarySepaMandate() {
private HsOfficeSepaMandateEntity givenSomeTemporarySepaMandateForDebitorNumber(final int debitorNumber) {
return jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net");
final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("First").get(0);
final var givenBankAccount = bankAccountRepo.findByOptionalHolderLike("First").get(0);
final var givenDebitor = debitorRepo.findDebitorByDebitorNumber(debitorNumber).get(0);
final var bankAccountHolder = ofNullable(givenDebitor.getPartner().getPartnerRole().getRelHolder().getTradeName())
.orElse(givenDebitor.getPartner().getPartnerRole().getRelHolder().getFamilyName());
final var givenBankAccount = bankAccountRepo.findByOptionalHolderLike(bankAccountHolder).get(0);
final var newSepaMandate = HsOfficeSepaMandateEntity.builder()
.uuid(UUID.randomUUID())
.debitor(givenDebitor)

View File

@ -170,9 +170,9 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTestWithC
// then
allTheseSepaMandatesAreReturned(
result,
"SEPA-Mandate(DE02100500000054540402, ref-11120002, 2022-09-30, [2022-10-01,2027-01-01))",
"SEPA-Mandate(DE02120300000000202051, ref-11110001, 2022-09-30, [2022-10-01,2027-01-01))",
"SEPA-Mandate(DE02300209000106531065, ref-11130003, 2022-09-30, [2022-10-01,2027-01-01))");
"SEPA-Mandate(DE02100500000054540402, ref-10002-12, 2022-09-30, [2022-10-01,2027-01-01))",
"SEPA-Mandate(DE02120300000000202051, ref-10001-11, 2022-09-30, [2022-10-01,2027-01-01))",
"SEPA-Mandate(DE02300209000106531065, ref-10003-13, 2022-09-30, [2022-10-01,2027-01-01))");
}
@Test
@ -186,7 +186,7 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTestWithC
// then:
exactlyTheseSepaMandatesAreReturned(
result,
"SEPA-Mandate(DE02120300000000202051, ref-11110001, 2022-09-30, [2022-10-01,2027-01-01))");
"SEPA-Mandate(DE02120300000000202051, ref-10001-11, 2022-09-30, [2022-10-01,2027-01-01))");
}
}
@ -204,9 +204,9 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTestWithC
// then
exactlyTheseSepaMandatesAreReturned(
result,
"SEPA-Mandate(DE02100500000054540402, ref-11120002, 2022-09-30, [2022-10-01,2027-01-01))",
"SEPA-Mandate(DE02120300000000202051, ref-11110001, 2022-09-30, [2022-10-01,2027-01-01))",
"SEPA-Mandate(DE02300209000106531065, ref-11130003, 2022-09-30, [2022-10-01,2027-01-01))");
"SEPA-Mandate(DE02100500000054540402, ref-10002-12, 2022-09-30, [2022-10-01,2027-01-01))",
"SEPA-Mandate(DE02120300000000202051, ref-10001-11, 2022-09-30, [2022-10-01,2027-01-01))",
"SEPA-Mandate(DE02300209000106531065, ref-10003-13, 2022-09-30, [2022-10-01,2027-01-01))");
}
@Test
@ -220,7 +220,7 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTestWithC
// then
exactlyTheseSepaMandatesAreReturned(
result,
"SEPA-Mandate(DE02300209000106531065, ref-11130003, 2022-09-30, [2022-10-01,2027-01-01))");
"SEPA-Mandate(DE02300209000106531065, ref-10003-13, 2022-09-30, [2022-10-01,2027-01-01))");
}
}
@ -388,7 +388,7 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTestWithC
@SuppressWarnings("unchecked") final List<Object[]> customerLogEntries = query.getResultList();
// then
assertThat(customerLogEntries).map(Arrays::toString).containsExactly(
assertThat(customerLogEntries).map(Arrays::toString).contains(
"[creating SEPA-mandate test-data 1000111, hs_office_sepamandate, INSERT]",
"[creating SEPA-mandate test-data 1000212, hs_office_sepamandate, INSERT]",
"[creating SEPA-mandate test-data 1000313, hs_office_sepamandate, INSERT]");