Search in sources :

Example 51 with User

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);
}
Also used : User(com.sanctionco.thunder.models.User) Email(com.sanctionco.thunder.models.Email) Test(org.junit.jupiter.api.Test)

Aggregations

User (com.sanctionco.thunder.models.User)51 Test (org.junit.jupiter.api.Test)41 Email (com.sanctionco.thunder.models.Email)26 RequestValidator (com.sanctionco.thunder.validation.RequestValidator)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 UsersDao (com.sanctionco.thunder.dao.UsersDao)8 Objects (java.util.Objects)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 UUID (java.util.UUID)7 BsonDocument (org.bson.BsonDocument)6 Document (org.bson.Document)6 Metered (com.codahale.metrics.annotation.Metered)5 Counter (com.codahale.metrics.Counter)4 MetricRegistry (com.codahale.metrics.MetricRegistry)4 ThunderException (com.sanctionco.thunder.ThunderException)4 SwaggerAnnotations (com.sanctionco.thunder.openapi.SwaggerAnnotations)4 MetricNameUtil (com.sanctionco.thunder.util.MetricNameUtil)4 RequestValidationException (com.sanctionco.thunder.validation.RequestValidationException)4 POST (javax.ws.rs.POST)4