feature/use-case-acceptance-tests-3 (#119)

Co-authored-by: Michael Hoennig <michael@hoennig.de>
Reviewed-on: #119
Reviewed-by: Marc Sandlus <marc.sandlus@hostsharing.net>
This commit is contained in:
Michael Hoennig 2024-11-07 10:11:46 +01:00
parent 6191bf16e0
commit e97b177a92
13 changed files with 156 additions and 22 deletions

View File

@ -34,8 +34,8 @@ public class HsOfficeMembershipController implements HsOfficeMembershipsApi {
public ResponseEntity<List<HsOfficeMembershipResource>> listMemberships(
final String currentSubject,
final String assumedRoles,
UUID partnerUuid,
Integer memberNumber) {
final UUID partnerUuid,
final Integer memberNumber) {
context.define(currentSubject, assumedRoles);
final var entities = ( memberNumber != null)

View File

@ -11,12 +11,14 @@ import net.hostsharing.hsadminng.hs.office.scenarios.debitor.CreateSepaMandateFo
import net.hostsharing.hsadminng.hs.office.scenarios.debitor.FinallyDeleteSepaMandateForDebitor;
import net.hostsharing.hsadminng.hs.office.scenarios.debitor.DontDeleteDefaultDebitor;
import net.hostsharing.hsadminng.hs.office.scenarios.debitor.InvalidateSepaMandateForDebitor;
import net.hostsharing.hsadminng.hs.office.scenarios.membership.CancelMembership;
import net.hostsharing.hsadminng.hs.office.scenarios.membership.CreateMembership;
import net.hostsharing.hsadminng.hs.office.scenarios.partner.AddOperationsContactToPartner;
import net.hostsharing.hsadminng.hs.office.scenarios.partner.CreatePartner;
import net.hostsharing.hsadminng.hs.office.scenarios.debitor.DeleteDebitor;
import net.hostsharing.hsadminng.hs.office.scenarios.partner.DeletePartner;
import net.hostsharing.hsadminng.hs.office.scenarios.partner.AddRepresentativeToPartner;
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.UnsubscribeFromMailinglist;
@ -197,6 +199,16 @@ class HsOfficeScenarioTests extends ScenarioTest {
.doRun();
}
@Test
@Order(1201)
@Requires("Partner: Michelle Matthieu")
void shouldUpdatePersonData() {
new ShouldUpdatePersonData(this)
.given("oldFamilyName", "Matthieu")
.given("newFamilyName", "Matthieu-Zhang")
.doRun();
}
@Test
@Order(2010)
@Requires("Partner: Test AG")
@ -302,12 +314,26 @@ class HsOfficeScenarioTests extends ScenarioTest {
@Test
@Order(4000)
@Requires("Partner: Test AG")
@Produces("Membership: Test AG 00")
void shouldCreateMembershipForPartner() {
new CreateMembership(this)
.given("partnerName", "Test AG")
.given("memberNumberSuffix", "00")
.given("validFrom", "2024-10-15")
.given("newStatus", "ACTIVE")
.given("membershipFeeBillable", "true")
.doRun()
.keep();
}
@Test
@Order(4900)
@Requires("Membership: Test AG 00")
void shouldCancelMembershipOfPartner() {
new CancelMembership(this)
.given("memberNumber", "3101000")
.given("validTo", "2025-12-30")
.given("newStatus", "CANCELLED")
.doRun();
}

View File

@ -86,13 +86,13 @@ public abstract class UseCase<T extends UseCase<?>> {
})
);
final var response = run();
verify();
verify(response);
return response;
}
protected abstract HttpResponse run();
protected void verify() {
protected void verify(final HttpResponse response) {
}
public final UseCase<T> given(final String propName, final Object propValue) {
@ -233,6 +233,7 @@ public abstract class UseCase<T extends UseCase<?>> {
@Getter
private final HttpStatus status;
@Getter
private UUID locationUuid;
@SneakyThrows

View File

@ -40,7 +40,7 @@ public class AddPhoneNumberToContactData extends UseCase<AddPhoneNumberToContact
}
@Override
protected void verify() {
protected void verify(final UseCase<AddPhoneNumberToContactData>.HttpResponse response) {
verify(
"Verify if the New Phone Number Got Added",
() -> httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}"))

View File

@ -39,7 +39,7 @@ public class RemovePhoneNumberFromContactData extends UseCase<RemovePhoneNumberF
}
@Override
protected void verify() {
protected void verify(final UseCase<RemovePhoneNumberFromContactData>.HttpResponse response) {
verify(
"Verify if the New Phone Number Got Added",
() -> httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}"))

View File

@ -57,7 +57,7 @@ public class ReplaceContactData extends UseCase<ReplaceContactData> {
}
@Override
protected void verify() {
protected void verify(final UseCase<ReplaceContactData>.HttpResponse response) {
verify(
"Verify if the Contact-Relation Got Replaced in the Partner-Relation",
() -> httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}"))

View File

@ -0,0 +1,47 @@
package net.hostsharing.hsadminng.hs.office.scenarios.membership;
import io.restassured.http.ContentType;
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.springframework.http.HttpStatus.OK;
public class CancelMembership extends UseCase<CancelMembership> {
public CancelMembership(final ScenarioTest testSuite) {
super(testSuite);
}
@Override
protected HttpResponse run() {
obtain("Membership: %{memberNumber}", () ->
httpGet("/api/hs/office/memberships?memberNumber=%{memberNumber}")
.expectArrayElements(1),
response -> response.expectArrayElements(1).getFromBody("[0].uuid")
);
return withTitle("Patch the New Status Into the Membership", () ->
httpPatch("/api/hs/office/memberships/%{Membership: %{memberNumber}}", usingJsonBody("""
{
"validTo": ${validTo},
"status": ${newStatus}
}
"""))
.expecting(HttpStatus.OK).expecting(ContentType.JSON)
);
}
@Override
protected void verify(final UseCase<CancelMembership>.HttpResponse response) {
verify(
"Verify That the Membership Got Cancelled",
() -> httpGet("/api/hs/office/memberships/%{Membership: %{memberNumber}}")
.expecting(OK).expecting(JSON),
path("validTo").contains("%{validTo}"),
path("status").contains("CANCELLED")
);
}
}

View File

@ -5,6 +5,9 @@ import net.hostsharing.hsadminng.hs.office.scenarios.UseCase;
import net.hostsharing.hsadminng.hs.office.scenarios.ScenarioTest;
import org.springframework.http.HttpStatus;
import static io.restassured.http.ContentType.JSON;
import static org.springframework.http.HttpStatus.OK;
public class CreateMembership extends UseCase<CreateMembership> {
public CreateMembership(final ScenarioTest testSuite) {
@ -13,17 +16,26 @@ public class CreateMembership extends UseCase<CreateMembership> {
@Override
protected HttpResponse run() {
obtain("Membership: %{partnerName} 00", () ->
httpPost("/api/hs/office/memberships", usingJsonBody("""
{
"partnerUuid": ${Partner: Test AG},
"memberNumberSuffix": ${memberNumberSuffix},
"validFrom": ${validFrom},
"membershipFeeBillable": ${membershipFeeBillable}
}
"""))
.expecting(HttpStatus.CREATED).expecting(ContentType.JSON)
return httpPost("/api/hs/office/memberships", usingJsonBody("""
{
"partnerUuid": ${Partner: Test AG},
"memberNumberSuffix": ${memberNumberSuffix},
"status": "ACTIVE",
"validFrom": ${validFrom},
"membershipFeeBillable": ${membershipFeeBillable}
}
"""))
.expecting(HttpStatus.CREATED).expecting(ContentType.JSON);
}
@Override
protected void verify(final UseCase<CreateMembership>.HttpResponse response) {
verify(
"Verify That the Membership Got Created",
() -> httpGet("/api/hs/office/memberships/" + response.getLocationUuid())
.expecting(OK).expecting(JSON),
path("validFrom").contains("%{validFrom}"),
path("status").contains("ACTIVE")
);
return null;
}
}

View File

@ -66,7 +66,7 @@ public class AddOperationsContactToPartner extends UseCase<AddOperationsContactT
}
@Override
protected void verify() {
protected void verify(final UseCase<AddOperationsContactToPartner>.HttpResponse response) {
verify(
"Verify the New OPERATIONS Relation",
() -> httpGet("/api/hs/office/relations?relationType=OPERATIONS&personData=" + uriEncoded(

View File

@ -69,7 +69,7 @@ public class AddRepresentativeToPartner extends UseCase<AddRepresentativeToPartn
}
@Override
protected void verify() {
protected void verify(final UseCase<AddRepresentativeToPartner>.HttpResponse response) {
verify(
"Verify the REPRESENTATIVE Relation Got Removed",
() -> httpGet("/api/hs/office/relations?relationType=REPRESENTATIVE&personData=" + uriEncoded("%{representativeFamilyName}"))

View File

@ -76,7 +76,7 @@ public class CreatePartner extends UseCase<CreatePartner> {
}
@Override
protected void verify() {
protected void verify(final UseCase<CreatePartner>.HttpResponse response) {
verify(
"Verify the New Partner Relation",
() -> httpGet("/api/hs/office/relations?relationType=PARTNER&contactData=&{contactCaption}")

View File

@ -0,0 +1,48 @@
package net.hostsharing.hsadminng.hs.office.scenarios.person;
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.springframework.http.HttpStatus.OK;
public class ShouldUpdatePersonData extends UseCase<ShouldUpdatePersonData> {
public ShouldUpdatePersonData(final ScenarioTest testSuite) {
super(testSuite);
}
@Override
protected HttpResponse run() {
obtain(
"personUuid",
() -> httpGet("/api/hs/office/persons?name=" + uriEncoded("%{oldFamilyName}"))
.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."
);
withTitle("Patch the Additional Phone-Number into the Person", () ->
httpPatch("/api/hs/office/persons/%{personUuid}", usingJsonBody("""
{
"familyName": ${newFamilyName}
}
"""))
.expecting(HttpStatus.OK)
);
return null;
}
@Override
protected void verify(final UseCase<ShouldUpdatePersonData>.HttpResponse response) {
verify(
"Verify that the Family Name Got Amended",
() -> httpGet("/api/hs/office/persons/%{personUuid}")
.expecting(OK).expecting(JSON),
path("familyName").contains("%{newFamilyName}")
);
}
}

View File

@ -33,7 +33,7 @@ public class RemoveOperationsContactFromPartner extends UseCase<RemoveOperations
}
@Override
protected void verify() {
protected void verify(final UseCase<RemoveOperationsContactFromPartner>.HttpResponse response) {
verify(
"Verify the New OPERATIONS Relation",
() -> httpGet("/api/hs/office/relations/&{Operations-Contact: %{operationsContactPerson}}")