From 848fb0aae87c1d0a6566a71bb12dc4937954159a Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Sun, 3 Nov 2024 18:10:37 +0100 Subject: [PATCH] add scenario shouldAddPhoneNumberToContactData --- .../scenarios/HsOfficeScenarioTests.java | 12 +++++ .../hs/office/scenarios/UseCase.java | 20 +++++++- .../contact/AddPhoneNumberToContactData.java | 47 +++++++++++++++++++ .../scenarios/contact/AmendContactData.java | 4 +- 4 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/AddPhoneNumberToContactData.java 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 1817416b..33b96a1a 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 @@ -1,6 +1,7 @@ package net.hostsharing.hsadminng.hs.office.scenarios; import net.hostsharing.hsadminng.HsadminNgApplication; +import net.hostsharing.hsadminng.hs.office.scenarios.contact.AddPhoneNumberToContactData; import net.hostsharing.hsadminng.hs.office.scenarios.contact.AmendContactData; import net.hostsharing.hsadminng.hs.office.scenarios.contact.ReplaceContactData; import net.hostsharing.hsadminng.hs.office.scenarios.debitor.CreateExternalDebitorForPartner; @@ -145,6 +146,17 @@ class HsOfficeScenarioTests extends ScenarioTest { @Test @Order(1101) + @Requires("Partner: Michelle Matthieu") + void shouldAddPhoneNumberToContactData() { + new AddPhoneNumberToContactData(this) + .given("partnerName", "Matthieu") + .given("newOfficePhoneNumberKey", "mobile") + .given("newOfficePhoneNumber", "+49 152 1234567") + .doRun(); + } + + @Test + @Order(1103) @Requires("Partner: Test AG") void shouldReplaceContactData() { new ReplaceContactData(this) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/UseCase.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/UseCase.java index bc5f58d7..5f0706d1 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/UseCase.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/UseCase.java @@ -80,11 +80,16 @@ public abstract class UseCase> { } }) ); - return run(); + final var response = run(); + verify(); + return response; } protected abstract HttpResponse run(); + protected void verify() { + } + public final UseCase given(final String propName, final Object propValue) { givenProperties.put(propName, propValue); ScenarioTest.putProperty(propName, propValue); @@ -106,6 +111,17 @@ public abstract class UseCase> { }); } +// public final void validate( +// final String title, +// final Supplier http, +// final Function extractor, +// final String... extraInfo) { +// withTitle(ScenarioTest.resolve(title), () -> { +// http.get(); +// Arrays.stream(extraInfo).forEach(testReport::printPara); +// }); +// } + public final void obtain(final String alias, final Supplier http, final String... extraInfo) { withTitle(ScenarioTest.resolve(alias), () -> { http.get().keep(); @@ -267,7 +283,7 @@ public abstract class UseCase> { @SneakyThrows public String getFromBody(final String path) { - return JsonPath.parse(response.body()).read(path); + return JsonPath.parse(response.body()).read(ScenarioTest.resolve(path)); } @SneakyThrows diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/AddPhoneNumberToContactData.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/AddPhoneNumberToContactData.java new file mode 100644 index 00000000..89d67e25 --- /dev/null +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/AddPhoneNumberToContactData.java @@ -0,0 +1,47 @@ +package net.hostsharing.hsadminng.hs.office.scenarios.contact; + +import net.hostsharing.hsadminng.hs.office.scenarios.ScenarioTest; +import net.hostsharing.hsadminng.hs.office.scenarios.UseCase; +import org.springframework.http.HttpStatus; + +import static io.restassured.http.ContentType.JSON; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.http.HttpStatus.OK; + +public class AddPhoneNumberToContactData extends UseCase { + + public AddPhoneNumberToContactData(final ScenarioTest testSuite) { + super(testSuite); + } + + @Override + protected HttpResponse run() { + + obtain("partnerContactUuid", () -> + httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}")) + .expecting(OK).expecting(JSON), + response -> response.expectArrayElements(1).getFromBody("[0].contact.uuid"), + "In production, data this query could result in multiple outputs. In that case, you have to find out which is the right one." + ); + + httpPatch("/api/hs/office/contacts/%{partnerContactUuid}", usingJsonBody(""" + { + "phoneNumbers": { + ${newOfficePhoneNumberKey}: ${newOfficePhoneNumber} + } + } + """)) + .expecting(HttpStatus.OK); + + return null; + } + + @Override + protected void verify() { + testSuite.testReport.printPara("### Verify"); + assertThat( + httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}")) + .expecting(OK).expecting(JSON).expectArrayElements(1).getFromBody("[0].contact.phoneNumbers.%{newOfficePhoneNumberKey}") + ).isEqualTo(ScenarioTest.resolve("%{newOfficePhoneNumber}")); + } +} diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/AmendContactData.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/AmendContactData.java index 273ab663..e4f81140 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/AmendContactData.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/AmendContactData.java @@ -17,8 +17,8 @@ public class AmendContactData extends UseCase { protected HttpResponse run() { obtain("partnerContactUuid", () -> - httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}")) - .expecting(OK).expecting(JSON), + httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}")) + .expecting(OK).expecting(JSON), response -> response.expectArrayElements(1).getFromBody("[0].contact.uuid"), "In production, data this query could result in multiple outputs. In that case, you have to find out which is the right one." );