From 207e2632a878ff308b30cbf24b0930e7221ffe5c Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 25 Sep 2017 10:24:59 +0300 Subject: api: add timestamp and 404 tests --- .../src/test/java/com/juick/api/tests/MessagesTests.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'juick-api/src/test/java/com/juick') diff --git a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java b/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java index e8045cc2..b30cdece 100644 --- a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java +++ b/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java @@ -31,6 +31,7 @@ import com.juick.service.MessagesService; import com.juick.service.TagService; import com.juick.service.UserService; import com.juick.test.util.MockUtils; +import com.juick.util.DateFormattersHolder; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -51,6 +52,7 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.socket.client.WebSocketConnectionManager; import javax.inject.Inject; +import java.time.Instant; import java.util.*; import static org.hamcrest.Matchers.hasSize; @@ -151,7 +153,8 @@ public class MessagesTests { String msgText = "Привет, я - Угнич"; Message msg = MockUtils.mockMessage(1, ugnich, msgText); - + Instant now = Instant.now(); + msg.setTimestamp(now); when(messagesService.getMyFeed(1, 0, true)) .thenReturn(Collections.singletonList(1)); when(messagesService.getMessages(Collections.singletonList(1))) @@ -164,6 +167,7 @@ public class MessagesTests { .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$", hasSize(1))) .andExpect(jsonPath("$[0].mid", is(1))) + .andExpect(jsonPath("$[0].timestamp", is(DateFormattersHolder.getMessageFormatterInstance().format(now)))) .andExpect(jsonPath("$[0].body", is(msgText))); } @@ -288,4 +292,9 @@ public class MessagesTests { .with(httpBasic(ugnichName, ugnichPassword))) .andExpect(status().isOk()); } + @Test + public void threadWithEphemeralNumberShouldReturn404() throws Exception { + mockMvc.perform(get("/thread").param("mid", "999999999") + .with(httpBasic(ugnichName, ugnichPassword))).andExpect(status().is4xxClientError()); + } } -- cgit v1.2.3