diff options
Diffstat (limited to 'juick-server/src/test/java/com')
-rw-r--r-- | juick-server/src/test/java/com/juick/server/tests/ServerTests.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java index 1aff9ca3..2d28dc9d 100644 --- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java +++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java @@ -1130,4 +1130,42 @@ public class ServerTests { Files.deleteIfExists(pngOutput); } } + @Test + public void messageEditingSpec() throws Exception { + MvcResult result = mockMvc.perform(post("/post").with(httpBasic(ugnichName, ugnichPassword)) + .param("body", "YO")).andExpect(status().is2xxSuccessful()).andReturn(); + Message original = jsonMapper.readValue(result.getResponse().getContentAsString(), CommandResult.class) + .getNewMessage().get(); + assertThat(original.getText(), equalTo("YO")); + assertThat(original.getUpdatedAt(), equalTo(original.getTimestamp())); + // to have updated_at greater than ts + Thread.sleep(1000); + result = mockMvc.perform(post("/update").with(httpBasic(ugnichName, ugnichPassword)) + .param("mid", String.valueOf(original.getMid())) + .param("body", "PEOPLE")).andExpect(status().is2xxSuccessful()).andReturn(); + Message edited = jsonMapper.readValue(result.getResponse().getContentAsString(), CommandResult.class) + .getNewMessage().get(); + assertThat(edited.getText(), equalTo("PEOPLE")); + assertThat(edited.getUpdatedAt(), greaterThan(edited.getTimestamp())); + mockMvc.perform(post("/update").with(httpBasic(freefdName, freefdPassword)) + .param("mid", String.valueOf(original.getMid())) + .param("body", "PEOPLE")).andExpect(status().is(403)); + result = mockMvc.perform(post("/comment").with(httpBasic(freefdName, freefdPassword)) + .param("mid", String.valueOf(original.getMid())) + .param("body", "HEY")).andExpect(status().is2xxSuccessful()).andReturn(); + Message comment = jsonMapper.readValue(result.getResponse().getContentAsString(), Message.class); + assertThat(comment.getText(), is("HEY")); + assertThat(comment.getUpdatedAt(), is(comment.getTimestamp())); + // to have updated_at greater than ts + Thread.sleep(1000); + result = mockMvc.perform(post("/update").with(httpBasic(freefdName, freefdPassword)) + .param("mid", String.valueOf(comment.getMid())) + .param("rid", String.valueOf(comment.getRid())) + .param("body", "HEY, JOE")).andExpect(status().is2xxSuccessful()).andReturn(); + Message editedComment = jsonMapper.readValue(result.getResponse().getContentAsString(), CommandResult.class) + .getNewMessage().get(); + assertThat(editedComment.getText(), is("HEY, JOE")); + assertThat(editedComment.getUpdatedAt(), greaterThan(editedComment.getTimestamp())); + messagesService.deleteMessage(ugnich.getUid(), original.getMid()); + } } |