aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/test/java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-08-14 13:23:53 +0300
committerGravatar Vitaly Takmazov2018-08-14 16:45:12 +0300
commit2c1bfab10903895ece9644bc095597aaef2a75e8 (patch)
treec721f8582e2b9f1d91ab88ce7d3dfb6cd7e9d2d5 /juick-server/src/test/java
parentc0ac4aa5824b45ff9543f60c648625869b11b1a3 (diff)
Message editing API
Diffstat (limited to 'juick-server/src/test/java')
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java38
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());
+ }
}