use of com.sanctionco.thunder.models.User in project thunder by RohanNagar.
the class MongoDbUsersDaoTest method testSuccessfulInsert.
@Test
void testSuccessfulInsert() {
MongoCollection<Document> collection = mock(MongoCollection.class);
MongoDbUsersDao usersDao = new MongoDbUsersDao(collection, MAPPER);
User result = usersDao.insert(USER).join();
// Insert will set the creation and update time
long creationTime = (Long) result.getProperties().get("creationTime");
long updateTime = (Long) result.getProperties().get("lastUpdateTime");
assertAll("The creation and update time are correct", () -> assertTrue(creationTime > CURR_TIME), () -> assertTrue(updateTime > CURR_TIME), () -> assertEquals(creationTime, updateTime));
assertEquals(USER.withTime(creationTime, updateTime), result);
verify(collection, times(1)).insertOne(argThat((Document doc) -> doc.containsKey("_id") && doc.containsKey("id") && doc.containsKey("version") && doc.containsKey("creation_time") && doc.containsKey("update_time") && doc.containsKey("document")));
}
use of com.sanctionco.thunder.models.User in project thunder by RohanNagar.
the class MongoDbUsersDaoTest method testSameExistingEmail.
@Test
void testSameExistingEmail() {
MongoCollection<Document> collection = mock(MongoCollection.class);
FindIterable<Document> findIterable = mock(FindIterable.class);
when(findIterable.first()).thenReturn(DOCUMENT);
doReturn(findIterable).when(collection).find(any(Bson.class));
MongoDbUsersDao usersDao = new MongoDbUsersDao(collection, MAPPER);
User result = usersDao.update("test@test.com", USER).join();
// Update will set the update time
long creationTime = (Long) result.getProperties().get("creationTime");
long updateTime = (Long) result.getProperties().get("lastUpdateTime");
assertAll("The creation and update time are correct", () -> assertEquals(CURR_TIME, creationTime), () -> assertTrue(updateTime > CURR_TIME));
assertEquals(USER.withTime(creationTime, updateTime), result);
verify(collection, times(1)).find(eq(Filters.eq("_id", "test@test.com")));
verify(collection, times(1)).updateOne(argThat((Bson bson) -> {
BsonDocument doc = bson.toBsonDocument(BsonDocument.class, MongoClientSettings.getDefaultCodecRegistry());
return doc.containsKey("version");
}), any(Bson.class));
verify(collection, never()).deleteOne(any());
}
use of com.sanctionco.thunder.models.User in project thunder by RohanNagar.
the class RequestValidatorTest method testValidateUserNullEmailAddress.
@Test
void testValidateUserNullEmailAddress() {
Email email = new Email(null, false, "token");
User user = new User(email, "password");
RequestValidationException e = assertThrows(RequestValidationException.class, () -> validator.validate(user));
assertEquals("Invalid email address format. Please try again.", e.getMessage());
assertEquals(RequestValidationException.Error.INVALID_PARAMETERS, e.getError());
}
use of com.sanctionco.thunder.models.User in project thunder by RohanNagar.
the class ThunderClientFake method sendVerificationEmail.
@Override
public CompletableFuture<User> sendVerificationEmail(String email, String password) {
// This does not actually send an email, but it does update the verification token of the user.
var user = inMemoryStore.get(email);
if (user == null) {
return fail(404);
}
if (requirePasswordHeader && !user.getPassword().equals(password)) {
return fail(401);
}
var updated = new User(new Email(user.getEmail().getAddress(), user.getEmail().isVerified(), UUID.randomUUID().toString()), user.getPassword(), user.getProperties());
inMemoryStore.put(email, updated);
return CompletableFuture.completedFuture(updated);
}
use of com.sanctionco.thunder.models.User in project thunder by RohanNagar.
the class ThunderClientTest method testUpdateUser.
@Test
void testUpdateUser() throws Exception {
User response = client.updateUser(user, "email", password).get();
assertEquals(user.getEmail(), response.getEmail());
}
Aggregations