mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-17 02:31:14 +01:00
Add unit tests for user update
This commit is contained in:
@@ -73,6 +73,7 @@ public class UserRootResourceTest {
|
||||
when(userManager.getPage(any(), eq(0), eq(10))).thenReturn(new PageResult<>(singletonList(dummyUser), 1));
|
||||
when(userManager.get("Neo")).thenReturn(dummyUser);
|
||||
doNothing().when(userManager).create(userCaptor.capture());
|
||||
doNothing().when(userManager).modify(userCaptor.capture());
|
||||
|
||||
UserCollectionToDtoMapper userCollectionToDtoMapper = new UserCollectionToDtoMapper(userToDtoMapper, uriInfoStore);
|
||||
UserCollectionResource userCollectionResource = new UserCollectionResource(userManager, dtoToUserMapper, userToDtoMapper,
|
||||
@@ -134,6 +135,26 @@ public class UserRootResourceTest {
|
||||
assertEquals("encrypted123", createdUser.getPassword());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldUpdateChangedUserWithEncryptedPassword() throws URISyntaxException, IOException {
|
||||
URL url = Resources.getResource("sonia/scm/api/v2/user-test-update.json");
|
||||
byte[] userJson = Resources.toByteArray(url);
|
||||
|
||||
MockHttpRequest request = MockHttpRequest
|
||||
.put("/" + UserRootResource.USERS_PATH_V2 + "Neo")
|
||||
.contentType(VndMediaType.USER)
|
||||
.content(userJson);
|
||||
MockHttpResponse response = new MockHttpResponse();
|
||||
when(passwordService.encryptPassword("pwd123")).thenReturn("encrypted123");
|
||||
|
||||
dispatcher.invoke(request, response);
|
||||
|
||||
assertEquals(204, response.getStatus());
|
||||
User updatedUser = userCaptor.getValue();
|
||||
assertNotNull(updatedUser);
|
||||
assertEquals("encrypted123", updatedUser.getPassword());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailForMissingContent() throws URISyntaxException {
|
||||
MockHttpRequest request = MockHttpRequest
|
||||
|
||||
Reference in New Issue
Block a user