diff options
author | Vitaly Takmazov | 2019-08-21 11:09:54 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2019-08-21 11:09:54 +0300 |
commit | b10719e4c69b489830001c9707f6e2eba265abad (patch) | |
tree | 29c14701fb43a3380cb71a07f48efa86eccfe0e9 /src/test/java/com/juick/server/tests | |
parent | d9d481d824f920f797cff4d9ca92c8cd9b895389 (diff) |
Settings API
Diffstat (limited to 'src/test/java/com/juick/server/tests')
-rw-r--r-- | src/test/java/com/juick/server/tests/ServerTests.java | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java index 688e6148..e113c44a 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -34,6 +34,7 @@ import com.juick.model.CommandResult; import com.juick.model.PrivateChats; import com.juick.model.TagStats; import com.juick.server.*; +import com.juick.server.api.Users; import com.juick.server.api.activity.Profile; import com.juick.server.api.activity.model.Context; import com.juick.server.api.activity.model.activities.*; @@ -254,6 +255,9 @@ public class ServerTests { @Inject private ApplicationEventPublisher applicationEventPublisher; + @Inject + private Users usersController; + private static User ugnich, freefd, juick; static String ugnichName, ugnichPassword, freefdName, freefdPassword, juickName, juickPassword; URI emptyUri = URI.create(StringUtils.EMPTY); @@ -1936,7 +1940,7 @@ public class ServerTests { assertThat(userService.getUserByName("ugnich").isVerified(), is(true)); } @Test - public void avatarUploadOverApi() throws Exception { + public void changeProfileOverApi() throws Exception { ClassPathResource defaultAvatar = new ClassPathResource("static/av-96.png"); String hash = DigestUtils.md5DigestAsHex(IOUtils.toByteArray(defaultAvatar.getInputStream())); assertThat(webApp.getAvatarUrl(userService.getUserByName(freefdName)), is(String.format("http://localhost:8080/av-96-%s.png", hash))); @@ -1950,7 +1954,38 @@ public class ServerTests { String newHash = DigestUtils.md5DigestAsHex(newAvatarData); URI newUri = Paths.get(imgDir, "ao", String.format("%d.png", freefd.getUid())).toUri(); assertThat(DigestUtils.md5DigestAsHex(IOUtils.toByteArray(newUri)), is(newHash)); + mockMvc.perform(post("/api/me") + .with(httpBasic(ugnichName, ugnichPassword)) + .param("password", "newPassword")) + .andExpect(status().isOk()); + mockMvc.perform(get("/api/me") + .with(httpBasic(ugnichName, ugnichPassword))) + .andExpect(status().isUnauthorized()); + mockMvc.perform(post("/api/me") + .with(httpBasic(ugnichName, "newPassword")) + .param("password", ugnichPassword)) + .andExpect(status().isOk()); + mockMvc.perform(get("/api/me") + .with(httpBasic(ugnichName, ugnichPassword))) + .andExpect(status().isOk()); + assertThat(usersController.getMe(ugnich).getJIDs().size(), is(0)); + jdbcTemplate.update("INSERT INTO jids(user_id, jid) VALUES(?, ?)", + ugnich.getUid(), "test@example.com"); + jdbcTemplate.update("INSERT INTO jids(user_id, jid) VALUES(?, ?)", + ugnich.getUid(), "test2@example.com"); + assertThat(usersController.getMe(ugnich).getJIDs().size(), is(2)); + mockMvc.perform(post("/api/me") + .with(httpBasic(ugnichName, ugnichPassword)) + .param("jid-del", "test@example.com")) + .andExpect(status().isOk()); + assertThat(usersController.getMe(ugnich).getJIDs().size(), is(1)); + mockMvc.perform(post("/api/me") + .with(httpBasic(ugnichName, ugnichPassword)) + .param("jid-del", "test2@example.com")) + .andExpect(status().isBadRequest()); + jdbcTemplate.execute("DELETE FROM jids"); } + @Test public void varyMvcResponse() throws Exception { mockMvc.perform(get("/")) |