-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from UdL-EPS-SoftArch/Feature-Edit-Medical-Record
Feature edit medical record
- Loading branch information
Showing
3 changed files
with
155 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/test/java/cat/udl/eps/softarch/demo/steps/EditMedicalRecordStepDefs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package cat.udl.eps.softarch.demo.steps; | ||
|
||
import cat.udl.eps.softarch.demo.domain.MedicalRecord; | ||
import cat.udl.eps.softarch.demo.domain.Pet; | ||
import cat.udl.eps.softarch.demo.repository.MedicalRecordRepository; | ||
import cat.udl.eps.softarch.demo.repository.PetRepository; | ||
import io.cucumber.java.en.And; | ||
import io.cucumber.java.en.When; | ||
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.put; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
|
||
public class EditMedicalRecordStepDefs { | ||
|
||
@Autowired | ||
private StepDefs stepDefs; | ||
|
||
@Autowired | ||
MedicalRecordRepository medicalRecordRepository; | ||
|
||
@Autowired | ||
PetRepository petRepository; | ||
|
||
@And("a medical record exists for the pet") | ||
public void aMedicalRecordExistsForThePet() { | ||
Pet pet = petRepository.findAll().iterator().next(); | ||
|
||
MedicalRecord existingMedicalRecord; | ||
existingMedicalRecord = new MedicalRecord(); | ||
existingMedicalRecord.setPet(pet); | ||
existingMedicalRecord.setIssue("Initial Issue"); | ||
existingMedicalRecord.setDescription("Initial Description"); | ||
existingMedicalRecord.setDate(ZonedDateTime.now()); | ||
medicalRecordRepository.save(existingMedicalRecord); | ||
|
||
} | ||
|
||
@When("I edit the medical record for a pet with new issue {string}, new description {string}, and new date {string}") | ||
public void iEditTheMedicalRecordForAPetWithNewIssueNewDescriptionAndNewDate(String issue, String description, String date) throws Throwable { | ||
MedicalRecord existingMedicalRecord = medicalRecordRepository.findAll().iterator().next(); | ||
existingMedicalRecord.setIssue(issue); | ||
existingMedicalRecord.setDescription(description); | ||
existingMedicalRecord.setDate(ZonedDateTime.parse(date)); | ||
|
||
stepDefs.result = stepDefs.mockMvc.perform( | ||
put("/medicalRecords/" + existingMedicalRecord.getId()) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(stepDefs.mapper.writeValueAsString(existingMedicalRecord)) | ||
.characterEncoding(StandardCharsets.UTF_8) | ||
.with(AuthenticationStepDefs.authenticate())) | ||
.andDo(print()); | ||
} | ||
|
||
@When("I edit the medical record for a pet with new issue {string}, new description {string}") | ||
public void iEditTheMedicalRecordForAPetWithNewIssueNewDescription(String issue, String description) throws Throwable { | ||
MedicalRecord existingMedicalRecord = medicalRecordRepository.findAll().iterator().next(); | ||
|
||
existingMedicalRecord.setIssue(issue); | ||
existingMedicalRecord.setDescription(description); | ||
// Keeping the original date | ||
|
||
stepDefs.result = stepDefs.mockMvc.perform( | ||
put("/medicalRecords/" + existingMedicalRecord.getId()) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(stepDefs.mapper.writeValueAsString(existingMedicalRecord)) | ||
.characterEncoding(StandardCharsets.UTF_8) | ||
.with(AuthenticationStepDefs.authenticate())) | ||
.andDo(print()); | ||
} | ||
|
||
@When("I try to edit a medical record for a pet") | ||
public void iTryToEditAMedicalRecordForAPet() throws Exception { | ||
MedicalRecord existingMedicalRecord = medicalRecordRepository.findAll().iterator().next(); | ||
|
||
stepDefs.result = stepDefs.mockMvc.perform( | ||
put("/medicalRecords/" + existingMedicalRecord.getId()) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(stepDefs.mapper.writeValueAsString(existingMedicalRecord)) | ||
.characterEncoding(StandardCharsets.UTF_8) | ||
.with(AuthenticationStepDefs.authenticate())) | ||
.andDo(print()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Feature: Edit Medical Record | ||
In order to keep pet health history up to date | ||
As a shelter volunteer | ||
I want to edit existing medical records in pets' profiles | ||
|
||
Background: | ||
Given a pet exists in the system | ||
And a medical record exists for the pet | ||
Given There is a registered user with username "user" and password "password" and email "[email protected]" | ||
Given There is a registered admin with name "admin" and password "password" and email "[email protected]" | ||
Given There is a registered volunteer with name "volunteer" and password "password" and email "[email protected]" | ||
|
||
|
||
Scenario: Edit an existing medical record as Volunteer | ||
Given I login as "volunteer" with password "password" | ||
When I edit the medical record for a pet with new issue "Allergy Update", new description "Updated seasonal allergy treatment", and new date "2024-03-08T14:00:00Z" | ||
Then The response code is 204 | ||
|
||
Scenario: Edit a medical record with empty issue as Volunteer | ||
Given I login as "volunteer" with password "password" | ||
When I edit the medical record for a pet with new issue "", new description "Revaccination", and new date "2024-03-08T14:00:00Z" | ||
Then The response code is 400 | ||
|
||
Scenario: Edit a medical record with empty description as Volunteer | ||
Given I login as "volunteer" with password "password" | ||
When I edit the medical record for a pet with new issue "Vaccination Update", new description "", and new date "2024-03-08T14:00:00Z" | ||
Then The response code is 400 | ||
|
||
Scenario: Edit a medical record without changing the date as Volunteer | ||
Given I login as "volunteer" with password "password" | ||
When I edit the medical record for a pet with new issue "Injury Update", new description "Healed cut on paw" | ||
Then The response code is 204 | ||
|
||
Scenario: Attempt to edit a medical record as a normal user | ||
Given I login as "user" with password "password" | ||
When I try to edit a medical record for a pet | ||
Then The response code is 403 | ||
And The error message is "Unauthorized access" | ||
|
||
Scenario: Attempt to edit a medical record as an admin | ||
Given I login as "admin" with password "password" | ||
When I try to edit a medical record for a pet | ||
Then The response code is 204 |