Merge branch 'feature/http-get-endpoints-for-partner-debitor-and-memberhip-number' into feature/add-scenario-test-for-deceased-partner-with-community-of-heirs

# Conflicts:
#	src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorController.java
#	src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepository.java
#	src/main/resources/api-definition/hs-office/hs-office-debitors-with-debitorNumber.yaml
#	src/main/resources/api-definition/hs-office/hs-office-debitors.yaml
#	src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorControllerAcceptanceTest.java
#	src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java
This commit is contained in:
Michael Hoennig 2024-12-10 13:32:03 +01:00
commit 69cbeb6e77
13 changed files with 126 additions and 101 deletions

View File

@ -57,12 +57,15 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi {
final String currentSubject,
final String assumedRoles,
final String name,
final UUID partnerUuid,
final String partnerNumber) {
context.define(currentSubject, assumedRoles);
final var entities = partnerNumber != null
? debitorRepo.findDebitorByPartnerNumber(cropTag("P-", partnerNumber))
: debitorRepo.findDebitorByOptionalNameLike(name);
? debitorRepo.findDebitorsByPartnerNumber(cropTag("P-", partnerNumber))
: partnerUuid != null
? debitorRepo.findDebitorsByPartnerUuid(partnerUuid)
: debitorRepo.findDebitorsByOptionalNameLike(name);
final var resources = mapper.mapList(entities, HsOfficeDebitorResource.class, ENTITY_TO_RESOURCE_POSTMAPPER);
return ResponseEntity.ok(resources);

View File

@ -14,6 +14,9 @@ public interface HsOfficeDebitorRepository extends Repository<HsOfficeDebitorEnt
@Timed("app.office.debitors.repo.findByUuid")
Optional<HsOfficeDebitorEntity> findByUuid(UUID id);
@Timed("app.office.debitors.repo.findDebitorByPartnerUuid")
List<HsOfficeDebitorEntity> findDebitorsByPartnerUuid(UUID partnerUuid);
@Query("""
SELECT debitor FROM HsOfficeDebitorEntity debitor
JOIN HsOfficePartnerEntity partner
@ -32,7 +35,7 @@ public interface HsOfficeDebitorRepository extends Repository<HsOfficeDebitorEnt
return result.stream().reduce(Reducer::toSingleElement);
}
default List<HsOfficeDebitorEntity> findDebitorByPartnerNumber(int partnerNumber) {
default List<HsOfficeDebitorEntity> findDebitorsByPartnerNumber(int partnerNumber) {
final var result = findDebitorByPartnerNumberAndOptionalDebitorNumberSuffix(partnerNumber, null);
return result;
}
@ -56,7 +59,7 @@ public interface HsOfficeDebitorRepository extends Repository<HsOfficeDebitorEnt
OR contact.caption like concat(cast(:name as text), '%')
""")
@Timed("app.office.debitors.repo.findDebitorByOptionalNameLike")
List<HsOfficeDebitorEntity> findDebitorByOptionalNameLike(String name);
List<HsOfficeDebitorEntity> findDebitorsByOptionalNameLike(String name);
@Timed("app.office.debitors.repo.save")
HsOfficeDebitorEntity save(final HsOfficeDebitorEntity entity);

View File

@ -12,8 +12,8 @@ get:
schema:
type: number
format: integer
minimum: 1000000
maximum: 9999999
# minimum: 1000000
# maximum: 9999999
description: debitor-number of the debitor to fetch.
responses:
"200":

View File

@ -13,13 +13,20 @@ get:
schema:
type: string
description: Prefix of name properties from person or contact to filter the results.
- name: partnerUuid
in: query
required: false
schema:
type: string
format: uuid
description: UUID of the business partner, exclusive to `memberNumber`.
- name: partnerNumber
in: query
required: false
schema:
type: string
minLength: 9
maxLength: 9
minLength: 7
maxLength: 7
pattern: 'P-[0-9]{5}'
description: Partner number of the requested debitor.
responses:

View File

@ -120,7 +120,7 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup
// given
context("superuser-alex@hostsharing.net");
final var count = rbacBookingItemRepo.count();
final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("First").get(0);
final var givenDebitor = debitorRepo.findDebitorsByOptionalNameLike("First").get(0);
final var givenProject = realProjectRepo.findAllByDebitorUuid(givenDebitor.getUuid()).get(0);
// when
@ -151,7 +151,7 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup
// when
attempt(em, () -> {
final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("First").get(0);
final var givenDebitor = debitorRepo.findDebitorsByOptionalNameLike("First").get(0);
final var givenProject = realProjectRepo.findAllByDebitorUuid(givenDebitor.getUuid()).get(0);
final var newBookingItem = HsBookingItemRbacEntity.builder()
.project(givenProject)

View File

@ -31,7 +31,10 @@ import static net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType.
import static net.hostsharing.hsadminng.rbac.test.IsValidUuidMatcher.isUuidValid;
import static net.hostsharing.hsadminng.rbac.test.JsonMatcher.lenientlyEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
@ -74,6 +77,69 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
@PersistenceContext
EntityManager em;
@Nested
class GetSingleDebitor {
@Test
void globalAdmin_withoutAssumedRoles_canGetDebitorByDebitorUuid() {
final var givenDebitor = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net");
return debitorRepo.findDebitorByDebitorNumber(1000212).orElseThrow();
}).assertSuccessful().returnedValue();
RestAssured // @formatter:off
.given()
.header("current-subject", "superuser-alex@hostsharing.net")
.port(port)
.when()
.get("http://localhost/api/hs/office/debitors/" + givenDebitor.getUuid())
.then().log().all().assertThat()
.statusCode(200)
.contentType("application/json")
.body("", lenientlyEquals("""
{
"debitorNumber": "D-1000212",
"partner": { "partnerNumber": "P-10002" },
"debitorRel": {
"contact": { "caption": "second contact" }
},
"vatId": null,
"vatCountryCode": null,
"vatBusiness": true
}
"""));
// @formatter:on
}
@Test
void globalAdmin_withoutAssumedRoles_canGetDebitorByDebitorNumber() {
RestAssured // @formatter:off
.given()
.header("current-subject", "superuser-alex@hostsharing.net")
.port(port)
.when()
.get("http://localhost/api/hs/office/debitors/D-1000212")
.then().log().all().assertThat()
.statusCode(200)
.contentType("application/json")
.body("", lenientlyEquals("""
{
"debitorNumber": "D-1000212",
"partner": { "partnerNumber": "P-10002" },
"debitorRel": {
"contact": { "caption": "second contact" }
},
"vatId": null,
"vatCountryCode": null,
"vatBusiness": true
}
"""));
// @formatter:on
}
}
@Nested
class GetListOfDebitors {
@ -232,55 +298,6 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
// @formatter:on
}
@Test
void globalAdmin_withoutAssumedRoles_canGetDebitorByDebitorNumber() {
RestAssured // @formatter:off
.given()
.header("current-subject", "superuser-alex@hostsharing.net")
.port(port)
.when()
.get("http://localhost/api/hs/office/debitors/P-10002")
.then().log().all().assertThat()
.statusCode(200)
.contentType("application/json")
.body("", lenientlyEquals("""
[
{
"debitorNumber": "D-1000211",
"partner": { "partnerNumber": "P-10002" },
"debitorRel": {
"contact": { "caption": "second contact" }
},
"vatId": null,
"vatCountryCode": null,
"vatBusiness": true
},
{
"debitorNumber": "D-1000212",
"partner": { "partnerNumber": "P-10002" },
"debitorRel": {
"contact": { "caption": "second contact" }
},
"vatId": null,
"vatCountryCode": null,
"vatBusiness": true
},
{
"debitorNumber": "D-1000213",
"partner": { "partnerNumber": "P-10002" },
"debitorRel": {
"contact": { "caption": "second contact" }
},
"vatId": null,
"vatCountryCode": null,
"vatBusiness": true
}
]
"""));
// @formatter:on
}
@Test
void globalAdmin_withoutAssumedRoles_canFindDebitorsByPartnerNumber() {
@ -289,7 +306,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
.header("current-subject", "superuser-alex@hostsharing.net")
.port(port)
.when()
.get("http://localhost/api/hs/office/debitors?debitorNumber=D-1000212")
.get("http://localhost/api/hs/office/debitors?partnerNumber=P-10002")
.then().log().all().assertThat()
.statusCode(200)
.contentType("application/json")
@ -297,13 +314,9 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
[
{
"debitorNumber": "D-1000212",
"partner": { "partnerNumber": "P-10002" },
"debitorRel": {
"contact": { "caption": "second contact" }
},
"vatId": null,
"vatCountryCode": null,
"vatBusiness": true
"partner": {
"partnerNumber": "P-10002"
}
}
]
"""));
@ -493,7 +506,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
@Test
void globalAdmin_withoutAssumedRole_canGetArbitraryDebitor() {
context.define("superuser-alex@hostsharing.net");
final var givenDebitorUuid = debitorRepo.findDebitorByOptionalNameLike("First").get(0).getUuid();
final var givenDebitorUuid = debitorRepo.findDebitorsByOptionalNameLike("First").get(0).getUuid();
RestAssured // @formatter:off
.given()
@ -558,7 +571,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
@Test
void normalUser_canNotGetUnrelatedDebitor() {
context.define("superuser-alex@hostsharing.net");
final var givenDebitorUuid = debitorRepo.findDebitorByOptionalNameLike("First").get(0).getUuid();
final var givenDebitorUuid = debitorRepo.findDebitorsByOptionalNameLike("First").get(0).getUuid();
RestAssured // @formatter:off
.given()
@ -573,7 +586,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
@Test
void contactAdminUser_canGetRelatedDebitorExceptRefundBankAccount() {
context.define("superuser-alex@hostsharing.net");
final var givenDebitorUuid = debitorRepo.findDebitorByOptionalNameLike("first contact").get(0).getUuid();
final var givenDebitorUuid = debitorRepo.findDebitorsByOptionalNameLike("first contact").get(0).getUuid();
RestAssured // @formatter:off
.given()

View File

@ -234,7 +234,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
context("superuser-alex@hostsharing.net");
// when
final var result = debitorRepo.findDebitorByOptionalNameLike(null);
final var result = debitorRepo.findDebitorsByOptionalNameLike(null);
// then
allTheseDebitorsAreReturned(
@ -256,7 +256,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
context("superuser-alex@hostsharing.net", assumedRole);
// when:
final var result = debitorRepo.findDebitorByOptionalNameLike("");
final var result = debitorRepo.findDebitorsByOptionalNameLike("");
// then:
exactlyTheseDebitorsAreReturned(result,
@ -270,7 +270,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
context("selfregistered-test-user@hostsharing.org");
// when:
final var result = debitorRepo.findDebitorByOptionalNameLike(null);
final var result = debitorRepo.findDebitorsByOptionalNameLike(null);
// then:
assertThat(result).isEmpty();
@ -303,7 +303,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
context("superuser-alex@hostsharing.net");
// when
final var result = debitorRepo.findDebitorByPartnerNumber(10003);
final var result = debitorRepo.findDebitorsByPartnerNumber(10003);
// then
exactlyTheseDebitorsAreReturned(result,
@ -320,7 +320,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
context("superuser-alex@hostsharing.net");
// when
final var result = debitorRepo.findDebitorByOptionalNameLike("third contact");
final var result = debitorRepo.findDebitorsByOptionalNameLike("third contact");
// then
exactlyTheseDebitorsAreReturned(result, "debitor(D-1000313: rel(anchor='IF Third OHG', type='DEBITOR', holder='IF Third OHG'), thi)");

View File

@ -17,9 +17,9 @@ public class CreateSepaMandateForDebitor extends UseCase<CreateSepaMandateForDeb
protected HttpResponse run() {
obtain("Debitor: Test AG - main debitor", () ->
httpGet("/api/hs/office/debitors?debitorNumber=&{debitorNumber}")
httpGet("/api/hs/office/debitors/%{debitorNumber}")
.expecting(OK).expecting(JSON),
response -> response.expectArrayElements(1).getFromBody("[0].uuid")
response -> response.getFromBody("uuid")
);
obtain("BankAccount: Test AG - debit bank account", () ->

View File

@ -18,9 +18,8 @@ public class CancelMembership extends UseCase<CancelMembership> {
protected HttpResponse run() {
obtain("Membership: %{memberNumber}", () ->
httpGet("/api/hs/office/memberships?memberNumber=%{memberNumber}")
.expectArrayElements(1),
response -> response.expectArrayElements(1).getFromBody("[0].uuid")
httpGet("/api/hs/office/memberships/%{memberNumber}"),
response -> response.getFromBody("uuid")
);
return withTitle("Patch the New Status Into the Membership", () ->

View File

@ -18,9 +18,9 @@ public abstract class CreateCoopAssetsTransaction extends UseCase<CreateCoopAsse
protected HttpResponse run() {
obtain("#{Find }membershipUuid", () ->
httpGet("/api/hs/office/memberships?memberNumber=&{memberNumber}")
.expecting(OK).expecting(JSON).expectArrayElements(1),
response -> response.getFromBody("$[0].uuid")
httpGet("/api/hs/office/memberships/%{memberNumber}")
.expecting(OK).expecting(JSON),
response -> response.getFromBody("uuid")
);
return withTitle("Create the Coop-Assets-%{transactionType} Transaction", () ->

View File

@ -18,9 +18,9 @@ public abstract class CreateCoopSharesTransaction extends UseCase<CreateCoopShar
protected HttpResponse run() {
obtain("#{Find }membershipUuid", () ->
httpGet("/api/hs/office/memberships?memberNumber=&{memberNumber}")
.expecting(OK).expecting(JSON).expectArrayElements(1),
response -> response.getFromBody("$[0].uuid")
httpGet("/api/hs/office/memberships/%{memberNumber}")
.expecting(OK).expecting(JSON),
response -> response.getFromBody("uuid")
);
return withTitle("Create the Coop-Shares-%{transactionType} Transaction", () ->

View File

@ -138,7 +138,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
void globalAdmin_canPostNewSepaMandate() {
context.define("superuser-alex@hostsharing.net");
final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("Third").get(0);
final var givenDebitor = debitorRepo.findDebitorsByOptionalNameLike("Third").get(0);
final var givenBankAccount = bankAccountRepo.findByIbanOrderByIbanAsc("DE02200505501015871393").get(0);
final var location = RestAssured // @formatter:off
@ -180,7 +180,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
void globalAdmin_canNotPostNewSepaMandateWhenDebitorUuidIsMissing() {
context.define("superuser-alex@hostsharing.net");
final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("Third").get(0);
final var givenDebitor = debitorRepo.findDebitorsByOptionalNameLike("Third").get(0);
final var givenBankAccount = bankAccountRepo.findByIbanOrderByIbanAsc("DE02200505501015871393").get(0);
final var location = RestAssured // @formatter:off
@ -205,7 +205,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
void globalAdmin_canNotPostNewSepaMandate_ifBankAccountDoesNotExist() {
context.define("superuser-alex@hostsharing.net");
final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("Third").get(0);
final var givenDebitor = debitorRepo.findDebitorsByOptionalNameLike("Third").get(0);
final var givenBankAccountUuid = UUID.fromString("00000000-0000-0000-0000-000000000000");
final var location = RestAssured // @formatter:off

View File

@ -66,7 +66,7 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTestWithC
// given
context("superuser-alex@hostsharing.net");
final var count = sepaMandateRepo.count();
final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("First").get(0);
final var givenDebitor = debitorRepo.findDebitorsByOptionalNameLike("First").get(0);
final var givenBankAccount = bankAccountRepo.findByOptionalHolderLike("Paul Winkler").get(0);
// when
@ -100,7 +100,7 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTestWithC
// when
attempt(em, () -> {
final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("First").get(0);
final var givenDebitor = debitorRepo.findDebitorsByOptionalNameLike("First").get(0);
final var givenBankAccount = bankAccountRepo.findByOptionalHolderLike("Paul Winkler").get(0);
final var newSepaMandate = HsOfficeSepaMandateEntity.builder()
.debitor(givenDebitor)
@ -397,7 +397,7 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTestWithC
private HsOfficeSepaMandateEntity givenSomeTemporarySepaMandate(final String iban) {
return jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net");
final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("First").get(0);
final var givenDebitor = debitorRepo.findDebitorsByOptionalNameLike("First").get(0);
final var givenBankAccount = bankAccountRepo.findByIbanOrderByIbanAsc(iban).get(0);
final var newSepaMandate = HsOfficeSepaMandateEntity.builder()
.debitor(givenDebitor)