Compare commits

..

2 Commits

Author SHA1 Message Date
Michael Hoennig
ce6981c7ca add M- in front of memberNumber for related tests 2024-11-15 15:10:50 +01:00
Michael Hoennig
628f984ae6 add M- in front of memberNumber for API 2024-11-15 14:39:11 +01:00
8 changed files with 38 additions and 28 deletions

View File

@ -17,6 +17,7 @@ import java.util.UUID;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import static java.util.Optional.ofNullable; import static java.util.Optional.ofNullable;
import static net.hostsharing.hsadminng.repr.TaggedNumber.cropTag;
@RestController @RestController
@ -37,11 +38,11 @@ public class HsOfficeMembershipController implements HsOfficeMembershipsApi {
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final UUID partnerUuid, final UUID partnerUuid,
final Integer memberNumber) { final String memberNumber) {
context.define(currentSubject, assumedRoles); context.define(currentSubject, assumedRoles);
final var entities = ( memberNumber != null) final var entities = ( memberNumber != null)
? ofNullable(membershipRepo.findMembershipByMemberNumber(memberNumber)).stream().toList() ? ofNullable(membershipRepo.findMembershipByMemberNumber(cropTag("M-", memberNumber))).stream().toList()
: membershipRepo.findMembershipsByOptionalPartnerUuid(partnerUuid); : membershipRepo.findMembershipsByOptionalPartnerUuid(partnerUuid);
final var resources = mapper.mapList(entities, HsOfficeMembershipResource.class, final var resources = mapper.mapList(entities, HsOfficeMembershipResource.class,
@ -125,7 +126,7 @@ public class HsOfficeMembershipController implements HsOfficeMembershipsApi {
} }
final BiConsumer<HsOfficeMembershipEntity, HsOfficeMembershipResource> SEPA_MANDATE_ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> { final BiConsumer<HsOfficeMembershipEntity, HsOfficeMembershipResource> SEPA_MANDATE_ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> {
// TODO.refa: this should be possible via ModelMapper config resource.setMemberNumber(entity.getTaggedMemberNumber());
resource.setValidFrom(entity.getValidity().lower()); resource.setValidFrom(entity.getValidity().lower());
if (entity.getValidity().hasUpperBound()) { if (entity.getValidity().hasUpperBound()) {
resource.setValidTo(entity.getValidity().upper().minusDays(1)); resource.setValidTo(entity.getValidity().upper().minusDays(1));

View File

@ -130,6 +130,7 @@ public class HsOfficeMembershipEntity implements BaseEntity<HsOfficeMembershipEn
} }
return validity; return validity;
} }
public Integer getMemberNumber() { public Integer getMemberNumber() {
if (partner == null || partner.getPartnerNumber() == null || memberNumberSuffix == null ) { if (partner == null || partner.getPartnerNumber() == null || memberNumberSuffix == null ) {
return null; return null;
@ -138,6 +139,10 @@ public class HsOfficeMembershipEntity implements BaseEntity<HsOfficeMembershipEn
return getPartner().getPartnerNumber() * 100 + Integer.parseInt(memberNumberSuffix, 10); return getPartner().getPartnerNumber() * 100 + Integer.parseInt(memberNumberSuffix, 10);
} }
public String getTaggedMemberNumber() {
return MEMBER_NUMBER_TAG + getMemberNumber();
}
@Override @Override
public String toString() { public String toString() {
return stringify.apply(this); return stringify.apply(this);

View File

@ -26,9 +26,10 @@ components:
mainDebitor: mainDebitor:
$ref: 'hs-office-debitor-schemas.yaml#/components/schemas/HsOfficeDebitor' $ref: 'hs-office-debitor-schemas.yaml#/components/schemas/HsOfficeDebitor'
memberNumber: memberNumber:
type: integer type: string
minimum: 1000000 minLength: 9
maximum: 9999999 maxLength: 9
pattern: 'M-[0-9]{7}'
memberNumberSuffix: memberNumberSuffix:
type: string type: string
minLength: 2 minLength: 2

View File

@ -19,7 +19,10 @@ get:
in: query in: query
required: false required: false
schema: schema:
type: integer type: string
minLength: 9
maxLength: 9
pattern: 'M-[0-9]{7}'
description: Member number, exclusive to `partnerUuid`. description: Member number, exclusive to `partnerUuid`.
responses: responses:
"200": "200":

View File

@ -78,7 +78,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
[ [
{ {
"partner": { "partnerNumber": "P-10001" }, "partner": { "partnerNumber": "P-10001" },
"memberNumber": 1000101, "memberNumber": "M-1000101",
"memberNumberSuffix": "01", "memberNumberSuffix": "01",
"validFrom": "2022-10-01", "validFrom": "2022-10-01",
"validTo": null, "validTo": null,
@ -86,7 +86,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
}, },
{ {
"partner": { "partnerNumber": "P-10002" }, "partner": { "partnerNumber": "P-10002" },
"memberNumber": 1000202, "memberNumber": "M-1000202",
"memberNumberSuffix": "02", "memberNumberSuffix": "02",
"validFrom": "2022-10-01", "validFrom": "2022-10-01",
"validTo": null, "validTo": null,
@ -94,7 +94,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
}, },
{ {
"partner": { "partnerNumber": "P-10003" }, "partner": { "partnerNumber": "P-10003" },
"memberNumber": 1000303, "memberNumber": "M-1000303",
"memberNumberSuffix": "03", "memberNumberSuffix": "03",
"validFrom": "2022-10-01", "validFrom": "2022-10-01",
"validTo": null, "validTo": null,
@ -125,7 +125,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
[ [
{ {
"partner": { "partnerNumber": "P-10001" }, "partner": { "partnerNumber": "P-10001" },
"memberNumber": 1000101, "memberNumber": "M-1000101",
"memberNumberSuffix": "01", "memberNumberSuffix": "01",
"validFrom": "2022-10-01", "validFrom": "2022-10-01",
"validTo": null, "validTo": null,
@ -153,7 +153,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
[ [
{ {
"partner": { "partnerNumber": "P-10002" }, "partner": { "partnerNumber": "P-10002" },
"memberNumber": 1000202, "memberNumber": "M-1000202",
"memberNumberSuffix": "02", "memberNumberSuffix": "02",
"validFrom": "2022-10-01", "validFrom": "2022-10-01",
"validTo": null, "validTo": null,
@ -196,7 +196,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body("uuid", isUuidValid()) .body("uuid", isUuidValid())
.body("partner.partnerNumber", is("P-10003")) .body("partner.partnerNumber", is("P-10003"))
.body("memberNumber", is(expectedMemberNumber)) .body("memberNumber", is("M-" + expectedMemberNumber))
.body("memberNumberSuffix", is(givenMemberSuffix)) .body("memberNumberSuffix", is(givenMemberSuffix))
.body("validFrom", is("2022-10-13")) .body("validFrom", is("2022-10-13"))
.body("validTo", equalTo(null)) .body("validTo", equalTo(null))
@ -231,7 +231,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
.body("", lenientlyEquals(""" .body("", lenientlyEquals("""
{ {
"partner": { "partnerNumber": "P-10001" }, "partner": { "partnerNumber": "P-10001" },
"memberNumber": 1000101, "memberNumber": "M-1000101",
"memberNumberSuffix": "01", "memberNumberSuffix": "01",
"validFrom": "2022-10-01", "validFrom": "2022-10-01",
"validTo": null, "validTo": null,
@ -256,7 +256,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
} }
@Test @Test
void parnerRelAgent_canGetRelatedMembership() { void partnerRelAgent_canGetRelatedMembership() {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenMembershipUuid = membershipRepo.findMembershipByMemberNumber(1000303).getUuid(); final var givenMembershipUuid = membershipRepo.findMembershipByMemberNumber(1000303).getUuid();
@ -273,7 +273,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
.body("", lenientlyEquals(""" .body("", lenientlyEquals("""
{ {
"partner": { "partnerNumber": "P-10003" }, "partner": { "partnerNumber": "P-10003" },
"memberNumber": 1000303, "memberNumber": "M-1000303",
"memberNumberSuffix": "03", "memberNumberSuffix": "03",
"validFrom": "2022-10-01", "validFrom": "2022-10-01",
"validTo": null, "validTo": null,

View File

@ -260,7 +260,7 @@ class HsOfficeScenarioTests extends ScenarioTest {
@Requires("Person: Test AG") @Requires("Person: Test AG")
void shouldDeleteDebitor() { void shouldDeleteDebitor() {
new DeleteDebitor(this) new DeleteDebitor(this)
.given("partnerNumber", 31020) .given("partnerNumber", "P-31020")
.given("debitorSuffix", "02") .given("debitorSuffix", "02")
.doRun(); .doRun();
} }
@ -271,7 +271,7 @@ class HsOfficeScenarioTests extends ScenarioTest {
@Disabled("see TODO.spec in DontDeleteDefaultDebitor") @Disabled("see TODO.spec in DontDeleteDefaultDebitor")
void shouldNotDeleteDefaultDebitor() { void shouldNotDeleteDefaultDebitor() {
new DontDeleteDefaultDebitor(this) new DontDeleteDefaultDebitor(this)
.given("partnerNumber", 31010) .given("partnerNumber", "P-31010")
.given("debitorSuffix", "00") .given("debitorSuffix", "00")
.doRun(); .doRun();
} }
@ -337,7 +337,7 @@ class HsOfficeScenarioTests extends ScenarioTest {
@Produces("Coop-Shares SUBSCRIPTION Transaction") @Produces("Coop-Shares SUBSCRIPTION Transaction")
void shouldSubscribeCoopShares() { void shouldSubscribeCoopShares() {
new CreateCoopSharesSubscriptionTransaction(this) new CreateCoopSharesSubscriptionTransaction(this)
.given("memberNumber", "3101000") .given("memberNumber", "M-3101000")
.given("reference", "sign 2024-01-15") .given("reference", "sign 2024-01-15")
.given("shareCount", 100) .given("shareCount", 100)
.given("comment", "Signing the Membership") .given("comment", "Signing the Membership")
@ -350,7 +350,7 @@ class HsOfficeScenarioTests extends ScenarioTest {
@Requires("Membership: M-3101000 - Test AG") @Requires("Membership: M-3101000 - Test AG")
void shouldRevertCoopSharesSubscription() { void shouldRevertCoopSharesSubscription() {
new CreateCoopSharesRevertTransaction(this) new CreateCoopSharesRevertTransaction(this)
.given("memberNumber", "3101000") .given("memberNumber", "M-3101000")
.given("comment", "reverting some incorrect transaction") .given("comment", "reverting some incorrect transaction")
.given("dateOfIncorrectTransaction", "2024-02-15") .given("dateOfIncorrectTransaction", "2024-02-15")
.doRun(); .doRun();
@ -362,7 +362,7 @@ class HsOfficeScenarioTests extends ScenarioTest {
@Produces("Coop-Shares CANCELLATION Transaction") @Produces("Coop-Shares CANCELLATION Transaction")
void shouldCancelCoopSharesSubscription() { void shouldCancelCoopSharesSubscription() {
new CreateCoopSharesCancellationTransaction(this) new CreateCoopSharesCancellationTransaction(this)
.given("memberNumber", "3101000") .given("memberNumber", "M-3101000")
.given("reference", "cancel 2024-01-15") .given("reference", "cancel 2024-01-15")
.given("sharesToCancel", 8) .given("sharesToCancel", 8)
.given("comment", "Cancelling 8 Shares") .given("comment", "Cancelling 8 Shares")
@ -376,7 +376,7 @@ class HsOfficeScenarioTests extends ScenarioTest {
@Produces("Coop-Assets DEPOSIT Transaction") @Produces("Coop-Assets DEPOSIT Transaction")
void shouldSubscribeCoopAssets() { void shouldSubscribeCoopAssets() {
new CreateCoopAssetsDepositTransaction(this) new CreateCoopAssetsDepositTransaction(this)
.given("memberNumber", "3101000") .given("memberNumber", "M-3101000")
.given("reference", "sign 2024-01-15") .given("reference", "sign 2024-01-15")
.given("assetValue", 100*64) .given("assetValue", 100*64)
.given("comment", "disposal for initial shares") .given("comment", "disposal for initial shares")
@ -386,10 +386,10 @@ class HsOfficeScenarioTests extends ScenarioTest {
@Test @Test
@Order(4302) @Order(4302)
@Requires("Membership: M-3101000 - Test AG") @Requires("Coop-Assets DEPOSIT Transaction")
void shouldRevertCoopAssetsSubscription() { void shouldRevertCoopAssetsSubscription() {
new CreateCoopAssetsRevertTransaction(this) new CreateCoopAssetsRevertTransaction(this)
.given("memberNumber", "3101000") .given("memberNumber", "M-3101000")
.given("comment", "reverting some incorrect transaction") .given("comment", "reverting some incorrect transaction")
.given("dateOfIncorrectTransaction", "2024-02-15") .given("dateOfIncorrectTransaction", "2024-02-15")
.doRun(); .doRun();
@ -401,7 +401,7 @@ class HsOfficeScenarioTests extends ScenarioTest {
@Produces("Coop-Assets DISBURSAL Transaction") @Produces("Coop-Assets DISBURSAL Transaction")
void shouldDisburseCoopAssets() { void shouldDisburseCoopAssets() {
new CreateCoopAssetsDisbursalTransaction(this) new CreateCoopAssetsDisbursalTransaction(this)
.given("memberNumber", "3101000") .given("memberNumber", "M-3101000")
.given("reference", "cancel 2024-01-15") .given("reference", "cancel 2024-01-15")
.given("valueToDisburse", 8*64) .given("valueToDisburse", 8*64)
.given("comment", "disbursal according to shares cancellation") .given("comment", "disbursal according to shares cancellation")
@ -414,7 +414,7 @@ class HsOfficeScenarioTests extends ScenarioTest {
@Requires("Membership: M-3101000 - Test AG") @Requires("Membership: M-3101000 - Test AG")
void shouldCancelMembershipOfPartner() { void shouldCancelMembershipOfPartner() {
new CancelMembership(this) new CancelMembership(this)
.given("memberNumber", "3101000") .given("memberNumber", "M-3101000")
.given("validTo", "2025-12-30") .given("validTo", "2025-12-30")
.given("newStatus", "CANCELLED") .given("newStatus", "CANCELLED")
.doRun(); .doRun();

View File

@ -9,7 +9,7 @@ public class CreateCoopAssetsRevertTransaction extends CreateCoopAssetsTransacti
requires("CoopAssets-Transaction with incorrect assetValue", alias -> requires("CoopAssets-Transaction with incorrect assetValue", alias ->
new CreateCoopAssetsDepositTransaction(testSuite) new CreateCoopAssetsDepositTransaction(testSuite)
.given("memberNumber", "3101000") .given("memberNumber", "%{memberNumber}")
.given("reference", "sign %{dateOfIncorrectTransaction}") // same as revertedAssetTx .given("reference", "sign %{dateOfIncorrectTransaction}") // same as revertedAssetTx
.given("assetValue", 10) .given("assetValue", 10)
.given("comment", "coop-assets deposit transaction with wrong asset value") .given("comment", "coop-assets deposit transaction with wrong asset value")

View File

@ -9,7 +9,7 @@ public class CreateCoopSharesRevertTransaction extends CreateCoopSharesTransacti
requires("CoopShares-Transaction with incorrect shareCount", alias -> requires("CoopShares-Transaction with incorrect shareCount", alias ->
new CreateCoopSharesSubscriptionTransaction(testSuite) new CreateCoopSharesSubscriptionTransaction(testSuite)
.given("memberNumber", "3101000") .given("memberNumber", "%{memberNumber}")
.given("reference", "sign %{dateOfIncorrectTransaction}") // same as revertedShareTx .given("reference", "sign %{dateOfIncorrectTransaction}") // same as revertedShareTx
.given("shareCount", 100) .given("shareCount", 100)
.given("comment", "coop-shares subscription transaction with wrong share count") .given("comment", "coop-shares subscription transaction with wrong share count")