Skip to content

Commit

Permalink
Merge pull request #31 from UdL-EPS-SoftArch/initialize-admin
Browse files Browse the repository at this point in the history
adding root for front test with default pw
  • Loading branch information
rogargon authored Nov 28, 2023
2 parents 3f604b8 + ac60ef2 commit 1026561
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cat.udl.eps.softarch.myroutes.config;
import cat.udl.eps.softarch.myroutes.domain.Admin;
import cat.udl.eps.softarch.myroutes.domain.User;
import cat.udl.eps.softarch.myroutes.repository.UserRepository;
import cat.udl.eps.softarch.myroutes.repository.AdminRepository;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import jakarta.annotation.PostConstruct;
Expand All @@ -13,9 +15,11 @@ public class DBInitialization {
@Value("${spring.profiles.active:}")
private String activeProfiles;
private final UserRepository userRepository;
private final AdminRepository adminRepository;

public DBInitialization(UserRepository userRepository) {
public DBInitialization(UserRepository userRepository, AdminRepository adminRepository) {
this.userRepository = userRepository;
this.adminRepository = adminRepository;
}

@PostConstruct
Expand All @@ -29,6 +33,14 @@ public void initializeDatabase() {
user.encodePassword();
userRepository.save(user);
}
if (!adminRepository.existsById("root")) {
Admin admin = new Admin();
admin.setEmail("[email protected]");
admin.setId("admin");
admin.setPassword(defaultPassword);
admin.encodePassword();
adminRepository.save(admin);
}
if (Arrays.asList(activeProfiles.split(",")).contains("test")) {
// Testing instances
if (!userRepository.existsById("test")) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/features/CreateRoute.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Feature: Create Route
Given I login as "admin" with password "password"
And I don't have any route
When I create a route with a title "testRoute", description "route description", type "Running" and a creationDate "2023-10-25T17:27:00Z"
Then The response code is 401
Then The response code is 403

Scenario: Create an empty route while logged in
Given I login as "user" with password "password"
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/features/UpdateRoute.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Feature: Update Route
Scenario: Update a route while logged in as admin
Given I login as "admin" with password "password"
When I update a route with a title "testRoute", description "route description", type "Running" and a creationDate "2023-10-25T17:27:00Z"
Then The response code is 401
Then The response code is 403

Scenario: Update a route while logged in as reviewer
Given I login as "reviewer" with password "password"
Expand Down

0 comments on commit 1026561

Please sign in to comment.