diff options
author | Vitaly Takmazov | 2017-10-11 12:47:02 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-10-11 12:47:02 +0300 |
commit | 753d79d6bbabfdac33c6c382717fe0acaec2a3bd (patch) | |
tree | 006a2b957d4a599315d1472ae1d4f7e726136ee2 /juick-server-jdbc/src/test/java/com/juick | |
parent | 0ad4b98456e5de96a9fea6e128a20a4624c72c6a (diff) |
telegram: do not duplicate subscription requests
Diffstat (limited to 'juick-server-jdbc/src/test/java/com/juick')
-rw-r--r-- | juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java b/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java index 738a1250..44e46b70 100644 --- a/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java +++ b/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java @@ -17,22 +17,22 @@ package com.juick.service; -import com.juick.Message; +import com.juick.Tag; import com.juick.User; import com.juick.configuration.RepositoryConfiguration; import com.juick.server.helpers.AnonymousUser; import org.junit.Before; import org.junit.Test; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; import javax.inject.Inject; -import java.time.ZoneId; +import java.util.Collections; import java.util.List; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; /** * Created by aalexeev on 11/25/16. @@ -45,6 +45,14 @@ public class MessageServiceTest extends AbstractJUnit4SpringContextTests { private UserService userService; @Inject private SubscriptionService subscriptionService; + @Inject + private TagService tagService; + @Inject + private TelegramService telegramService; + @Inject + private JdbcTemplate jdbcTemplate; + @Inject + private CrosspostService crosspostService; int ugnichId, freefdId, mid; @@ -77,11 +85,24 @@ public class MessageServiceTest extends AbstractJUnit4SpringContextTests { User ugnich = userService.getUserByUID(ugnichId).orElse(AnonymousUser.INSTANCE); User freefd = userService.getUserByUID(freefdId).orElse(AnonymousUser.INSTANCE); - int mid = messagesService.createMessage(ugnichId, "yo", null, null); - subscriptionService.subscribeMessage(mid, freefdId); - int rid = messagesService.createReply(mid, 0, ugnichId, "yo", null); - Message reply = messagesService.getReply(mid, rid); - assertThat(messagesService.getNotifications(freefd, null).size(), is(1)); - assertThat(messagesService.getNotifications(freefd, reply.getTimestamp().atZone(ZoneId.systemDefault()).toLocalDateTime()).size(), is(0)); + Tag yoTag = tagService.getTag("yoyo", true); + int mid = messagesService.createMessage(ugnichId, "yo", null, Collections.singletonList(yoTag)); + List<User> subscribers = subscriptionService.getSubscribedUsers(ugnichId, mid); + + telegramService.createTelegramUser(12345, "freefd"); + String loginhash = jdbcTemplate.queryForObject("SELECT loginhash FROM telegram where tg_id=?", + String.class, 12345); + crosspostService.setTelegramUser(loginhash, freefd.getUid()); + + List<Long> telegramSubscribers = telegramService.getTelegramIdentifiers(subscribers); + assertThat(subscribers.size(), equalTo(1)); + assertThat(subscribers.size(), equalTo(telegramSubscribers.size())); + assertThat(subscribers.get(0).getUid(), equalTo(freefd.getUid())); + tagService.blacklistTag(freefd, yoTag); + List<User> subscribers2 = subscriptionService.getSubscribedUsers(ugnichId, mid); + assertThat(subscribers2.size(), equalTo(0)); + assertThat(telegramService.getTelegramIdentifiers(subscribers2).size(), equalTo(0)); + tagService.blacklistTag(freefd, yoTag); + assertThat(subscriptionService.getSubscribedUsers(ugnichId, mid).size(), equalTo(1)); } } |