-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change passwordChange REST & services
- Loading branch information
Showing
9 changed files
with
28 additions
and
130 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
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
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 |
---|---|---|
|
@@ -28,65 +28,6 @@ private String randomToken() { | |
return UUID.randomUUID().toString(); | ||
} | ||
|
||
@Test | ||
void findByUsernameReturnsResultMatchingTheToken() { | ||
final UserAccount user = Generator.generateUserAccountWithPassword(); | ||
transactional(() -> em.persist(user)); | ||
|
||
final String TOKEN = randomToken(); | ||
final PasswordChangeRequest passwordChangeRequest = new PasswordChangeRequest(); | ||
passwordChangeRequest.setToken(TOKEN); | ||
passwordChangeRequest.setUserAccount(user); | ||
passwordChangeRequest.setCreatedAt(Instant.now()); | ||
transactional(() -> em.persist(passwordChangeRequest)); | ||
|
||
final Optional<PasswordChangeRequest> result = sut.findByUsername(user.getUsername()); | ||
assertTrue(result.isPresent()); | ||
assertEquals(TOKEN, result.get().getToken()); | ||
assertEquals(user.getUri(), result.get().getUserAccount().getUri()); | ||
} | ||
|
||
@Test | ||
void findByUsernameReturnsEmptyOptionalWhenNoMatchingRequestIsFound() { | ||
final UserAccount user = Generator.generateUserAccountWithPassword(); | ||
transactional(() -> em.persist(user)); | ||
|
||
final String TOKEN = randomToken(); | ||
final PasswordChangeRequest passwordChangeRequest = new PasswordChangeRequest(); | ||
passwordChangeRequest.setToken(TOKEN); | ||
passwordChangeRequest.setUserAccount(user); | ||
passwordChangeRequest.setCreatedAt(Instant.now()); | ||
transactional(() -> em.persist(passwordChangeRequest)); | ||
|
||
final Optional<PasswordChangeRequest> result = sut.findByUsername("[email protected]"); | ||
assertFalse(result.isPresent()); | ||
} | ||
|
||
@Test | ||
void findByUsernameReturnsSingleResultWhenMultipleArePresent() { | ||
final UserAccount user = Generator.generateUserAccountWithPassword(); | ||
transactional(() -> em.persist(user)); | ||
|
||
final String TOKEN = randomToken(); | ||
final String ANOTHER_TOKEN = randomToken(); | ||
final PasswordChangeRequest passwordChangeRequest = new PasswordChangeRequest(); | ||
final PasswordChangeRequest secondPasswordChangeRequest = new PasswordChangeRequest(); | ||
passwordChangeRequest.setToken(TOKEN); | ||
secondPasswordChangeRequest.setToken(ANOTHER_TOKEN); | ||
passwordChangeRequest.setUserAccount(user); | ||
secondPasswordChangeRequest.setUserAccount(user); | ||
// make the password request the latest | ||
passwordChangeRequest.setCreatedAt(Instant.now().plusSeconds(1)); | ||
secondPasswordChangeRequest.setCreatedAt(Instant.now()); | ||
transactional(() -> em.persist(passwordChangeRequest)); | ||
transactional(() -> em.persist(secondPasswordChangeRequest)); | ||
|
||
final Optional<PasswordChangeRequest> result = sut.findByUsername(user.getUsername()); | ||
assertTrue(result.isPresent()); | ||
assertEquals(TOKEN, result.get().getToken()); | ||
assertEquals(user.getUri(), result.get().getUserAccount().getUri()); | ||
} | ||
|
||
@Test | ||
void findAllByUsernameReturnsAllResults() { | ||
final UserAccount user = Generator.generateUserAccountWithPassword(); | ||
|
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