From 2c1bfab10903895ece9644bc095597aaef2a75e8 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 14 Aug 2018 13:23:53 +0300 Subject: Message editing API --- .../java/com/juick/server/tests/ServerTests.java | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'juick-server/src/test/java') 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()); + } } -- cgit v1.2.3