From ff42bc45ab1ae2de86945d105e5e232affadb87c Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 13 Nov 2024 14:56:44 +0100 Subject: [PATCH] add RestTest for findMembershipByNonExistingMemberNumberReturnsEmptyList --- .../HsOfficeMembershipControllerRestTest.java | 33 ++++++++++++++++++- .../hs/office/scenarios/PathAssertion.java | 1 - 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipControllerRestTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipControllerRestTest.java index 455008a2..2306fcca 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipControllerRestTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipControllerRestTest.java @@ -20,6 +20,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import java.util.UUID; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; @@ -44,8 +45,36 @@ public class HsOfficeMembershipControllerRestTest { @MockBean EntityManagerWrapper em; + @Nested + class GetMemberships { + + @Test + void findMembershipByNonExistingMemberNumberReturnsEmptyList() throws Exception { + + // when + mockMvc.perform(MockMvcRequestBuilders + .get("/api/hs/office/memberships?memberNumber=12345") + .header("current-subject", "superuser-alex@hostsharing.net") + .contentType(MediaType.APPLICATION_JSON) + .content(""" + { + "partner.uuid": null, + "memberNumberSuffix": "01", + "validFrom": "2022-10-13", + "membershipFeeBillable": "true" + } + """) + .accept(MediaType.APPLICATION_JSON)) + + // then + .andExpect(status().is2xxSuccessful()) + .andExpect(jsonPath("$", hasSize(0))); + } + } + @Nested class AddMembership { + @Test void respondBadRequest_ifPartnerUuidIsMissing() throws Exception { @@ -98,7 +127,9 @@ public class HsOfficeMembershipControllerRestTest { .andExpect(status().is4xxClientError()) .andExpect(jsonPath("statusCode", is(400))) .andExpect(jsonPath("statusPhrase", is("Bad Request"))) - .andExpect(jsonPath("message", is("ERROR: [400] Unable to find Partner by partner.uuid: " + givenPartnerUuid))); + .andExpect(jsonPath( + "message", + is("ERROR: [400] Unable to find Partner by partner.uuid: " + givenPartnerUuid))); } @ParameterizedTest diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/PathAssertion.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/PathAssertion.java index baf8d358..a358280d 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/PathAssertion.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/PathAssertion.java @@ -18,7 +18,6 @@ public class PathAssertion { public Consumer contains(final String resolvableValue) { return response -> { try { - // FIXME: typed check instead of .map(Object::toString) possible? response.path(path).map(Object::toString).contains(ScenarioTest.resolve(resolvableValue)); } catch (final AssertionError e) { // without this, the error message is often lacking important context