diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java index 9f957472..c7a2236a 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java @@ -31,7 +31,7 @@ import net.hostsharing.hsadminng.hs.office.scenarios.partner.CreatePartner; import net.hostsharing.hsadminng.hs.office.scenarios.partner.DeletePartner; import net.hostsharing.hsadminng.hs.office.scenarios.person.ShouldUpdatePersonData; import net.hostsharing.hsadminng.hs.office.scenarios.subscription.RemoveOperationsContactFromPartner; -import net.hostsharing.hsadminng.hs.office.scenarios.subscription.SubscribeToMailinglist; +import net.hostsharing.hsadminng.hs.office.scenarios.subscription.SubscribeNewPersonAndContactToMailinglist; import net.hostsharing.hsadminng.hs.office.scenarios.subscription.UnsubscribeFromMailinglist; import net.hostsharing.hsadminng.hs.scenarios.Produces; import net.hostsharing.hsadminng.hs.scenarios.Requires; @@ -564,7 +564,7 @@ class HsOfficeScenarioTests extends ScenarioTest { @Requires("Person: Test AG") @Produces("Subscription: Michael Miller to operations-announce") void shouldSubscribeNewPersonAndContactToMailinglist() { - new SubscribeToMailinglist(scenarioTest) + new SubscribeNewPersonAndContactToMailinglist(scenarioTest) // TODO.spec: do we need the personType? or is an operational contact always a natural person? what about distribution lists? .given("partnerPersonTradeName", "Test AG") .given("subscriberFamilyName", "Miller") diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/subscription/SubscribeNewPersonAndContactToMailinglist.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/subscription/SubscribeNewPersonAndContactToMailinglist.java new file mode 100644 index 00000000..5638e440 --- /dev/null +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/subscription/SubscribeNewPersonAndContactToMailinglist.java @@ -0,0 +1,46 @@ +package net.hostsharing.hsadminng.hs.office.scenarios.subscription; + +import net.hostsharing.hsadminng.hs.scenarios.UseCase; +import net.hostsharing.hsadminng.hs.scenarios.ScenarioTest; + +import static io.restassured.http.ContentType.JSON; +import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.OK; + +public class SubscribeNewPersonAndContactToMailinglist extends UseCase { + + public SubscribeNewPersonAndContactToMailinglist(final ScenarioTest testSuite) { + super(testSuite); + } + + @Override + protected HttpResponse run() { + + obtain("Person: %{partnerPersonTradeName}", () -> + httpGet("/api/hs/office/persons?name=" + uriEncoded("%{partnerPersonTradeName}")) + .expecting(OK).expecting(JSON), + response -> response.expectArrayElements(1).getFromBody("[0].uuid"), + "In production, data this query could result in multiple outputs. In that case, you have to find out which is the right one." + ); + + return httpPost("/api/hs/office/relations", usingJsonBody(""" + { + "type": "SUBSCRIBER", + "mark": ${mailingList}, + "anchor.uuid": ${Person: %{partnerPersonTradeName}}, + "holder": { + "personType": "NATURAL_PERSON", + "familyName": ${subscriberFamilyName}, + "givenName": ${subscriberGivenName} + }, + "contact": { + "caption": "%{subscriberGivenName} %{subscriberFamilyName}", + "emailAddresses": { + "main": ${subscriberEMailAddress} + } + } + } + """)) + .expecting(CREATED).expecting(JSON); + } +} diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/subscription/SubscribeToMailinglist.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/subscription/SubscribeToMailinglist.java deleted file mode 100644 index c524fb18..00000000 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/subscription/SubscribeToMailinglist.java +++ /dev/null @@ -1,62 +0,0 @@ -package net.hostsharing.hsadminng.hs.office.scenarios.subscription; - -import io.restassured.http.ContentType; -import net.hostsharing.hsadminng.hs.scenarios.UseCase; -import net.hostsharing.hsadminng.hs.scenarios.ScenarioTest; -import org.springframework.http.HttpStatus; - -import static io.restassured.http.ContentType.JSON; -import static org.springframework.http.HttpStatus.CREATED; -import static org.springframework.http.HttpStatus.OK; - -public class SubscribeToMailinglist extends UseCase { - - public SubscribeToMailinglist(final ScenarioTest testSuite) { - super(testSuite); - } - - @Override - protected HttpResponse run() { - - obtain("Person: %{partnerPersonTradeName}", () -> - httpGet("/api/hs/office/persons?name=" + uriEncoded("%{partnerPersonTradeName}")) - .expecting(OK).expecting(JSON), - response -> response.expectArrayElements(1).getFromBody("[0].uuid"), - "In production, data this query could result in multiple outputs. In that case, you have to find out which is the right one." - ); - - obtain("Person: %{subscriberGivenName} %{subscriberFamilyName}", () -> - httpPost("/api/hs/office/persons", usingJsonBody(""" - { - "personType": "NATURAL_PERSON", - "familyName": ${subscriberFamilyName}, - "givenName": ${subscriberGivenName} - } - """)) - .expecting(HttpStatus.CREATED).expecting(ContentType.JSON) - ); - - obtain("Contact: %{subscriberGivenName} %{subscriberFamilyName}", () -> - httpPost("/api/hs/office/contacts", usingJsonBody(""" - { - "caption": "%{subscriberGivenName} %{subscriberFamilyName}", - "emailAddresses": { - "main": ${subscriberEMailAddress} - } - } - """)) - .expecting(CREATED).expecting(JSON) - ); - - return httpPost("/api/hs/office/relations", usingJsonBody(""" - { - "type": "SUBSCRIBER", - "mark": ${mailingList}, - "anchor.uuid": ${Person: %{partnerPersonTradeName}}, - "holder.uuid": ${Person: %{subscriberGivenName} %{subscriberFamilyName}}, - "contact.uuid": ${Contact: %{subscriberGivenName} %{subscriberFamilyName}} - } - """)) - .expecting(CREATED).expecting(JSON); - } -}