use of com.sanctionco.thunder.models.User in project thunder by RohanNagar.
the class UserResourceTest method delete_isSuccessful.
@Test
void delete_isSuccessful() {
when(usersDao.findByEmail(EMAIL.getAddress())).thenReturn(CompletableFuture.completedFuture(USER));
when(usersDao.delete(EMAIL.getAddress())).thenReturn(CompletableFuture.completedFuture(USER));
var asyncResponse = mock(AsyncResponse.class);
var captor = ArgumentCaptor.forClass(Response.class);
resource.deleteUser(asyncResponse, key, "password", EMAIL.getAddress());
verify(asyncResponse, timeout(100).times(1)).resume(captor.capture());
User result = (User) captor.getValue().getEntity();
assertAll("Assert successful delete user", () -> assertEquals(Response.Status.OK, captor.getValue().getStatusInfo()), () -> assertEquals(USER, result));
}
use of com.sanctionco.thunder.models.User in project thunder by RohanNagar.
the class UserResourceTest method put_shouldSucceed.
@Test
void put_shouldSucceed() {
// Set up the user that should already exist in the database
var existingEmail = new Email("existing@test.com", true, "token");
var existingUser = new User(existingEmail, "password", Collections.emptyMap());
// Define the updated user with changed verification info
var updatedUser = new User(new Email(existingEmail.getAddress(), false, "changedToken"), "newPassword", Collections.emptyMap());
// Expect that the existing verification information stays the same even though
// the updated user had different information
var expectedResponse = new User(new Email(updatedUser.getEmail().getAddress(), true, "token"), updatedUser.getPassword(), updatedUser.getProperties());
var userCaptor = ArgumentCaptor.forClass(User.class);
var asyncResponse = mock(AsyncResponse.class);
when(usersDao.findByEmail(existingEmail.getAddress())).thenReturn(CompletableFuture.completedFuture(existingUser));
when(usersDao.update(eq(null), userCaptor.capture())).thenReturn(CompletableFuture.completedFuture(expectedResponse));
resource.updateUser(asyncResponse, key, "password", null, updatedUser);
var responseCaptor = ArgumentCaptor.forClass(Response.class);
verify(asyncResponse, timeout(100).times(1)).resume(responseCaptor.capture());
var result = (User) responseCaptor.getValue().getEntity();
assertAll("Assert successful user update", () -> assertEquals(Response.Status.OK, responseCaptor.getValue().getStatusInfo()), () -> assertEquals(expectedResponse, userCaptor.getValue()), () -> assertEquals(expectedResponse, result));
}
use of com.sanctionco.thunder.models.User in project thunder by RohanNagar.
the class UserResourceTest method delete_nullPasswordWithDisabledHeaderCheckSucceeds.
@Test
void delete_nullPasswordWithDisabledHeaderCheckSucceeds() {
var validator = new RequestValidator(EMAIL_VALIDATOR, propertyValidator, HASH_SERVICE, false);
var resource = new UserResource(usersDao, OPTIONS, validator, HASH_SERVICE, METRICS);
when(usersDao.findByEmail(EMAIL.getAddress())).thenReturn(CompletableFuture.completedFuture(USER));
when(usersDao.delete(EMAIL.getAddress())).thenReturn(CompletableFuture.completedFuture(USER));
var asyncResponse = mock(AsyncResponse.class);
var captor = ArgumentCaptor.forClass(Response.class);
resource.deleteUser(asyncResponse, key, null, EMAIL.getAddress());
verify(asyncResponse, timeout(100).times(1)).resume(captor.capture());
User result = (User) captor.getValue().getEntity();
assertAll("Assert successful delete user", () -> assertEquals(Response.Status.OK, captor.getValue().getStatusInfo()), () -> assertEquals(USER, result));
}
use of com.sanctionco.thunder.models.User in project thunder by RohanNagar.
the class VerificationResourceTest method reset_disabledPasswordHeaderCheckAndNullPasswordSucceeds.
@Test
void reset_disabledPasswordHeaderCheckAndNullPasswordSucceeds() {
var requestValidator = new RequestValidator(EMAIL_VALIDATOR, propertyValidator, hashService, false);
var resource = new VerificationResource(usersDao, OPTIONS, requestValidator, emailService, METRICS);
// Set up the user that should already exist in the database
Email existingEmail = new Email("existing@test.com", true, "token");
User existingUser = new User(existingEmail, "password", Collections.emptyMap());
// Set up expected user object
Email updatedEmail = new Email("existing@test.com", false, null);
User updatedUser = new User(updatedEmail, "password", Collections.emptyMap());
var userCaptor = ArgumentCaptor.forClass(User.class);
when(usersDao.findByEmail(existingEmail.getAddress())).thenReturn(CompletableFuture.completedFuture(existingUser));
when(usersDao.update(eq(null), userCaptor.capture())).thenReturn(CompletableFuture.completedFuture(updatedUser));
var asyncResponse = mock(AsyncResponse.class);
var responseCaptor = ArgumentCaptor.forClass(Response.class);
resource.resetVerified(asyncResponse, key, existingEmail.getAddress(), null);
verify(asyncResponse, timeout(100).times(1)).resume(responseCaptor.capture());
User result = (User) responseCaptor.getValue().getEntity();
assertAll("Assert successful verification status reset", () -> assertEquals(responseCaptor.getValue().getStatusInfo(), Response.Status.OK), () -> assertEquals(updatedUser, userCaptor.getValue()), () -> assertEquals(updatedUser, result));
}
use of com.sanctionco.thunder.models.User in project thunder by RohanNagar.
the class MongoDbUsersDaoTest method testSuccessfulFindByEmail.
@Test
void testSuccessfulFindByEmail() {
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.findByEmail("test@test.com").join();
assertEquals(USER.withTime(CURR_TIME, CURR_TIME), result);
verify(collection, times(1)).find(eq(Filters.eq("_id", "test@test.com")));
}
Aggregations