-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature - Edit shelter #80
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ac21fee
Created .feature for EditShelter feature
SebastianJitaru29 9eb9453
Merge branch 'main' into Feature-Edit-Shelter
SebastianJitaru29 7f1aabc
Added step defs
SebastianJitaru29 704c586
Merge branch 'main' into Feature-Edit-Shelter
SebastianJitaru29 7003e62
Merge branch 'main' into Feature-Edit-Shelter
SebastianJitaru29 4a58258
New Scenarios implemeted
SebastianJitaru29 037d2aa
Added checking if updated shelter has new name
SebastianJitaru29 45be26c
Solving Pull request maven errors
SebastianJitaru29 8cd9277
Troubleshoot new error json string can't be null or empty
SebastianJitaru29 2609391
Troubleshoot new error json string can't be null or empty 2
SebastianJitaru29 edf7016
Troubleshoot new error json string can't be null or empty 3
SebastianJitaru29 bde078b
Testing where the error is
SebastianJitaru29 abcbd25
Testing where the error is
SebastianJitaru29 610e6be
Util search key function implemented
SebastianJitaru29 f8021a9
Util search key function implemented
SebastianJitaru29 4c01610
using jsonobject
SebastianJitaru29 f9773cd
Merge remote-tracking branch 'origin/main' into Feature-Edit-Shelter
rogargon 20b0b9e
Add missing feature title
rogargon 58e1db0
Fix merge conflicts
rogargon a9e17e0
Fix web security issue blocking all HTTP methods for shelters
rogargon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
87 changes: 83 additions & 4 deletions
87
src/test/java/cat/udl/eps/softarch/demo/steps/EditShelterStepDefs.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 |
---|---|---|
@@ -1,34 +1,113 @@ | ||
package cat.udl.eps.softarch.demo.steps; | ||
|
||
import cat.udl.eps.softarch.demo.domain.Shelter; | ||
import cat.udl.eps.softarch.demo.domain.User; | ||
import cat.udl.eps.softarch.demo.domain.ShelterVolunteer; | ||
import cat.udl.eps.softarch.demo.domain.Admin; | ||
|
||
|
||
import cat.udl.eps.softarch.demo.repository.AdminRepository; | ||
import cat.udl.eps.softarch.demo.repository.ShelterRepository; | ||
import cat.udl.eps.softarch.demo.repository.ShelterVolunteerRepository; | ||
import cat.udl.eps.softarch.demo.repository.UserRepository; | ||
|
||
import io.cucumber.java.en.And; | ||
import io.cucumber.java.en.Given; | ||
import io.cucumber.java.en.When; | ||
import org.json.JSONObject; | ||
import org.junit.Assert; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
|
||
import static com.jayway.jsonpath.internal.path.PathCompiler.fail; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
|
||
import org.json.JSONObject; | ||
|
||
public class EditShelterStepDefs { | ||
|
||
@Autowired | ||
ShelterRepository shelterRepository; | ||
User user = new User(); | ||
@Autowired | ||
UserRepository userRepository; | ||
@And("^There a shelter with name \"([^\"]*)\" email \"([^\"]*)\" and mobile \"([^\"]*)\"$") | ||
public void thereAShelterWithNameEmailAndMobile(String name, String email, String mobile) { | ||
@Autowired | ||
AdminRepository adminRepository; | ||
@Autowired | ||
ShelterVolunteerRepository shelterVolunteerRepository; | ||
@Autowired | ||
StepDefs stepDefs; | ||
@And("^There is already a shelter with name \"([^\"]*)\" email \"([^\"]*)\" and mobile \"([^\"]*)\"$") | ||
public void thereIsAlreadyAShelterWithNameEmailAndMobile(String name, String email, String mobile) { | ||
Shelter shelter = new Shelter(); | ||
shelter.setName(name); | ||
shelter.setEmail(email); | ||
shelter.setMobile(mobile); | ||
shelterRepository.save(shelter); | ||
} | ||
|
||
@When("^I update the shelter with name \"([^\"]*)\" to name \"([^\"]*)\" email \"([^\"]*)\" and mobile \"([^\"]*)\"$") | ||
public void iUpdateTheShelterWithNameToNameEmailAndMobile(String prevName, String newName, String email, String mobile) | ||
throws Throwable { | ||
Shelter shelter = shelterRepository.findByName(prevName).get(0); | ||
if (shelter != null) { | ||
shelter = shelterRepository.findByName(prevName).get(0); | ||
} | ||
stepDefs.result = stepDefs.mockMvc.perform(patch(shelter.getUri()) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(new JSONObject().put("name", newName) | ||
.put("email", email) | ||
.put("mobile", mobile).toString()) | ||
.characterEncoding(StandardCharsets.UTF_8) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.with(AuthenticationStepDefs.authenticate())) | ||
.andDo(print()); | ||
} | ||
|
||
@Given("^There is a registered volunteer with username \"([^\"]*)\" and password \"([^\"]*)\"$") | ||
public void thereIsARegisteredVolunteerWithUsernameAndPasswordAndEmail(String name, String mobile) { | ||
if (!shelterVolunteerRepository.existsById(name)) { | ||
ShelterVolunteer volunteer = new ShelterVolunteer(); | ||
volunteer.setEmail("[email protected]"); | ||
volunteer.setId(name); | ||
volunteer.setPassword(mobile); | ||
volunteer.encodePassword(); | ||
shelterVolunteerRepository.save(volunteer); | ||
} | ||
} | ||
|
||
@And("^I get the shelter with name \"([^\"]*)\"") | ||
public void iGetTheShelterWithName(String newname) throws Exception { | ||
List<Shelter> shelters = shelterRepository.findByName(newname); | ||
Shelter shelter = shelters.get(0); | ||
stepDefs.result = stepDefs.mockMvc.perform(get("/shelters/" + shelter.getId()) | ||
.accept(MediaType.APPLICATION_JSON)).andDo(print()); | ||
JSONObject jsonObject = new JSONObject(stepDefs.result.andReturn().getResponse().getContentAsString()); | ||
jsonObject.getString("name"); | ||
try { | ||
String actualName = jsonObject.getString("name"); | ||
Assert.assertEquals(newname, actualName); | ||
} catch (Exception e) { | ||
fail("Key not found"); | ||
} | ||
} | ||
|
||
|
||
@Given("There is a registered already admin with username \"([^\"]*)\" and password \"([^\"]*)\" and email \"([^\"]*)\"$") | ||
public void thereIsARegisteredAlreadyAdminWithUsernameAndPasswordAndEmail(String adminname, String adminPasswd, String adminEmail) { | ||
if (!adminRepository.existsById(adminname)) { | ||
Admin user = new Admin(); | ||
user.setEmail(adminEmail); | ||
user.setId(adminname); | ||
user.setPassword(adminPasswd); | ||
user.encodePassword(); | ||
adminRepository.save(user); | ||
|
||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Feature: | ||
Feature: Delete Pet | ||
in order to use the app | ||
As a Shelter Volunteer | ||
I must be able to delete a Pet | ||
|
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,53 @@ | ||
Feature: Edit Shelter | ||
In order to update shelter information | ||
As a shelter manager | ||
I want to edit a shelter | ||
|
||
Background: | ||
Given There is a registered user with username "user" and password "existing" and email "[email protected]" | ||
Given There is a registered already admin with username "admin" and password "admin" and email "[email protected]" | ||
Given There is a registered volunteer with username "volunteer" and password "volunteer" | ||
And There is already a shelter with name "Shelter 1" email "[email protected]" and mobile "999999999" | ||
|
||
Scenario: Edit shelter without being logged in | ||
Given I'm not logged in | ||
When I update the shelter with name "Shelter 1" to name "Another Shelter" email "[email protected]" and mobile "123123123" | ||
Then The response code is 401 | ||
And The error message is "Unauthorized" | ||
|
||
Scenario: Edit shelter with user | ||
Given I login as "client" with password "existing" | ||
When I update the shelter with name "Shelter 1" to name "Another Shelter" email "[email protected]" and mobile "123123123" | ||
Then The response code is 401 | ||
And The error message is "Unauthorized" | ||
|
||
Scenario: Edit shelter with admin | ||
Given I login as "admin" with password "admin" | ||
When I update the shelter with name "Shelter 1" to name "Another Shelter" email "[email protected]" and mobile "123123123" | ||
And I get the shelter with name "Another Shelter" | ||
Then The response code is 200 | ||
|
||
Scenario: Edit shelter with volunteer | ||
Given I login as "volunteer" with password "volunteer" | ||
When I update the shelter with name "Shelter 1" to name "Another Shelter" email "[email protected]" and mobile "123123123" | ||
And I get the shelter with name "Another Shelter" | ||
Then The response code is 200 | ||
|
||
Scenario: Edit shelter with missing new name | ||
Given I login as "admin" with password "admin" | ||
When I update the shelter with name "Shelter 1" to name "" email "[email protected]" and mobile "123123123" | ||
Then The response code is 400 | ||
And The error message is "must not be blank" | ||
|
||
Scenario: Edit shelter with missing new email | ||
Given I login as "admin" with password "admin" | ||
When I update the shelter with name "Shelter 1" to name "Another Shelter" email "" and mobile "123123123" | ||
Then The response code is 400 | ||
And The error message is "must not be blank" | ||
|
||
Scenario: Edit shelter with missing new mobile | ||
Given I login as "admin" with password "admin" | ||
When I update the shelter with name "Shelter 1" to name "Another Shelter" email "[email protected]" and mobile "" | ||
Then The response code is 400 | ||
And The error message is "must not be blank" | ||
|
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 |
---|---|---|
|
@@ -5,10 +5,10 @@ Feature: Kick ShelterVolunteer from Shelter | |
|
||
Background: | ||
Given There is a registered user with username "user" and password "pass" and email "[email protected]" | ||
And There a shelter with name "shelter1" email "[email protected]" and mobile "12345678" | ||
And There is already a shelter with name "shelter1" email "[email protected]" and mobile "12345678" | ||
And There is a shelter volunteer with username "volunteer" and password "pass" in the shelter "shelter1" | ||
And There is a shelter volunteer with username "volunteer1" and password "pass" in the shelter "shelter1" | ||
And There a shelter with name "shelter2" email "[email protected]" and mobile "12345679" | ||
And There is already a shelter with name "shelter2" email "[email protected]" and mobile "12345679" | ||
And There is a shelter volunteer with username "volunteer2" and password "pass" in the shelter "shelter2" | ||
|
||
Scenario: Kick volunteer from shelter | ||
|
@@ -17,18 +17,13 @@ Feature: Kick ShelterVolunteer from Shelter | |
Then The response code is 200 | ||
And I cannot login with username "volunteer1" and password "pass" | ||
|
||
|
||
|
||
Scenario: Kick volunteer from shelter as user | ||
|
||
And I can login with username "user" and password "pass" | ||
When I kick user "volunteer1" from shelter "shelter" | ||
Then The response code is 403 | ||
And I can login with username "volunteer1" and password "pass" | ||
|
||
|
||
Scenario: Kick volunteer from shelter as volunteer in another shelter | ||
|
||
Given I can login with username "volunteer" and password "pass" | ||
When I kick user "volunteer2" from shelter "shelter" | ||
Then The response code is 412 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also check that the update has been materialised in the backend. For that you can add an additional step where a GET is performed using the shelter ID and the you check in the returned JSON, using JSONPath, that the updated name is returned now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pushed the implementation of the specified step and changes in the .feature file