Compare commits

..

3 Commits

Author SHA1 Message Date
Dev und Test fuer hsadminng
bfbbaed5c3 WIP: addSepaMandateWithBankAccountData 2025-02-24 21:27:29 +01:00
Michael Hoennig
73509990e1 business-glossary entries for Coop-Asset-Transactions-Types and Coop-Share-Transactions-Types 2025-02-24 19:35:54 +01:00
Michael Hoennig
fb216c4769 multiple debitors and subsequent memberships 2025-02-24 19:34:30 +01:00
4 changed files with 102 additions and 61 deletions

View File

@ -2,13 +2,12 @@ package net.hostsharing.hsadminng.hs.office.sepamandate;
import io.micrometer.core.annotation.Timed;
import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.errors.Validate;
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity;
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository;
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeSepaMandatesApi;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorResource;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeSepaMandateInsertResource;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeSepaMandatePatchResource;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeSepaMandateResource;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.*;
import net.hostsharing.hsadminng.mapper.StrictMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
@ -20,6 +19,7 @@ import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.validation.ValidationException;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.UUID;
import java.util.function.BiConsumer;
@ -75,6 +75,17 @@ public class HsOfficeSepaMandateController implements HsOfficeSepaMandatesApi {
final var entityToSave = mapper.map(body, HsOfficeSepaMandateEntity.class, SEPA_MANDATE_RESOURCE_TO_ENTITY_POSTMAPPER);
Validate.validate("bankAccount, bankAccount.uuid").exactlyOne(body.getBankAccount(), body.getBankAccountUuid());
if ( body.getBankAccountUuid() != null) {
entityToSave.setBankAccount(bankAccountRepo.findByUuid(body.getBankAccountUuid()).orElseThrow(
() -> new NoSuchElementException("cannot find BankAccount by bankAccountUuid: " + body.getBankAccountUuid())
));
} else {
entityToSave.setBankAccount(bankAccountRepo.save(
mapper.map(body.getBankAccount(), HsOfficeBankAccountEntity.class)
) );
}
final var saved = sepaMandateRepo.save(entityToSave);
final var uri =

View File

@ -38,8 +38,6 @@ create table if not exists hs_office.membership
CREATE OR REPLACE FUNCTION hs_office.validate_membership_validity()
RETURNS trigger AS $$
DECLARE
partnerNumber int;
BEGIN
IF EXISTS (
SELECT 1
@ -48,10 +46,7 @@ BEGIN
AND uuid <> NEW.uuid
AND NEW.validity && validity
) THEN
SELECT p.partnerNumber INTO partnerNumber
FROM hs_office.partner AS p
WHERE p.uuid = NEW.partnerUuid;
RAISE EXCEPTION 'Membership validity ranges overlap for partnerUuid %, partnerNumber %', NEW.partnerUuid, partnerNumber;
RAISE EXCEPTION 'Membership validity ranges overlap for partnerUuid %', NEW.partnerUuid;
END IF;
RETURN NEW;

View File

@ -4,10 +4,10 @@ import io.hypersistence.utils.hibernate.type.range.Range;
import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRealRepository;
import net.hostsharing.hsadminng.mapper.Array;
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
import net.hostsharing.hsadminng.rbac.grant.RawRbacGrantRepository;
import net.hostsharing.hsadminng.rbac.role.RawRbacRoleRepository;
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
import net.hostsharing.hsadminng.mapper.Array;
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Tag;
@ -15,9 +15,9 @@ import org.junit.jupiter.api.Test;
import org.postgresql.util.PSQLException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.context.annotation.Import;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
@ -71,8 +71,7 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTestWithCl
final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("First").get(0);
// when
final var result = attempt(
em, () -> {
final var result = attempt(em, () -> {
final var newMembership = HsOfficeMembershipEntity.builder()
.memberNumberSuffix("11")
.partner(givenPartner)
@ -93,11 +92,11 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTestWithCl
public void creatingMembershipForSamePartnerIsDisallowedIfAnotherOneIsStillActive() {
// given
context("superuser-alex@hostsharing.net");
final var count = membershipRepo.count();
final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("First").getFirst();
// when
final var result = attempt(
em, () -> {
final var result = attempt(em, () -> {
final var newMembership = HsOfficeMembershipEntity.builder()
.memberNumberSuffix("11")
.partner(givenPartner)
@ -108,10 +107,7 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTestWithCl
});
// then
result.assertExceptionWithRootCauseMessage(
PSQLException.class,
"Membership validity ranges overlap for partnerUuid " + givenPartner.getUuid() +
", partnerNumber " + givenPartner.getPartnerNumber());
result.assertExceptionWithRootCauseMessage(PSQLException.class, "Membership validity ranges overlap for partnerUuid " + givenPartner.getUuid());
}
@Test
@ -124,8 +120,7 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTestWithCl
.toList();
// when
attempt(
em, () -> {
attempt(em, () -> {
final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("First").get(0);
final var newMembership = HsOfficeMembershipEntity.builder()
.memberNumberSuffix("17")
@ -206,8 +201,7 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTestWithCl
final var result = membershipRepo.findMembershipsByPartnerUuid(givenPartner.getUuid());
// then
exactlyTheseMembershipsAreReturned(
result,
exactlyTheseMembershipsAreReturned(result,
"Membership(M-1000101, P-10001, [2022-10-01,2024-12-31), ACTIVE)");
}
@ -250,8 +244,7 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTestWithCl
final var result = membershipRepo.findMembershipsByPartnerNumber(10002);
// then
exactlyTheseMembershipsAreReturned(
result,
exactlyTheseMembershipsAreReturned(result,
"Membership(M-1000202, P-10002, [2022-10-01,2026-01-01), ACTIVE)");
}
}
@ -303,8 +296,7 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTestWithCl
});
// then
result.assertExceptionWithRootCauseMessage(
JpaSystemException.class,
result.assertExceptionWithRootCauseMessage(JpaSystemException.class,
"[403] Subject ", " is not allowed to update hs_office.membership uuid");
}
@ -412,9 +404,7 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTestWithCl
"[creating Membership test-data, hs_office.membership, INSERT, 03]");
}
private HsOfficeMembershipEntity givenSomeTemporaryMembership(
final String partnerTradeName,
final String memberNumberSuffix) {
private HsOfficeMembershipEntity givenSomeTemporaryMembership(final String partnerTradeName, final String memberNumberSuffix) {
return jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net");
final var givenPartner = partnerRepo.findPartnerByOptionalNameLike(partnerTradeName).get(0);

View File

@ -137,7 +137,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
class PostNewSepaMandate {
@Test
void globalAdmin_canPostNewSepaMandate() {
void globalAdmin_canPostNewSepaMandateWithBankAccountUuid() {
context.define("superuser-alex@hostsharing.net");
final var givenDebitor = debitorRepo.findDebitorsByOptionalNameLike("Third").get(0);
@ -177,6 +177,51 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
assertThat(newSubjectUuid).isNotNull();
}
@Test
void globalAdmin_canPostNewSepaMandateWithBankAccountData() {
context.define("superuser-alex@hostsharing.net");
final var givenDebitor = debitorRepo.findDebitorsByOptionalNameLike("Third").get(0);
final var location = RestAssured // @formatter:off
.given()
.header("current-subject", "superuser-alex@hostsharing.net")
.contentType(ContentType.JSON)
.body("""
{
"debitor.uuid": "%s",
"bankAccount": {
"holder": "Fourth eG B",
"iban": "DE02200505501015871393"
"bic": "HASPDEHH"
},
"reference": "temp ref CAT A",
"agreement": "2020-01-02",
"validFrom": "2022-10-13"
}
""".formatted(givenDebitor.getUuid(), givenBankAccount.getUuid()))
.port(port)
.when()
.post("http://localhost/api/hs/office/sepamandates")
.then().log().all().assertThat()
.statusCode(201)
.contentType(ContentType.JSON)
.body("uuid", isUuidValid())
.body("debitor.partner.partnerNumber", is("P-10003"))
.body("bankAccount.holder", is("Fourth eG B"))
.body("bankAccount.iban", is("DE02200505501015871393"))
.body("reference", is("temp ref CAT A"))
.body("validFrom", is("2022-10-13"))
.body("validTo", equalTo(null))
.header("Location", startsWith("http://localhost"))
.extract().header("Location"); // @formatter:on
// finally, the new sepaMandate can be accessed under the generated UUID
final var newSubjectUuid = UUID.fromString(
location.substring(location.lastIndexOf('/') + 1));
assertThat(newSubjectUuid).isNotNull();
}
// TODO.test: move validation tests to a ...WebMvcTest
@Test
void globalAdmin_canNotPostNewSepaMandateWhenDebitorUuidIsMissing() {