From f5136502fd12ec88af216001774d6128d8e6cdaf Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 19 Jun 2019 19:14:27 +0300 Subject: API: add tag stats to /me endpoint --- src/test/java/com/juick/server/tests/ServerTests.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/test/java/com/juick/server') diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java index 9b905319..4c72913e 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -2103,4 +2103,22 @@ public class ServerTests { TopEvent receivedEvent = topEventCaptor.getValue(); assertThat(receivedEvent.getMessage().getUser(), is(ugnich)); } + @Test + public void tagStatsSpec() throws Exception { + String newUserName = "tagger"; + String newUserSecret = "secret"; + User newUser = userService.createUser(newUserName, newUserSecret) + .orElseThrow(IllegalStateException::new); + commandsManager.processCommand(newUser, "*test yo", emptyUri); + commandsManager.processCommand(newUser, "*test yo2", emptyUri); + commandsManager.processCommand(newUser, "*rare yo3", emptyUri); + MvcResult userResponse = mockMvc.perform(get("/api/me").with(httpBasic(newUserName, newUserSecret))) + .andExpect(status().isOk()).andReturn(); + User userData = jsonMapper.readValue(userResponse.getResponse().getContentAsString(), User.class); + List userTags = userData.getTagStats(); + assertThat(userTags.size(), is(2)); + TagStats rareTagStats = userTags.stream().filter(tagStats -> tagStats.getTag().getName().equals("rare")) + .findFirst().orElseThrow(IllegalStateException::new); + assertThat(rareTagStats.getUsageCount(), is(1)); + } } -- cgit v1.2.3