fix tests
This commit is contained in:
@ -74,11 +74,14 @@ interface FetchContentTask {
|
||||
item: RssFeedItem
|
||||
}
|
||||
|
||||
export const isOldItem = (item: RssFeedItem, lastFetchedAt: number) => {
|
||||
export const isOldItem = (
|
||||
item: RssFeedItem,
|
||||
mostRecentItemTimestamp: number
|
||||
) => {
|
||||
// existing items and items that were published before 24h
|
||||
const publishedAt = item.isoDate ? new Date(item.isoDate) : new Date()
|
||||
return (
|
||||
publishedAt <= new Date(lastFetchedAt) ||
|
||||
publishedAt <= new Date(mostRecentItemTimestamp) ||
|
||||
publishedAt < new Date(Date.now() - 24 * 60 * 60 * 1000)
|
||||
)
|
||||
}
|
||||
|
||||
@ -477,6 +477,10 @@ export const functionResolvers = {
|
||||
DEFAULT_SUBSCRIPTION_FOLDER
|
||||
)
|
||||
},
|
||||
// for campability with old clients
|
||||
lastFetchedAt(subscription: Subscription) {
|
||||
return subscription.mostRecentItemDate
|
||||
},
|
||||
},
|
||||
NewsletterEmail: {
|
||||
subscriptionCount(newsletterEmail: NewsletterEmail) {
|
||||
|
||||
@ -103,7 +103,7 @@ export const saveSubscription = async ({
|
||||
unsubscribeHttpUrl,
|
||||
unsubscribeMailTo,
|
||||
icon,
|
||||
lastFetchedAt: new Date(),
|
||||
refreshedAt: new Date(),
|
||||
}
|
||||
|
||||
const existingSubscription = await getSubscriptionByName(name, userId)
|
||||
@ -199,7 +199,7 @@ export const createSubscription = async (
|
||||
newsletterEmail,
|
||||
status,
|
||||
unsubscribeMailTo,
|
||||
lastFetchedAt: new Date(),
|
||||
refreshedAt: new Date(),
|
||||
type: subscriptionType,
|
||||
url,
|
||||
})
|
||||
|
||||
@ -7,17 +7,17 @@ describe('isOldItem', () => {
|
||||
const item = {
|
||||
pubDate: '2020-01-01',
|
||||
} as RssFeedItem
|
||||
const lastFetchedAt = Date.now()
|
||||
const mostRecentItemTimestamp = Date.now()
|
||||
|
||||
expect(isOldItem(item, lastFetchedAt)).to.be.true
|
||||
expect(isOldItem(item, mostRecentItemTimestamp)).to.be.true
|
||||
})
|
||||
|
||||
it('returns true if item was published at the last fetched time', () => {
|
||||
const lastFetchedAt = Date.now()
|
||||
const mostRecentItemTimestamp = Date.now()
|
||||
const item = {
|
||||
pubDate: new Date(lastFetchedAt).toISOString(),
|
||||
pubDate: new Date(mostRecentItemTimestamp).toISOString(),
|
||||
} as RssFeedItem
|
||||
|
||||
expect(isOldItem(item, lastFetchedAt)).to.be.true
|
||||
expect(isOldItem(item, mostRecentItemTimestamp)).to.be.true
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user