From 67c1b5023987534a258d07f1166e2b5ab909eac9 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 14 Mar 2024 12:52:24 +0100 Subject: [PATCH] fix setting relation mark via API (#24) Co-authored-by: Michael Hoennig Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/24 Reviewed-by: Timotheus Pokorra --- .../hs/office/relation/HsOfficeRelationController.java | 1 + .../hs-office/hs-office-relations-schemas.yaml | 3 ++- .../relation/HsOfficeRelationControllerAcceptanceTest.java | 7 +++++-- .../HsOfficeRelationRepositoryIntegrationTest.java | 6 +++++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationController.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationController.java index a7923128..e1f80148 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationController.java @@ -70,6 +70,7 @@ public class HsOfficeRelationController implements HsOfficeRelationsApi { final var entityToSave = new HsOfficeRelationEntity(); entityToSave.setType(HsOfficeRelationType.valueOf(body.getType())); + entityToSave.setMark(body.getMark()); entityToSave.setAnchor(holderRepo.findByUuid(body.getAnchorUuid()).orElseThrow( () -> new NoSuchElementException("cannot find anchorUuid " + body.getAnchorUuid()) )); diff --git a/src/main/resources/api-definition/hs-office/hs-office-relations-schemas.yaml b/src/main/resources/api-definition/hs-office/hs-office-relations-schemas.yaml index b092cd0a..7b316b40 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-relations-schemas.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-relations-schemas.yaml @@ -55,6 +55,7 @@ components: nullable: true mark: type: string + nullable: true contactUuid: type: string format: uuid @@ -62,4 +63,4 @@ components: - anchorUuid - holderUuid - type - - relContactUuid + - contactUuid diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java index fd978e1d..c4654bd3 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java @@ -137,12 +137,14 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean .body(""" { "type": "%s", + "mark": "%s", "anchorUuid": "%s", "holderUuid": "%s", "contactUuid": "%s" } """.formatted( - HsOfficeRelationTypeResource.DEBITOR, + HsOfficeRelationTypeResource.SUBSCRIBER, + "operations-discuss", givenAnchorPerson.getUuid(), givenHolderPerson.getUuid(), givenContact.getUuid())) @@ -153,7 +155,8 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean .statusCode(201) .contentType(ContentType.JSON) .body("uuid", isUuidValid()) - .body("type", is("DEBITOR")) + .body("type", is("SUBSCRIBER")) + .body("mark", is("operations-discuss")) .body("anchor.tradeName", is("Third OHG")) .body("holder.givenName", is("Paul")) .body("contact.label", is("second contact")) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepositoryIntegrationTest.java index 545e7b03..5c10af88 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRepositoryIntegrationTest.java @@ -72,7 +72,8 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea final var newRelation = HsOfficeRelationEntity.builder() .anchor(givenAnchorPerson) .holder(givenHolderPerson) - .type(HsOfficeRelationType.REPRESENTATIVE) + .type(HsOfficeRelationType.SUBSCRIBER) + .mark("operations-announce") .contact(givenContact) .build(); return toCleanup(relationRepo.save(newRelation)); @@ -83,6 +84,9 @@ class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithClea assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeRelationEntity::getUuid).isNotNull(); assertThatRelationIsPersisted(result.returnedValue()); assertThat(relationRepo.count()).isEqualTo(count + 1); + final var stored = relationRepo.findByUuid(result.returnedValue().getUuid()); + assertThat(stored).isNotEmpty().map(HsOfficeRelationEntity::toString).get() + .isEqualTo("rel(anchor='NP Bessler, Anita', type='SUBSCRIBER', mark='operations-announce', holder='NP Bessler, Anita', contact='fourth contact')"); } @Test