aboutsummaryrefslogtreecommitdiff
path: root/juick-api
diff options
context:
space:
mode:
Diffstat (limited to 'juick-api')
-rw-r--r--juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java2
-rw-r--r--juick-api/src/main/java/com/juick/api/controllers/Messages.java9
-rw-r--r--juick-api/src/test/java/com/juick/api/tests/MessagesTests.java25
3 files changed, 34 insertions, 2 deletions
diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java b/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java
index df091d51..828f8cbd 100644
--- a/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java
+++ b/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java
@@ -45,7 +45,7 @@ import java.util.Collections;
@EnableWebMvc
@EnableSwagger2
@PropertySource("classpath:juick.conf")
-@ComponentScan(basePackages = "com.juick.api")
+@ComponentScan(basePackages = "com.juick")
public class ApiAppConfiguration extends BaseWebConfiguration {
@Bean
public JuickServerComponent juickServerComponent() {
diff --git a/juick-api/src/main/java/com/juick/api/controllers/Messages.java b/juick-api/src/main/java/com/juick/api/controllers/Messages.java
index 322effa3..5f00ee68 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/Messages.java
+++ b/juick-api/src/main/java/com/juick/api/controllers/Messages.java
@@ -178,6 +178,15 @@ public class Messages {
}
throw new HttpForbiddenException();
}
+ @ApiIgnore
+ @RequestMapping("/messages/top_candidates")
+ public List<Integer> topCandidates() {
+ User visitor = UserUtils.getCurrentUser();
+ if ((visitor.getUid() == 0) || !(visitor.getName().equals("juick"))) {
+ throw new HttpForbiddenException();
+ }
+ return messagesService.getPopularCandidates();
+ }
@ApiIgnore
@RequestMapping("/messages/set_popular")
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 13d399ca..35f09314 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
@@ -24,6 +24,7 @@ import com.juick.Message;
import com.juick.Tag;
import com.juick.User;
import com.juick.api.configuration.ApiAppConfiguration;
+import com.juick.api.configuration.ApiSecurityConfig;
import com.juick.api.tests.configuration.MockStorageConfiguration;
import com.juick.configuration.RepositoryConfiguration;
import com.juick.service.ImagesService;
@@ -51,6 +52,7 @@ import javax.inject.Inject;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.stream.IntStream;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
@@ -62,7 +64,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
* Created by vitalyster on 25.11.2016.
*/
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(classes = {RepositoryConfiguration.class, ApiAppConfiguration.class, MockStorageConfiguration.class})
+@ContextConfiguration(classes = {ApiAppConfiguration.class, ApiSecurityConfig.class, RepositoryConfiguration.class, MockStorageConfiguration.class})
@WebAppConfiguration
public class MessagesTests extends AbstractJUnit4SpringContextTests {
@@ -84,6 +86,7 @@ public class MessagesTests extends AbstractJUnit4SpringContextTests {
private static User ugnich, freefd, juick;
static String ugnichName, ugnichPassword, freefdName, freefdPassword, juickName, juickPassword;
static Message msg;
+ static int juickTagId;
private static boolean isSetUp = false;
@@ -112,6 +115,8 @@ public class MessagesTests extends AbstractJUnit4SpringContextTests {
int mid = messagesService.createMessage(ugnich.getUid(), msgText, "png", null);
msg = messagesService.getMessage(mid);
+ tagService.createTag("ั‚ะตัั‚");
+ juickTagId = tagService.createTag("juick");
isSetUp = true;
}
}
@@ -281,4 +286,22 @@ public class MessagesTests extends AbstractJUnit4SpringContextTests {
.contentType(MediaType.APPLICATION_JSON_UTF8)
.content(jsonMapper.writeValueAsBytes(tokens))).andExpect(status().isOk());
}
+ @Test
+ public void topTest() throws Exception {
+ int topmid = messagesService.createMessage(ugnich.getUid(), "top message", null, null);
+ IntStream.rangeClosed(6, 12).forEach(i -> {
+ messagesService.createReply(topmid, 0, i, "yo", null);
+ });
+ mockMvc.perform(get("/messages/top_candidates").with(httpBasic(juickName, juickPassword))
+ .contentType(MediaType.APPLICATION_JSON_UTF8))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$[0]", is(topmid)));
+ Tag juickTag = tagService.getTag(juickTagId);
+ assertThat(juickTag.TID, is(2));
+ tagService.updateTags(topmid, Collections.singletonList(juickTag));
+ mockMvc.perform(get("/messages/top_candidates").with(httpBasic(juickName, juickPassword))
+ .contentType(MediaType.APPLICATION_JSON_UTF8))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$", hasSize(0)));
+ }
}