use of com.sanctionco.thunder.models.User in project thunder by RohanNagar.
the class RequestValidatorTest method testValidatePasswordAndEmailDisabledHeaderCheck.
/* Disable header check */
@Test
void testValidatePasswordAndEmailDisabledHeaderCheck() {
var propertyValidator = mock(PropertyValidator.class);
var validator = new RequestValidator(EMAIL_VALIDATOR, propertyValidator, HASH_SERVICE, false);
when(propertyValidator.isValidPropertiesMap(anyMap())).thenReturn(true);
Email email = new Email("test@test.com", false, "token");
User user = new User(email, "password");
assertDoesNotThrow(() -> validator.validate(null, "test@test.com", false));
assertDoesNotThrow(() -> validator.validate("", "test@test.com", false));
assertDoesNotThrow(() -> validator.validate(null, "test@test.com", user));
assertDoesNotThrow(() -> validator.validate("", "test@test.com", user));
}
use of com.sanctionco.thunder.models.User in project thunder by RohanNagar.
the class MongoDbUsersDaoTest method testSuccessfulEmailUpdate.
@Test
void testSuccessfulEmailUpdate() {
MongoCollection<Document> collection = mock(MongoCollection.class);
FindIterable<Document> findIterableNew = mock(FindIterable.class);
when(findIterableNew.first()).thenReturn(null);
doReturn(findIterableNew).when(collection).find(eq(Filters.eq("_id", USER.getEmail().getAddress())));
FindIterable<Document> findIterableExisting = mock(FindIterable.class);
when(findIterableExisting.first()).thenReturn(DOCUMENT);
doReturn(findIterableExisting).when(collection).find(eq(Filters.eq("_id", "existingEmail")));
MongoDbUsersDao usersDao = new MongoDbUsersDao(collection, MAPPER);
User result = usersDao.update("existingEmail", USER).join();
// The creation time and update time will have been reset since an email update
// triggers a delete and insert
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)).find(eq(Filters.eq("_id", "existingEmail")));
verify(collection, times(1)).find(eq(Filters.eq("_id", "test@test.com")));
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")));
verify(collection, times(1)).deleteOne(eq(Filters.eq("_id", "existingEmail")));
}
use of com.sanctionco.thunder.models.User in project thunder by RohanNagar.
the class MongoDbUsersDaoTest method testSuccessfulUpdate.
@Test
void testSuccessfulUpdate() {
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(null, 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(any(Bson.class));
verify(collection, times(1)).updateOne(argThat((Bson bson) -> {
BsonDocument doc = bson.toBsonDocument(BsonDocument.class, MongoClientSettings.getDefaultCodecRegistry());
return doc.containsKey("version");
}), any(Bson.class));
}
use of com.sanctionco.thunder.models.User in project thunder by RohanNagar.
the class MongoDbUsersDaoTest method testSuccessfulDelete.
@Test
void testSuccessfulDelete() {
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.delete("test@test.com").join();
assertEquals(USER.withTime(CURR_TIME, CURR_TIME), result);
verify(collection, times(1)).find(eq(Filters.eq("_id", "test@test.com")));
verify(collection, times(1)).deleteOne(eq(Filters.eq("_id", "test@test.com")));
}
use of com.sanctionco.thunder.models.User in project thunder by RohanNagar.
the class ThunderClientTest method testSendVerificationEmail.
@Test
void testSendVerificationEmail() throws Exception {
User response = client.sendVerificationEmail("email", password).get();
assertEquals(user.getEmail(), response.getEmail());
}
Aggregations