-
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 #78 from UdL-EPS-SoftArch/feature-Delete-Shelter
Feature-Delete-Shelter
- Loading branch information
Showing
5 changed files
with
138 additions
and
1 deletion.
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
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
49 changes: 49 additions & 0 deletions
49
src/test/java/cat/udl/eps/softarch/demo/steps/DeleteShelterStepDefs.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,49 @@ | ||
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.Given; | ||
import io.cucumber.java.en.When; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
|
||
import java.util.List; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
|
||
public class DeleteShelterStepDefs { | ||
|
||
@Autowired | ||
private StepDefs stepDefs; | ||
|
||
@Autowired | ||
private ShelterRepository shelterRepository; | ||
|
||
|
||
@Given("There is a created shelter with name {string}, email {string} and phone {string}") | ||
public void thereIsACreatedShelterWithNameEmailAndPhone(String name, String email, String phone) { | ||
if (shelterRepository.findByName(name).isEmpty()) { | ||
Shelter shelter = new Shelter(); | ||
shelter.setName(name); | ||
shelter.setEmail(email); | ||
shelter.setMobile(phone); | ||
shelter.setLocatedAt(null); | ||
|
||
shelterRepository.save(shelter); | ||
} | ||
} | ||
|
||
@When("I try to delete Shelter with name {string}") | ||
public void iTryToDeleteShelterWithName(String name) throws Exception { | ||
List<Shelter> shelterList = shelterRepository.findByName(name); | ||
|
||
stepDefs.result = stepDefs.mockMvc.perform( | ||
delete("/shelters/{id}", shelterList.isEmpty() ? "0" : shelterList.get(0).getId()) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.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
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,47 @@ | ||
Feature: Delete Shelter | ||
In order to use the app | ||
only admins must be able to delete Shelters | ||
|
||
Background: | ||
Given There is a created shelter with name "name", email "[email protected]" and phone "123123123" | ||
|
||
Scenario: Delete a Shelter not logged in | ||
Given I'm not logged in | ||
When I try to delete Shelter with name "name" | ||
Then The response code is 401 | ||
|
||
Scenario: Delete a Shelter as user | ||
Given There is a registered user with username "user" and password "password" and email "[email protected]" | ||
Given I login as "user" with password "password" | ||
When I try to delete Shelter with name "name" | ||
Then The response code is 403 | ||
|
||
Scenario: Delete a Shelter as ShelterVolunteer | ||
Given There is a registered shelter volunteer with username "ShelterVolunteer" and password "password" and email "[email protected]" | ||
Given I login as "ShelterVolunteer" with password "password" | ||
When I try to delete Shelter with name "name" | ||
Then The response code is 403 | ||
|
||
Scenario: Delete a Shelter as admin | ||
Given There is a registered admin with username "admin" and password "password" and email "[email protected]" | ||
Given I login as "admin" with password "password" | ||
When I try to delete Shelter with name "name" | ||
Then The response code is 200 | ||
|
||
Scenario: Delete a Shelter that does not exist as user | ||
Given There is a registered user with username "user" and password "password" and email "[email protected]" | ||
Given I login as "user" with password "password" | ||
When I try to delete Shelter with name "name" | ||
Then The response code is 403 | ||
|
||
Scenario: Delete a Shelter that does not exist as ShelterVolunteer | ||
Given There is a registered shelter volunteer with username "ShelterVolunteer" and password "password" and email "[email protected]" | ||
Given I login as "ShelterVolunteer" with password "password" | ||
When I try to delete Shelter with name "name" | ||
Then The response code is 403 | ||
|
||
Scenario: Delete a Shelter that does not exist as admin | ||
Given There is a registered admin with username "admin" and password "password" and email "[email protected]" | ||
Given I login as "admin" with password "password" | ||
When I try to delete Shelter with name "unregistered" | ||
Then The response code is 404 |