aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/juick/server/tests
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2023-01-22 20:27:45 +0300
committerGravatar Vitaly Takmazov2023-01-22 20:57:06 +0300
commit478a7bfba88401c1996d0be5a144459011b60e10 (patch)
tree2bdbf40a9910c799673874d64a87a4ef0e5dc04b /src/test/java/com/juick/server/tests
parent9ad08dc78e0cdbe2cdebf10a96c800e72d48e48b (diff)
db refactoring: merge getMessages with isSubscribed query
Diffstat (limited to 'src/test/java/com/juick/server/tests')
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java60
1 files changed, 27 insertions, 33 deletions
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index b7b78fa9..dba662b0 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -1029,7 +1029,7 @@ public class ServerTests {
Message msg4 = messagesService.getMessage(mid1).get();
assertThat(msg4.getRecommendations().size(), is(0));
assertThat(
- messagesService.getMessages(AnonymousUser.INSTANCE, Collections.singletonList(mid1))
+ messagesService.getMessages(AnonymousUser.INSTANCE.getUid(), Collections.singletonList(mid1))
.get(0).getRecommendations().size(),
is(0));
assertEquals(1, msg4.getReactions().stream().filter(r -> r.getId() == 2).findFirst()
@@ -1057,7 +1057,7 @@ public class ServerTests {
assertThat(lastRead.apply(ugnich, mid), is(0));
assertThat(messagesService.getUnread(ugnich).size(), is(1));
assertThat(messagesService.getUnread(ugnich).get(0), is(mid));
- assertThat(messagesService.getMessages(ugnich, Collections.singletonList(mid)).get(0).isUnread(),
+ assertThat(messagesService.getMessages(ugnich.getUid(), Collections.singletonList(mid)).get(0).isUnread(),
is(true));
messagesService.getReplies(ugnich, mid);
assertThat(lastRead.apply(ugnich, mid), is(1));
@@ -1093,30 +1093,30 @@ public class ServerTests {
int mid = messagesService.createMessage(ugnich.getUid(), "yo", "jpg", Set.of(banned));
privacyQueriesService.blacklistTag(freefd, banned);
assertThat(messagesService
- .getMessages(AnonymousUser.INSTANCE, messagesService.getAll(freefd.getUid(), 0))
+ .getMessages(AnonymousUser.INSTANCE.getUid(), messagesService.getAll(freefd.getUid(), 0))
.stream().noneMatch(m -> m.getTags().contains(banned)), is(true));
assertFalse(messagesService
- .getMessages(AnonymousUser.INSTANCE, messagesService.getAll(ugnich.getUid(), 0))
+ .getMessages(AnonymousUser.INSTANCE.getUid(), messagesService.getAll(ugnich.getUid(), 0))
.stream().noneMatch(m -> m.getTags().contains(banned)));
assertThat(messagesService
- .getMessages(AnonymousUser.INSTANCE, messagesService.getPhotos(freefd.getUid(), 0))
+ .getMessages(AnonymousUser.INSTANCE.getUid(), messagesService.getPhotos(freefd.getUid(), 0))
.stream().noneMatch(m -> m.getTags().contains(banned)), is(true));
assertFalse(messagesService
- .getMessages(AnonymousUser.INSTANCE, messagesService.getPhotos(ugnich.getUid(), 0))
+ .getMessages(AnonymousUser.INSTANCE.getUid(), messagesService.getPhotos(ugnich.getUid(), 0))
.stream().noneMatch(m -> m.getTags().contains(banned)));
messagesService.recommendMessage(mid, serviceUser.getUid());
assertThat(messagesService
- .getMessages(AnonymousUser.INSTANCE,
+ .getMessages(AnonymousUser.INSTANCE.getUid(),
messagesService.getUserBlogWithRecommendations(serviceUser, freefd, 0,
0))
.stream().noneMatch(m -> m.getTags().contains(banned)), is(true));
assertFalse(messagesService
- .getMessages(AnonymousUser.INSTANCE,
+ .getMessages(AnonymousUser.INSTANCE.getUid(),
messagesService.getUserBlogWithRecommendations(serviceUser, ugnich, 0,
0))
.stream().noneMatch(m -> m.getTags().contains(banned)));
assertThat(
- messagesService.getMessages(AnonymousUser.INSTANCE,
+ messagesService.getMessages(AnonymousUser.INSTANCE.getUid(),
messagesService.getMyFeed(freefd.getUid(), 0, true))
.stream().noneMatch(m -> m.getTags().contains(banned)),
is(true));
@@ -1124,7 +1124,7 @@ public class ServerTests {
int newMid = messagesService.createMessage(newUser1.getUid(), "people", null, Set.of(banned));
messagesService.recommendMessage(newMid, ugnich.getUid());
assertThat(
- messagesService.getMessages(AnonymousUser.INSTANCE,
+ messagesService.getMessages(AnonymousUser.INSTANCE.getUid(),
messagesService.getMyFeed(freefd.getUid(), 0, true))
.stream().noneMatch(m -> m.getTags().contains(banned)),
is(true));
@@ -1267,12 +1267,12 @@ public class ServerTests {
reply = messagesService.getReply(mid, 5);
assertThat(userService.isReplyToBL(ugnich, reply), is(true));
assertThat(replies.size(), is(1));
- List<Message> msgs = messagesService.getMessages(ugnich, Collections.singletonList(mid));
+ List<Message> msgs = messagesService.getMessages(ugnich.getUid(), Collections.singletonList(mid));
assertThat(msgs.get(0).getReplies(), is(1));
commandsManager.processCommand(ugnich, "BL @freefd", emptyUri);
messagesService.setRead(ugnich, mid);
assertThat(messagesService.getReplies(ugnich, mid).size(), is(5));
- List<Message> nonblmsgs = messagesService.getMessages(ugnich, Collections.singletonList(mid));
+ List<Message> nonblmsgs = messagesService.getMessages(ugnich.getUid(), Collections.singletonList(mid));
assertThat(nonblmsgs.get(0).getReplies(), is(5));
commandsManager.processCommand(ugnich, "BL @freefd", emptyUri);
Tag tag = tagService.getTag("linux", true);
@@ -1634,11 +1634,11 @@ public class ServerTests {
int casualRid = messagesService.createReply(mid, 0, userService.getUserByName("user"), "DOOR", null);
assertThat(messagesService.getReplies(AnonymousUser.INSTANCE, mid).size(), is(1));
assertThat(
- messagesService.getMessages(AnonymousUser.INSTANCE, Collections.singletonList(mid))
+ messagesService.getMessages(AnonymousUser.INSTANCE.getUid(), Collections.singletonList(mid))
.get(0).getReplies(),
is(1));
assertThat(messagesService.getReplies(banned, mid).size(), is(2));
- assertThat(messagesService.getMessages(banned, Collections.singletonList(mid)).get(0).getReplies(),
+ assertThat(messagesService.getMessages(banned.getUid(), Collections.singletonList(mid)).get(0).getReplies(),
is(2));
}
@@ -2167,7 +2167,7 @@ public class ServerTests {
messagesService.likeMessage(msg.getMid(), freefd.getUid(), Reaction.LIKE);
messagesService.likeMessage(msg.getMid(), 0, Reaction.LIKE, "http://localhost:8080/u/test");
messagesService.recommendMessage(msg.getMid(), serviceUser.getUid());
- List<Message> top = messagesService.getMessages(ugnich,
+ List<Message> top = messagesService.getMessages(ugnich.getUid(),
messagesService.getUserBlogWithRecommendations(serviceUser, ugnich, 0, 0));
assertThat(top.size(), is(1));
}
@@ -2551,8 +2551,8 @@ public class ServerTests {
var result = commandsManager.processCommand(ugnich, "test", emptyUri);
var mid = result.getNewMessage().get().getMid();
jdbcTemplate.update("UPDATE subscr_messages SET last_read_rid=10 WHERE message_id=?", mid);
- assertThat(messagesService.getMessages(ugnich, List.of(mid)).size(), is(1));
- assertThat(messagesService.getMessages(ugnich, List.of(mid)).get(0).isUnread(), is(false));
+ assertThat(messagesService.getMessages(ugnich.getUid(), List.of(mid)).size(), is(1));
+ assertThat(messagesService.getMessages(ugnich.getUid(), List.of(mid)).get(0).isUnread(), is(false));
}
@Test
@@ -2642,22 +2642,16 @@ public class ServerTests {
assertThat(count, is(0));
jdbcTemplate.execute("DELETE FROM emails");
}
-/*
@Test
- public void tokenAuth() throws Exception {
- var token = keystoreManager.generateToken(ugnich);
- mockMvc.perform(get("/api/me")
- .header("Authorization", "Bearer " + token))
- .andExpect(jsonPath("$.uname", is("ugnich")));
- token = keystoreManager.generateToken(freefd);
- mockMvc.perform(get("/api/me")
- .header("Authorization", "Bearer " + token))
- .andExpect(jsonPath("$.uname", is("freefd")));
- token = keystoreManager.generateToken(ugnich) + "1";
- mockMvc.perform(get("/api/me")
- .header("Authorization", "Bearer " + token))
- .andExpect(status().isUnauthorized());
+ @Transactional
+ public void isSubscribed() {
+ int mid = messagesService.createMessage(ugnich.getUid(), "test", "", Collections.emptySet());
+ var msg = messagesService.getMessage(ugnich.getUid(), mid).orElseThrow();
+ assertThat(msg.isSubscribed(), is(false));
+ subscriptionService.subscribeMessage(msg, ugnich);
+ msg = messagesService.getMessage(ugnich.getUid(), mid).orElseThrow();
+ assertThat(msg.isSubscribed(), is(true));
+ msg = messagesService.getMessage(freefd.getUid(), mid).orElseThrow();
+ assertThat(msg.isSubscribed(), is(false));
}
-
- */
}