Added check for admin user and test it

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
Marcin Woźniak 2020-12-23 13:48:26 +01:00
parent 165dee5bd2
commit da46582fc0
Signed by: y0rune
GPG Key ID: F204C385F57EB348
3 changed files with 26 additions and 0 deletions

View File

@ -85,4 +85,8 @@ public class UserService {
return this.repo.getByRefreshToken(refreshToken); return this.repo.getByRefreshToken(refreshToken);
} }
public boolean adminExists(){
return this.repo.getAllByRole(UserRoles.ADMIN).size() > 0;
}
} }

View File

@ -100,4 +100,21 @@ public class UserServiceTest {
assertTrue(user.getName() != "Tom"); assertTrue(user.getName() != "Tom");
} }
@Test
public void shouldReturnAdminExists() {
final String email = "shouldReturnAdminExists@UserService.test";
this.userService.save(new User("AdminTom", "Smieszny", email, UserRoles.ADMIN));
assertTrue(userService.adminExists());
}
@Test
/**
* In future can fail the test due to create a admin user in the another tests.
*/
public void shouldReturnNotAdminExists() {
final String email = "shouldReturnNotAdminExists@UserService.test";
this.userService.save(new User("StudentTom", "Smieszny", email, UserRoles.STUDENT));
assertTrue(userService.adminExists() == false);
}
} }

View File

@ -63,4 +63,9 @@ public class ConfigController {
} }
} }
public ResponseEntity<String> initAdmin(@RequestParam("ticket") String ticket){
return null;
}
} }