introduce-partner-business-role #16

Merged
hsh-michaelhoennig merged 33 commits from introduce-partner-business-role into master 2024-02-01 14:48:16 +01:00
4 changed files with 60 additions and 67 deletions
Showing only changes of commit 78b4fce761 - Show all commits

View File

@ -7,6 +7,7 @@ components:
type: string type: string
enum: enum:
- UNKNOWN - UNKNOWN
- PARTNER
- EX_PARTNER - EX_PARTNER
- REPRESENTATIVE, - REPRESENTATIVE,
- VIP_CONTACT - VIP_CONTACT

View File

@ -65,7 +65,7 @@ do language plpgsql $$
call createHsOfficePersonTestData('NP', null, 'Smith', 'Peter'); call createHsOfficePersonTestData('NP', null, 'Smith', 'Peter');
call createHsOfficePersonTestData('NP', null, 'Tucker', 'Jack'); call createHsOfficePersonTestData('NP', null, 'Tucker', 'Jack');
call createHsOfficePersonTestData('NP', null, 'Fouler', 'Ellie'); call createHsOfficePersonTestData('NP', null, 'Fouler', 'Ellie');
call createHsOfficePersonTestData('LP', 'Second e.K.', 'Sandra', 'Miller'); call createHsOfficePersonTestData('LP', 'Second e.K.', 'Smith', 'Peter');
call createHsOfficePersonTestData('IF', 'Third OHG'); call createHsOfficePersonTestData('IF', 'Third OHG');
call createHsOfficePersonTestData('IF', 'Fourth eG'); call createHsOfficePersonTestData('IF', 'Fourth eG');
call createHsOfficePersonTestData('UF', 'Erben Bessler', 'Mel', 'Bessler'); call createHsOfficePersonTestData('UF', 'Erben Bessler', 'Mel', 'Bessler');

View File

@ -35,6 +35,7 @@ import static org.hamcrest.Matchers.startsWith;
@Transactional @Transactional
class HsOfficeRelationshipControllerAcceptanceTest { class HsOfficeRelationshipControllerAcceptanceTest {
public static final UUID GIVEN_NON_EXISTING_HOLDER_PERSON_UUID = UUID.fromString("3fa85f64-5717-4562-b3fc-2c963f66afa6");
@LocalServerPort @LocalServerPort
private Integer port; private Integer port;
@ -67,7 +68,7 @@ class HsOfficeRelationshipControllerAcceptanceTest {
// given // given
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenPerson = personRepo.findPersonByOptionalNameLike("Smith").get(0); final var givenPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0);
RestAssured // @formatter:off RestAssured // @formatter:off
.given() .given()
@ -75,53 +76,45 @@ class HsOfficeRelationshipControllerAcceptanceTest {
.port(port) .port(port)
.when() .when()
.get("http://localhost/api/hs/office/relationships?personUuid=%s&relationshipType=%s" .get("http://localhost/api/hs/office/relationships?personUuid=%s&relationshipType=%s"
.formatted(givenPerson.getUuid(), HsOfficeRelationshipTypeResource.REPRESENTATIVE)) .formatted(givenPerson.getUuid(), HsOfficeRelationshipTypeResource.PARTNER))
.then().log().all().assertThat() .then().log().all().assertThat()
.statusCode(200) .statusCode(200)
.contentType("application/json") .contentType("application/json")
.body("", lenientlyEquals(""" .body("", lenientlyEquals("""
[ [
{ {
"relAnchor": { "relAnchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
"personType": "INCORPORATED_FIRM", "relHolder": { "personType": "LEGAL_PERSON", "tradeName": "First GmbH" },
"tradeName": "Third OHG" "relType": "PARTNER",
}, "relMark": null,
"relHolder": { "contact": { "label": "first contact" }
"personType": "NATURAL_PERSON",
"givenName": "Peter",
"familyName": "Smith"
},
"relType": "REPRESENTATIVE",
"contact": { "label": "third contact" }
}, },
{ {
"relAnchor": { "relAnchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
"personType": "LEGAL_PERSON", "relHolder": { "personType": "INCORPORATED_FIRM", "tradeName": "Fourth eG" },
"tradeName": "Second e.K.", "relType": "PARTNER",
"givenName": "Miller", "contact": { "label": "fourth contact" }
"familyName": "Sandra"
}, },
"relHolder": { {
"personType": "NATURAL_PERSON", "relAnchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
"givenName": "Peter", "relHolder": { "personType": "LEGAL_PERSON", "tradeName": "Second e.K.", "givenName": "Peter", "familyName": "Smith" },
"familyName": "Smith" "relType": "PARTNER",
}, "relMark": null,
"relType": "REPRESENTATIVE",
"contact": { "label": "second contact" } "contact": { "label": "second contact" }
}, },
{ {
"relAnchor": { "relAnchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
"personType": "LEGAL_PERSON", "relHolder": { "personType": "NATURAL_PERSON", "givenName": "Peter", "familyName": "Smith" },
"tradeName": "First GmbH" "relType": "PARTNER",
"relMark": null,
"contact": { "label": "sixth contact" }
}, },
"relHolder": { {
"personType": "NATURAL_PERSON", "relAnchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
"tradeName": null, "relHolder": { "personType": "INCORPORATED_FIRM", "tradeName": "Third OHG" },
"givenName": "Peter", "relType": "PARTNER",
"familyName": "Smith" "relMark": null,
}, "contact": { "label": "third contact" }
"relType": "REPRESENTATIVE",
"contact": { "label": "first contact" }
} }
] ]
""")); """));
@ -139,7 +132,7 @@ class HsOfficeRelationshipControllerAcceptanceTest {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Third").get(0); final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Third").get(0);
final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Paul").get(0); final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Paul").get(0);
final var givenContact = contactRepo.findContactByOptionalLabelLike("forth").get(0); final var givenContact = contactRepo.findContactByOptionalLabelLike("second").get(0);
final var location = RestAssured // @formatter:off final var location = RestAssured // @formatter:off
.given() .given()
@ -167,7 +160,7 @@ class HsOfficeRelationshipControllerAcceptanceTest {
.body("relType", is("ACCOUNTING")) .body("relType", is("ACCOUNTING"))
.body("relAnchor.tradeName", is("Third OHG")) .body("relAnchor.tradeName", is("Third OHG"))
.body("relHolder.givenName", is("Paul")) .body("relHolder.givenName", is("Paul"))
.body("contact.label", is("fourth contact")) .body("contact.label", is("second contact"))
.header("Location", startsWith("http://localhost")) .header("Location", startsWith("http://localhost"))
.extract().header("Location"); // @formatter:on .extract().header("Location"); // @formatter:on
@ -181,9 +174,9 @@ class HsOfficeRelationshipControllerAcceptanceTest {
void globalAdmin_canNotAddRelationship_ifAnchorPersonDoesNotExist() { void globalAdmin_canNotAddRelationship_ifAnchorPersonDoesNotExist() {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenAnchorPersonUuid = UUID.fromString("3fa85f64-5717-4562-b3fc-2c963f66afa6"); final var givenAnchorPersonUuid = GIVEN_NON_EXISTING_HOLDER_PERSON_UUID;
final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Smith").get(0); final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Smith").get(0);
final var givenContact = contactRepo.findContactByOptionalLabelLike("forth").get(0); final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth").get(0);
final var location = RestAssured // @formatter:off final var location = RestAssured // @formatter:off
.given() .given()
@ -206,7 +199,7 @@ class HsOfficeRelationshipControllerAcceptanceTest {
.post("http://localhost/api/hs/office/relationships") .post("http://localhost/api/hs/office/relationships")
.then().log().all().assertThat() .then().log().all().assertThat()
.statusCode(404) .statusCode(404)
.body("message", is("cannot find relAnchorUuid 3fa85f64-5717-4562-b3fc-2c963f66afa6")); .body("message", is("cannot find relAnchorUuid " + GIVEN_NON_EXISTING_HOLDER_PERSON_UUID));
// @formatter:on // @formatter:on
} }
@ -215,8 +208,7 @@ class HsOfficeRelationshipControllerAcceptanceTest {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Third").get(0); final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Third").get(0);
final var givenHolderPersonUuid = UUID.fromString("3fa85f64-5717-4562-b3fc-2c963f66afa6"); final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth").get(0);
final var givenContact = contactRepo.findContactByOptionalLabelLike("forth").get(0);
final var location = RestAssured // @formatter:off final var location = RestAssured // @formatter:off
.given() .given()
@ -232,14 +224,14 @@ class HsOfficeRelationshipControllerAcceptanceTest {
""".formatted( """.formatted(
HsOfficeRelationshipTypeResource.ACCOUNTING, HsOfficeRelationshipTypeResource.ACCOUNTING,
givenAnchorPerson.getUuid(), givenAnchorPerson.getUuid(),
givenHolderPersonUuid, GIVEN_NON_EXISTING_HOLDER_PERSON_UUID,
givenContact.getUuid())) givenContact.getUuid()))
.port(port) .port(port)
.when() .when()
.post("http://localhost/api/hs/office/relationships") .post("http://localhost/api/hs/office/relationships")
.then().log().all().assertThat() .then().log().all().assertThat()
.statusCode(404) .statusCode(404)
.body("message", is("cannot find relHolderUuid 3fa85f64-5717-4562-b3fc-2c963f66afa6")); .body("message", is("cannot find relHolderUuid " + GIVEN_NON_EXISTING_HOLDER_PERSON_UUID));
// @formatter:on // @formatter:on
} }
@ -284,7 +276,7 @@ class HsOfficeRelationshipControllerAcceptanceTest {
@Test @Test
void globalAdmin_withoutAssumedRole_canGetArbitraryRelationship() { void globalAdmin_withoutAssumedRole_canGetArbitraryRelationship() {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final UUID givenRelationshipUuid = findRelationship("First", "Smith").getUuid(); final UUID givenRelationshipUuid = findRelationship("First", "Firby").getUuid();
RestAssured // @formatter:off RestAssured // @formatter:off
.given() .given()
@ -298,7 +290,7 @@ class HsOfficeRelationshipControllerAcceptanceTest {
.body("", lenientlyEquals(""" .body("", lenientlyEquals("""
{ {
"relAnchor": { "tradeName": "First GmbH" }, "relAnchor": { "tradeName": "First GmbH" },
"relHolder": { "familyName": "Smith" }, "relHolder": { "familyName": "Firby" },
"contact": { "label": "first contact" } "contact": { "label": "first contact" }
} }
""")); // @formatter:on """)); // @formatter:on
@ -308,7 +300,7 @@ class HsOfficeRelationshipControllerAcceptanceTest {
@Accepts({ "Relationship:X(Access Control)" }) @Accepts({ "Relationship:X(Access Control)" })
void normalUser_canNotGetUnrelatedRelationship() { void normalUser_canNotGetUnrelatedRelationship() {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final UUID givenRelationshipUuid = findRelationship("First", "Smith").getUuid(); final UUID givenRelationshipUuid = findRelationship("First", "Firby").getUuid();
RestAssured // @formatter:off RestAssured // @formatter:off
.given() .given()
@ -324,7 +316,7 @@ class HsOfficeRelationshipControllerAcceptanceTest {
@Accepts({ "Relationship:X(Access Control)" }) @Accepts({ "Relationship:X(Access Control)" })
void contactAdminUser_canGetRelatedRelationship() { void contactAdminUser_canGetRelatedRelationship() {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenRelationship = findRelationship("First", "Smith"); final var givenRelationship = findRelationship("First", "Firby");
assertThat(givenRelationship.getContact().getLabel()).isEqualTo("first contact"); assertThat(givenRelationship.getContact().getLabel()).isEqualTo("first contact");
RestAssured // @formatter:off RestAssured // @formatter:off
@ -339,7 +331,7 @@ class HsOfficeRelationshipControllerAcceptanceTest {
.body("", lenientlyEquals(""" .body("", lenientlyEquals("""
{ {
"relAnchor": { "tradeName": "First GmbH" }, "relAnchor": { "tradeName": "First GmbH" },
"relHolder": { "familyName": "Smith" }, "relHolder": { "familyName": "Firby" },
"contact": { "label": "first contact" } "contact": { "label": "first contact" }
} }
""")); // @formatter:on """)); // @formatter:on
@ -369,7 +361,7 @@ class HsOfficeRelationshipControllerAcceptanceTest {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenRelationship = givenSomeTemporaryRelationshipBessler(); final var givenRelationship = givenSomeTemporaryRelationshipBessler();
assertThat(givenRelationship.getContact().getLabel()).isEqualTo("seventh contact"); assertThat(givenRelationship.getContact().getLabel()).isEqualTo("seventh contact");
final var givenContact = contactRepo.findContactByOptionalLabelLike("forth").get(0); final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth").get(0);
final var location = RestAssured // @formatter:off final var location = RestAssured // @formatter:off
.given() .given()

View File

@ -151,7 +151,7 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTest {
public void globalAdmin_withoutAssumedRole_canViewAllRelationshipsOfArbitraryPerson() { public void globalAdmin_withoutAssumedRole_canViewAllRelationshipsOfArbitraryPerson() {
// given // given
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
final var person = personRepo.findPersonByOptionalNameLike("Smith").stream().findFirst().orElseThrow(); final var person = personRepo.findPersonByOptionalNameLike("Second e.K.").stream().findFirst().orElseThrow();
// when // when
final var result = relationshipRepo.findRelationshipRelatedToPersonUuid(person.getUuid()); final var result = relationshipRepo.findRelationshipRelatedToPersonUuid(person.getUuid());
@ -159,8 +159,7 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTest {
// then // then
allTheseRelationshipsAreReturned( allTheseRelationshipsAreReturned(
result, result,
"rel(relAnchor='LP First GmbH', relType='REPRESENTATIVE', relHolder='NP Smith, Peter', contact='first contact')", "rel(relAnchor='LP Hostsharing eG', relType='PARTNER', relHolder='LP Second e.K.', contact='second contact')",
"rel(relAnchor='IF Third OHG', relType='REPRESENTATIVE', relHolder='NP Smith, Peter', contact='third contact')",
"rel(relAnchor='LP Second e.K.', relType='REPRESENTATIVE', relHolder='NP Smith, Peter', contact='second contact')"); "rel(relAnchor='LP Second e.K.', relType='REPRESENTATIVE', relHolder='NP Smith, Peter', contact='second contact')");
} }
@ -176,7 +175,8 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTest {
// then: // then:
exactlyTheseRelationshipsAreReturned( exactlyTheseRelationshipsAreReturned(
result, result,
"rel(relAnchor='LP First GmbH', relType='REPRESENTATIVE', relHolder='NP Smith, Peter', contact='first contact')"); "rel(relAnchor='LP Hostsharing eG', relType='PARTNER', relHolder='LP First GmbH', contact='first contact')",
"rel(relAnchor='LP First GmbH', relType='REPRESENTATIVE', relHolder='NP Firby, Susan', contact='first contact')");
} }
} }
@ -380,8 +380,8 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTest {
// then // then
assertThat(customerLogEntries).map(Arrays::toString).contains( assertThat(customerLogEntries).map(Arrays::toString).contains(
"[creating relationship test-data FirstGmbH-Smith, hs_office_relationship, INSERT]", "[creating relationship test-data HostsharingeG-FirstGmbH, hs_office_relationship, INSERT]",
"[creating relationship test-data Seconde.K.-Smith, hs_office_relationship, INSERT]"); "[creating relationship test-data FirstGmbH-Firby, hs_office_relationship, INSERT]");
} }
private HsOfficeRelationshipEntity givenSomeTemporaryRelationshipBessler(final String holderPerson, final String contact) { private HsOfficeRelationshipEntity givenSomeTemporaryRelationshipBessler(final String holderPerson, final String contact) {