Skip to content

Commit

Permalink
admin registered posted to mvc
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianJitaru29 committed Mar 21, 2024
1 parent d25590d commit b94a6f8
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,21 @@ public class CreateShelterStepDefs {
private AdminRepository adminRepository;

@Given("^There is a registered admin with name \"([^\"]*)\" and password \"([^\"]*)\" and email \"([^\"]*)\"$")
public void thereIsARegisteredAdminWithNameAndPasswordAndEmail(String username, String password, String email) {
public void thereIsARegisteredAdminWithNameAndPasswordAndEmail(String username, String password, String email) throws Throwable {
if (!userRepository.existsById(username)) {
Admin user = new Admin();
user.setEmail(email);
user.setId(username);
user.setPassword(password);
user.encodePassword();
adminRepository.save(user);
userRepository.save(user);
stepDefs.result = stepDefs.mockMvc.perform(
post("/admins")
.contentType(MediaType.APPLICATION_JSON)
.content(stepDefs.mapper.writeValueAsString(user))
.characterEncoding(StandardCharsets.UTF_8)
.with(AuthenticationStepDefs.authenticate()))
.andDo(print());
}
}

Expand Down

0 comments on commit b94a6f8

Please sign in to comment.