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
enum:
- UNKNOWN
- PARTNER
- EX_PARTNER
- REPRESENTATIVE,
- VIP_CONTACT

View File

@ -65,7 +65,7 @@ do language plpgsql $$
call createHsOfficePersonTestData('NP', null, 'Smith', 'Peter');
call createHsOfficePersonTestData('NP', null, 'Tucker', 'Jack');
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', 'Fourth eG');
call createHsOfficePersonTestData('UF', 'Erben Bessler', 'Mel', 'Bessler');

View File

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

View File

@ -151,7 +151,7 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTest {
public void globalAdmin_withoutAssumedRole_canViewAllRelationshipsOfArbitraryPerson() {
// given
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
final var result = relationshipRepo.findRelationshipRelatedToPersonUuid(person.getUuid());
@ -159,8 +159,7 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTest {
// then
allTheseRelationshipsAreReturned(
result,
"rel(relAnchor='LP First GmbH', relType='REPRESENTATIVE', relHolder='NP Smith, Peter', contact='first contact')",
"rel(relAnchor='IF Third OHG', relType='REPRESENTATIVE', relHolder='NP Smith, Peter', contact='third contact')",
"rel(relAnchor='LP Hostsharing eG', relType='PARTNER', relHolder='LP Second e.K.', 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:
exactlyTheseRelationshipsAreReturned(
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
assertThat(customerLogEntries).map(Arrays::toString).contains(
"[creating relationship test-data FirstGmbH-Smith, hs_office_relationship, INSERT]",
"[creating relationship test-data Seconde.K.-Smith, hs_office_relationship, INSERT]");
"[creating relationship test-data HostsharingeG-FirstGmbH, hs_office_relationship, INSERT]",
"[creating relationship test-data FirstGmbH-Firby, hs_office_relationship, INSERT]");
}
private HsOfficeRelationshipEntity givenSomeTemporaryRelationshipBessler(final String holderPerson, final String contact) {