use of com.sanctionco.thunder.models.User in project thunder by RohanNagar.
the class ThunderClientFakeTest method ensureFakeClientPersists.
@Test
void ensureFakeClientPersists() {
var client = ThunderClient.fake();
var user = new User(Email.unverified(ADDRESS), PASSWORD, Collections.emptyMap());
assertEquals(user, client.postUser(user).join());
assertEquals(user, client.getUser(ADDRESS, PASSWORD).join());
var userWithNewProperties = new User(new Email(user.getEmail().getAddress(), user.getEmail().isVerified(), user.getEmail().getVerificationToken()), user.getPassword(), Collections.singletonMap("prop1", "val1"));
assertEquals(userWithNewProperties, client.updateUser(userWithNewProperties, PASSWORD).join());
assertEquals(userWithNewProperties, client.getUser(ADDRESS, PASSWORD).join());
// Assert correct initial verification state
assertNull(client.getUser(ADDRESS, PASSWORD).join().getEmail().getVerificationToken());
assertFalse(client.getUser(ADDRESS, PASSWORD).join().getEmail().isVerified());
// Send email to set token
assertNotNull(client.sendVerificationEmail(ADDRESS, PASSWORD).join().getEmail().getVerificationToken());
var userWithToken = client.getUser(ADDRESS, PASSWORD).join();
assertNotNull(userWithToken.getEmail().getVerificationToken());
assertFalse(userWithToken.getEmail().isVerified());
// Verify user
assertTrue(client.verifyUser(ADDRESS, userWithToken.getEmail().getVerificationToken()).join().getEmail().isVerified());
var verifiedUser = client.getUser(ADDRESS, PASSWORD).join();
assertEquals(userWithToken.getEmail().getVerificationToken(), verifiedUser.getEmail().getVerificationToken());
assertTrue(verifiedUser.getEmail().isVerified());
// Reset verification
assertFalse(client.resetVerificationStatus(ADDRESS, PASSWORD).join().getEmail().isVerified());
var resetUser = client.getUser(ADDRESS, PASSWORD).join();
assertNull(resetUser.getEmail().getVerificationToken());
assertFalse(resetUser.getEmail().isVerified());
assertEquals(resetUser, client.deleteUser(ADDRESS, PASSWORD).join());
assertFailure(() -> client.getUser(ADDRESS, PASSWORD).get(), 404);
}
Aggregations