forked from Archives/Athou_commafeed
add tests for the new insertedBefore mechanic
This commit is contained in:
@@ -101,7 +101,7 @@ public abstract class BaseIT {
|
||||
protected Entries getFeedEntries(long subscriptionId) {
|
||||
Response response = client.target(apiBaseUrl + "feed/entries")
|
||||
.queryParam("id", subscriptionId)
|
||||
.queryParam("readType", "unread")
|
||||
.queryParam("readType", "all")
|
||||
.request()
|
||||
.get();
|
||||
return response.readEntity(Entries.class);
|
||||
|
||||
@@ -3,7 +3,9 @@ package com.commafeed.integration.rest;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.time.Duration;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
@@ -17,7 +19,6 @@ import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.commafeed.frontend.model.Entries;
|
||||
import com.commafeed.frontend.model.Entry;
|
||||
import com.commafeed.frontend.model.FeedInfo;
|
||||
import com.commafeed.frontend.model.Subscription;
|
||||
@@ -89,22 +90,43 @@ class FeedIT extends BaseIT {
|
||||
@Nested
|
||||
class Mark {
|
||||
@Test
|
||||
void mark() {
|
||||
long subscriptionId = subscribe(getFeedUrl());
|
||||
Entries entries = Awaitility.await()
|
||||
.atMost(Duration.ofSeconds(15))
|
||||
.until(() -> getFeedEntries(subscriptionId), e -> e.getEntries().size() == 2);
|
||||
Assertions.assertTrue(entries.getEntries().stream().noneMatch(Entry::isRead));
|
||||
|
||||
markFeedEntries(subscriptionId);
|
||||
Awaitility.await()
|
||||
.atMost(Duration.ofSeconds(15))
|
||||
.until(() -> getFeedEntries(subscriptionId), e -> e.getEntries().stream().allMatch(Entry::isRead));
|
||||
void markWithoutDates() {
|
||||
long subscriptionId = subscribeAndWaitForEntries(getFeedUrl());
|
||||
markFeedEntries(subscriptionId, null, null);
|
||||
Assertions.assertTrue(getFeedEntries(subscriptionId).getEntries().stream().allMatch(Entry::isRead));
|
||||
}
|
||||
|
||||
private void markFeedEntries(long subscriptionId) {
|
||||
@Test
|
||||
void markOlderThan() {
|
||||
long subscriptionId = subscribeAndWaitForEntries(getFeedUrl());
|
||||
markFeedEntries(subscriptionId, new GregorianCalendar(2023, Calendar.DECEMBER, 28).getTime(), null);
|
||||
Assertions.assertEquals(1, getFeedEntries(subscriptionId).getEntries().stream().filter(Entry::isRead).count());
|
||||
}
|
||||
|
||||
@Test
|
||||
void markInsertedBeforeBeforeSubscription() {
|
||||
Date insertedBefore = new Date();
|
||||
|
||||
long subscriptionId = subscribeAndWaitForEntries(getFeedUrl());
|
||||
markFeedEntries(subscriptionId, null, insertedBefore);
|
||||
Assertions.assertTrue(getFeedEntries(subscriptionId).getEntries().stream().noneMatch(Entry::isRead));
|
||||
}
|
||||
|
||||
@Test
|
||||
void markInsertedBeforeAfterSubscription() {
|
||||
long subscriptionId = subscribeAndWaitForEntries(getFeedUrl());
|
||||
|
||||
Date insertedBefore = new Date();
|
||||
|
||||
markFeedEntries(subscriptionId, null, insertedBefore);
|
||||
Assertions.assertTrue(getFeedEntries(subscriptionId).getEntries().stream().allMatch(Entry::isRead));
|
||||
}
|
||||
|
||||
private void markFeedEntries(long subscriptionId, Date olderThan, Date insertedBefore) {
|
||||
MarkRequest request = new MarkRequest();
|
||||
request.setId(String.valueOf(subscriptionId));
|
||||
request.setOlderThan(olderThan == null ? null : olderThan.getTime());
|
||||
request.setInsertedBefore(insertedBefore == null ? null : insertedBefore.getTime());
|
||||
getClient().target(getApiBaseUrl() + "feed/mark").request().post(Entity.json(request), Void.TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,17 @@
|
||||
<title>CommaFeed test feed</title>
|
||||
<link>https://hostname.local/commafeed</link>
|
||||
<description>CommaFeed test feed description</description>
|
||||
<item>
|
||||
<title>Item 1</title>
|
||||
<link>https://hostname.local/commafeed/1</link>
|
||||
<description>Item 1 description</description>
|
||||
</item>
|
||||
<item>
|
||||
<title>Item 2</title>
|
||||
<link>https://hostname.local/commafeed/2</link>
|
||||
<description>Item 2 description</description>
|
||||
<pubDate>Fri, 29 Dec 2023 15:02:00 +0100</pubDate>
|
||||
</item>
|
||||
<item>
|
||||
<title>Item 1</title>
|
||||
<link>https://hostname.local/commafeed/1</link>
|
||||
<description>Item 1 description</description>
|
||||
<pubDate>Wed, 27 Dec 2023 22:24:00 +0100</pubDate>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
||||
Reference in New Issue
Block a user