From 38c743822518f832bd002a2ecc3eb1922a26456d Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 18 Oct 2017 01:26:15 +0300 Subject: api: add notifications registration test --- .../java/com/juick/api/tests/MessagesTests.java | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'juick-api/src/test/java/com/juick/api') 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 6fddba11..b626b0e9 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 @@ -17,7 +17,9 @@ package com.juick.api.tests; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import com.juick.DeviceRegistration; import com.juick.Message; import com.juick.Tag; import com.juick.User; @@ -46,6 +48,7 @@ import org.springframework.web.context.WebApplicationContext; import javax.inject.Inject; import java.util.Arrays; import java.util.Collections; +import java.util.List; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; @@ -238,4 +241,25 @@ public class MessagesTests extends AbstractJUnit4SpringContextTests { assertThat(authHash, equalTo(ugnichHash)); mockMvc.perform(get("/home").param("hash", ugnichHash)).andExpect(status().isOk()); } + @Test + public void registerForNotificationsTests() throws Exception { + String juickName = "juick"; + String juickPassword = "demo"; + int juickId = userService.createUser(juickName, juickPassword); + String token = "123456"; + DeviceRegistration registration = new DeviceRegistration("apns", token); + mockMvc.perform(put("/notifications").with(httpBasic(ugnichName, ugnichPassword)) + .contentType(MediaType.APPLICATION_JSON_UTF8) + .content(jsonMapper.writeValueAsBytes(Collections.singletonList(registration)))) + .andExpect(status().isOk()); + MvcResult result = mockMvc.perform(get("/notifications") + .param("uid", String.valueOf(ugnich.getUid())) + .with(httpBasic(juickName, juickPassword))) + .andExpect(status().isOk()) + .andReturn(); + List user = jsonMapper.readValue(result.getResponse().getContentAsString(), + new TypeReference>() { + }); + assertThat(user.get(0).getDevices().get(0).getToken(), equalTo(token)); + } } -- cgit v1.2.3