Skip to content

Commit

Permalink
Improve step implementation and add a new one to double-check the cer…
Browse files Browse the repository at this point in the history
…tificate validity
  • Loading branch information
peremunoz committed Apr 4, 2024
1 parent 173f85c commit e362c5a
Showing 1 changed file with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit e362c5a

Please sign in to comment.