From e362c5aac295e5dc6b550f6394f0324d505a455c Mon Sep 17 00:00:00 2001 From: peremunoz Date: Thu, 4 Apr 2024 15:43:29 +0200 Subject: [PATCH] Improve step implementation and add a new one to double-check the certificate validity --- .../ValidateShelterCertificateStepDefs.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/test/java/cat/udl/eps/softarch/demo/steps/ValidateShelterCertificateStepDefs.java b/src/test/java/cat/udl/eps/softarch/demo/steps/ValidateShelterCertificateStepDefs.java index 4a39ae43..785278eb 100644 --- a/src/test/java/cat/udl/eps/softarch/demo/steps/ValidateShelterCertificateStepDefs.java +++ b/src/test/java/cat/udl/eps/softarch/demo/steps/ValidateShelterCertificateStepDefs.java @@ -135,12 +135,27 @@ public void thenAdminShouldVerifyTheCertificateValidityAssociatedWithAShelterWit JSONObject jsonObject = new JSONObject(stepDefs.result.andReturn().getResponse().getContentAsString()); - boolean isValidated = jsonObject.getBoolean("validated"); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSXXX"); - LocalDate shelterCertificateExpirationDate = LocalDate.parse(jsonObject.getString("expirationDate"), formatter); + String certificateUri = jsonObject.getString("uri"); - boolean isShelterCertificateValid = shelterCertificateExpirationDate.isAfter(LocalDate.now()); - Assert.assertFalse(isShelterCertificateValid && isValidated); + stepDefs.result = stepDefs.mockMvc.perform( + patch(certificateUri) + .content("{\"validated\":false}") + .with(AuthenticationStepDefs.authenticate()) + .accept("application/json")); } + @Then("The shelter certificate from shelter with name {string} is not validated") + public void theShelterCertificateFromShelterWithNameIsStillNotValidated(String shelterName) throws Exception { + Shelter shelter = shelterRepository.findByName(shelterName).get(0); + + stepDefs.result = stepDefs.mockMvc.perform( + get( "/shelterCertificates/search/findByShelterServed?shelterServed={id}", "/shelters/"+shelter.getId()) + .with(AuthenticationStepDefs.authenticate()) + .accept("application/json")); + + JSONObject jsonObject = new JSONObject(stepDefs.result.andReturn().getResponse().getContentAsString()); + boolean isValidated = jsonObject.getBoolean("validated"); + + Assert.assertFalse(isValidated); + } }