-
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 branch 'main' into crud-Shelter
- Loading branch information
Showing
8 changed files
with
44 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ class Pet { | |
age: String | ||
description: String | ||
breed: String | ||
|
||
img: String | ||
} | ||
|
||
class Shelter { | ||
|
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,8 +1,12 @@ | ||
package cat.udl.eps.softarch.demo.config; | ||
|
||
import cat.udl.eps.softarch.demo.domain.ShelterVolunteer; | ||
import cat.udl.eps.softarch.demo.domain.User; | ||
import cat.udl.eps.softarch.demo.repository.UserRepository; | ||
import cat.udl.eps.softarch.demo.repository.ShelterVolunteerRepository; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import java.util.Arrays; | ||
|
||
|
@@ -13,9 +17,11 @@ public class DBInitialization { | |
@Value("${spring.profiles.active:}") | ||
private String activeProfiles; | ||
private final UserRepository userRepository; | ||
private final ShelterVolunteerRepository shelterVolunteerRepository; | ||
|
||
public DBInitialization(UserRepository userRepository) { | ||
public DBInitialization(UserRepository userRepository, ShelterVolunteerRepository shelterVolunteerRepository) { | ||
this.userRepository = userRepository; | ||
this.shelterVolunteerRepository = shelterVolunteerRepository; | ||
} | ||
|
||
@PostConstruct | ||
|
@@ -29,6 +35,17 @@ public void initializeDatabase() { | |
user.encodePassword(); | ||
userRepository.save(user); | ||
} | ||
|
||
// Default ShelterVolunteer | ||
if (!shelterVolunteerRepository.existsById("volunteer")) { | ||
ShelterVolunteer volunteer = new ShelterVolunteer(); | ||
volunteer.setEmail("[email protected]"); | ||
volunteer.setId("volunteer"); | ||
volunteer.setPassword(defaultPassword); | ||
volunteer.encodePassword(); | ||
shelterVolunteerRepository.save(volunteer); | ||
} | ||
|
||
if (Arrays.asList(activeProfiles.split(",")).contains("test")) { | ||
// Testing instances | ||
if (!userRepository.existsById("test")) { | ||
|
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
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 |
---|---|---|
|
@@ -5,14 +5,14 @@ Feature: Add Shelter 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 "[email protected]" | ||
And There is a registered user with username "volunteer" and password "password" and email "[email protected]" | ||
|
||
Scenario: Adding a Shelter Certificate as a Shelter Volunteer | ||
Given I can login with username "volunteer" and password "123456789" | ||
Given I can login with username "volunteer" and password "password" | ||
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 | ||
Then The response code is 401 |
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ Feature: Edit 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" | ||
Given There is a registered volunteer with username "volunteer" and password "password" | ||
And There is already a shelter with name "Shelter 1" email "[email protected]" and mobile "999999999" | ||
|
||
Scenario: Edit shelter without being logged in | ||
|
@@ -28,7 +28,7 @@ Feature: Edit Shelter | |
Then The response code is 200 | ||
|
||
Scenario: Edit shelter with volunteer | ||
Given I login as "volunteer" with password "volunteer" | ||
Given I login as "volunteer" with password "password" | ||
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 | ||
|
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 |
---|---|---|
|
@@ -4,28 +4,28 @@ Feature: Kick ShelterVolunteer from Shelter | |
I want to be able to kick a volunteer from my shelter but not able to kick volunteers from other shelters | ||
|
||
Background: | ||
Given There is a registered user with username "user" and password "pass" and email "[email protected]" | ||
Given There is a registered user with username "user" and password "password" and email "[email protected]" | ||
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 is a shelter volunteer with username "volunteer" and password "password" in the shelter "shelter1" | ||
And There is a shelter volunteer with username "volunteer1" and password "password" in the shelter "shelter1" | ||
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" | ||
And There is a shelter volunteer with username "volunteer2" and password "password" in the shelter "shelter2" | ||
|
||
Scenario: Kick volunteer from shelter | ||
Given I can login with username "volunteer" and password "pass" | ||
Given I can login with username "volunteer" and password "password" | ||
When I kick user "volunteer1" from shelter "shelter" | ||
Then The response code is 200 | ||
And I cannot login with username "volunteer1" and password "pass" | ||
And I cannot login with username "volunteer1" and password "password" | ||
|
||
Scenario: Kick volunteer from shelter as user | ||
And I can login with username "user" and password "pass" | ||
And I can login with username "user" and password "password" | ||
When I kick user "volunteer1" from shelter "shelter" | ||
Then The response code is 403 | ||
And I can login with username "volunteer1" and password "pass" | ||
And I can login with username "volunteer1" and password "password" | ||
|
||
Scenario: Kick volunteer from shelter as volunteer in another shelter | ||
Given I can login with username "volunteer" and password "pass" | ||
Given I can login with username "volunteer" and password "password" | ||
When I kick user "volunteer2" from shelter "shelter" | ||
Then The response code is 412 | ||
And I can login with username "volunteer2" and password "pass" | ||
And I can login with username "volunteer2" and password "password" | ||
|