diff options
author | Vitaly Takmazov | 2018-05-17 23:18:40 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-05-17 23:18:40 +0300 |
commit | b17bf6508ef2b00fbd1ad04725ab457e0cf93831 (patch) | |
tree | 772661f08eba13623b72883bc660ec7787516668 /juick-server | |
parent | 235bb5b9fc7072531f19cc25c3b07258198d86ec (diff) |
tests refactoring
Diffstat (limited to 'juick-server')
3 files changed, 24 insertions, 19 deletions
diff --git a/juick-server/src/main/java/com/juick/server/api/Users.java b/juick-server/src/main/java/com/juick/server/api/Users.java index 3e546eac..5f8e66b0 100644 --- a/juick-server/src/main/java/com/juick/server/api/Users.java +++ b/juick-server/src/main/java/com/juick/server/api/Users.java @@ -23,6 +23,7 @@ import com.juick.server.util.HttpNotFoundException; import com.juick.service.UserService; import com.juick.server.util.UserUtils; import com.juick.server.util.WebUtils; +import io.swagger.annotations.ApiOperation; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; @@ -39,6 +40,7 @@ public class Users { @Inject private UserService userService; + @ApiOperation(value = "This returns user token", notes = "Pass login and password using HTTP Basic") @RequestMapping(value = "/auth", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public String getAuthToken() { return userService.getHashByUID(UserUtils.getCurrentUser().getUid()); 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 924615d7..ebca8c6c 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 @@ -160,8 +160,7 @@ public class ServerTests { private static User ugnich, freefd, juick; static String ugnichName, ugnichPassword, freefdName, freefdPassword, juickName, juickPassword; - static Message msg; - static int juickTagId; + URI emptyUri = URI.create(StringUtils.EMPTY); private static boolean isSetUp = false; @@ -184,13 +183,6 @@ public class ServerTests { freefd = userService.getUserByUID(freefdId).orElseThrow(IllegalStateException::new); int juickId = userService.createUser(juickName, juickPassword); juick = userService.getUserByUID(juickId).orElseThrow(IllegalStateException::new); - - String msgText = "Привет, я - Угнич"; - CommandResult result = commandsManager.processCommand(ugnich, msgText, URI.create("http://static.juick.com/settings/facebook.png")); - int mid = result.getNewMessage().get().getMid(); - msg = messagesService.getMessage(mid); - tagService.createTag("тест"); - juickTagId = tagService.createTag("juick"); isSetUp = true; } } @@ -384,17 +376,24 @@ public class ServerTests { @Test public void homeTestWithMessages() throws Exception { + String msgText = "Привет, я - Угнич"; + CommandResult result = commandsManager.processCommand(ugnich, msgText, URI.create("http://static.juick.com/settings/facebook.png")); + int mid = result.getNewMessage().get().getMid(); + Message msg = messagesService.getMessage(mid); + tagService.createTag("тест"); mockMvc.perform( get("/home") .with(httpBasic(ugnichName, ugnichPassword))) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) - .andExpect(jsonPath("$[-1].mid", is(msg.getMid()))) - .andExpect(jsonPath("$[-1].timestamp", + .andExpect(jsonPath("$[0].mid", is(msg.getMid()))) + .andExpect(jsonPath("$[0].timestamp", is(DateFormattersHolder.getMessageFormatterInstance().format(msg.getTimestamp())))) - .andExpect(jsonPath("$[-1].body", is(msg.getText()))) - .andExpect(jsonPath("$[-1].attachment.url", is("https://i.juick.com/p/1.png"))) - .andExpect(jsonPath("$[-1].attachment.small.url", is("https://i.juick.com/photos-512/1.png"))); + .andExpect(jsonPath("$[0].body", is(msg.getText()))) + .andExpect(jsonPath("$[0].attachment.url", + is(String.format("https://i.juick.com/p/%d.png", msg.getMid())))) + .andExpect(jsonPath("$[0].attachment.small.url", + is(String.format("https://i.juick.com/photos-512/%d.png", msg.getMid())))); } @Test @@ -564,10 +563,12 @@ public class ServerTests { } @Test public void notificationsSettingsAllowedOnlyForServiceUser() throws Exception { + CommandResult result = commandsManager.processCommand(ugnich, "yo", emptyUri); + String stringValueOfMid = String.valueOf(result.getNewMessage().get().getMid()); mockMvc.perform(get("/notifications").with(httpBasic(juickName, juickPassword)) - .param("mid", "1").param("uid", String.valueOf(ugnich.getUid()))).andExpect(status().isOk()); + .param("mid", stringValueOfMid).param("uid", String.valueOf(ugnich.getUid()))).andExpect(status().isOk()); mockMvc.perform(get("/notifications") - .param("mid", "1").param("uid", String.valueOf(ugnich.getUid()))).andExpect(status().isUnauthorized()); + .param("mid", stringValueOfMid).param("uid", String.valueOf(ugnich.getUid()))).andExpect(status().isUnauthorized()); } @Test public void topTest() { @@ -578,8 +579,10 @@ public class ServerTests { messagesService.createReply(topmid, 0, next, "yo", null); }); - assertThat(messagesService.getPopularCandidates().get(0), is(topmid)); - Tag juickTag = tagService.getTag(juickTagId); + List<Integer> topCandidates = messagesService.getPopularCandidates(); + assertThat(topCandidates.size(), is(1)); + assertThat(topCandidates.get(0), is(topmid)); + Tag juickTag = tagService.getTag("juick", false); assertThat(juickTag.TID, is(2)); tagService.updateTags(topmid, Collections.singletonList(juickTag)); assertThat(messagesService.getPopularCandidates().isEmpty(), is(true)); @@ -654,7 +657,6 @@ public class ServerTests { } @Test public void botCommandsTests() throws Exception { - URI emptyUri = URI.create(StringUtils.EMPTY); assertThat(commandsManager.processCommand(AnonymousUser.INSTANCE, "PING", emptyUri).getText(), is("PONG")); // subscription commands have two lines, others have 1 assertThat(commandsManager.processCommand(AnonymousUser.INSTANCE, "help", emptyUri).getText().split("\n").length, is(32)); diff --git a/juick-server/src/test/resources/data.sql b/juick-server/src/test/resources/data.sql index 17421b16..102b11f4 100644 --- a/juick-server/src/test/resources/data.sql +++ b/juick-server/src/test/resources/data.sql @@ -1,3 +1,4 @@ +INSERT INTO tags(tag_id, name) VALUES(2, 'juick'); INSERT INTO reactions (like_id, description) VALUES (1, 'like'); INSERT INTO reactions (like_id, description) VALUES (2, 'love'); INSERT INTO reactions (like_id, description) VALUES (3, 'lol'); |