diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/ShelterCertificate.java b/src/main/java/cat/udl/eps/softarch/demo/domain/ShelterCertificate.java index 101553a..3c8a4d8 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/ShelterCertificate.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/ShelterCertificate.java @@ -17,14 +17,17 @@ public class ShelterCertificate extends UriEntity { @GeneratedValue() private Long id; - @JsonProperty(access = JsonProperty.Access.READ_ONLY) @NotNull private ZonedDateTime expirationDate; - @NotNull private Boolean validated; @JsonIdentityReference(alwaysAsId = true) @ManyToOne private Shelter shelterServed; + + @PrePersist() + public void prePersist() { + this.validated = false; + } } diff --git a/src/test/java/cat/udl/eps/softarch/demo/steps/AddShelterCertificateStepdefs.java b/src/test/java/cat/udl/eps/softarch/demo/steps/AddShelterCertificateStepdefs.java new file mode 100644 index 0000000..7a8c925 --- /dev/null +++ b/src/test/java/cat/udl/eps/softarch/demo/steps/AddShelterCertificateStepdefs.java @@ -0,0 +1,37 @@ +package cat.udl.eps.softarch.demo.steps; + +import cat.udl.eps.softarch.demo.domain.Shelter; +import cat.udl.eps.softarch.demo.repository.ShelterRepository; +import io.cucumber.java.en.When; +import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; + +import java.nio.charset.StandardCharsets; +import java.time.ZonedDateTime; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; + +public class AddShelterCertificateStepdefs { + + @Autowired() + private ShelterRepository shelterRepository; + + @Autowired() + private StepDefs stepDefs; + + @When("I add a Shelter Certificate with valid expiration date to the shelter with name {string}") + public void iAddAShelterCertificateWithNameAndDescriptionToTheShelterWithName(String shelterName) throws Exception { + Shelter shelter = this.shelterRepository.findByName(shelterName).get(0); + + stepDefs.result = stepDefs.mockMvc.perform( + post("/shelterCertificates") + .contentType(MediaType.APPLICATION_JSON) + .content(new JSONObject() + .put("expirationDate", ZonedDateTime.now().plusMonths(1)) + .put("shelterServed", "/shelter/"+shelter.getId()) + .toString() + .getBytes(StandardCharsets.UTF_8)) + .with(AuthenticationStepDefs.authenticate())); + } +} diff --git a/src/test/resources/features/AddShelterCertificate.feature b/src/test/resources/features/AddShelterCertificate.feature new file mode 100644 index 0000000..cfc814b --- /dev/null +++ b/src/test/resources/features/AddShelterCertificate.feature @@ -0,0 +1,18 @@ +Feature: Add Shelter Certificate + As a ShelterVolunteer + I want to add a Shelter Certificate + So that my Shelter has a Certificate + + Background: Exists a shelter with name "test" and a shelter volunteer + Given A shelter with name "test" + And There is a registered user with username "volunteer" and password "123456789" and email "volunteer@mypets.com" + + Scenario: Adding a Shelter Certificate as a Shelter Volunteer + Given I can login with username "volunteer" and password "123456789" + When I add a Shelter Certificate with valid expiration date to the shelter with name "test" + Then The response code is 201 + + Scenario: Adding a Shelter Certificate as a non Shelter Volunteer + Given I cannot login with username "test" and password "wrongPassword" + When I add a Shelter Certificate with valid expiration date to the shelter with name "test" + Then The response code is 401 \ No newline at end of file