From e2c2cf416db9637ebd41c489cf5a533824d17d4c Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 1 Nov 2017 12:55:21 +0300 Subject: notifications: fix tokens deletion --- .../java/com/juick/api/tests/MessagesTests.java | 23 ++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (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 63fac6a1..13d399ca 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 @@ -81,8 +81,8 @@ public class MessagesTests extends AbstractJUnit4SpringContextTests { @Inject private ImagesService imagesService; - private static User ugnich, freefd; - static String ugnichName, ugnichPassword, freefdName, freefdPassword; + private static User ugnich, freefd, juick; + static String ugnichName, ugnichPassword, freefdName, freefdPassword, juickName, juickPassword; static Message msg; private static boolean isSetUp = false; @@ -99,11 +99,15 @@ public class MessagesTests extends AbstractJUnit4SpringContextTests { ugnichPassword = "MyPassw0rd!"; freefdName = "freefd"; freefdPassword = "MyPassw0rd!"; - + juickName = "juick"; + juickPassword = "demo"; int ugnichId = userService.createUser(ugnichName, ugnichPassword); ugnich = userService.getUserByUID(ugnichId).orElseThrow(IllegalStateException::new); int freefdId = userService.createUser(freefdName, freefdPassword); freefd = userService.getUserByUID(freefdId).orElseThrow(IllegalStateException::new); + int juickId = userService.createUser(juickName, juickPassword); + juick = userService.getUserByUID(juickId).orElseThrow(IllegalStateException::new); + String msgText = "Привет, я - Угнич"; int mid = messagesService.createMessage(ugnich.getUid(), msgText, "png", null); @@ -245,9 +249,6 @@ public class MessagesTests extends AbstractJUnit4SpringContextTests { } @Test public void registerForNotificationsTests() throws Exception { - String juickName = "juick"; - String juickPassword = "demo"; - int juickId = userService.createUser(juickName, juickPassword); String token = "123456"; ExternalToken registration = new ExternalToken(null, "apns", token, null); mockMvc.perform(put("/notifications").with(httpBasic(ugnichName, ugnichPassword)) @@ -270,4 +271,14 @@ public class MessagesTests extends AbstractJUnit4SpringContextTests { assertThat(uriComponents.getPath().substring(1), is("123456")); assertThat(uriComponents.getFragment(), is("23")); } + @Test + public void notificationsTokensTest() throws Exception { + List tokens = Collections.singletonList(new ExternalToken(null, "gcm", "123456", null)); + mockMvc.perform(delete("/notifications").with(httpBasic(ugnichName, ugnichPassword)) + .contentType(MediaType.APPLICATION_JSON_UTF8) + .content(jsonMapper.writeValueAsBytes(tokens))).andExpect(status().isForbidden()); + mockMvc.perform(delete("/notifications").with(httpBasic(juickName, juickPassword)) + .contentType(MediaType.APPLICATION_JSON_UTF8) + .content(jsonMapper.writeValueAsBytes(tokens))).andExpect(status().isOk()); + } } -- cgit v1.2.3