diff --git a/src/api/parser/src/utils/__mocks__/supabase.js b/src/api/parser/src/utils/__mocks__/supabase.js index a533a2b1d1..b4cb7c34b1 100644 --- a/src/api/parser/src/utils/__mocks__/supabase.js +++ b/src/api/parser/src/utils/__mocks__/supabase.js @@ -1,14 +1,12 @@ let feeds = []; - +let feedIds = new Set(); module.exports = { __setMockFeeds: (redisFeeds) => { - const mockFeeds = redisFeeds.map((feed) => { - return { - id: feed.id, - flagged: false, - }; - }); - feeds = mockFeeds; + const mockFeeds = redisFeeds + .filter((feed) => !feedIds.has(feed.id)) + .map((feed) => ({ id: feed.id, flagged: false })); + feeds = feeds.concat(mockFeeds); + console.log(feeds); }, // Flagged feed related functions getAllFeeds: jest.fn().mockImplementation(() => Promise.resolve(feeds)), @@ -35,7 +33,8 @@ module.exports = { }), isFlagged: jest.fn().mockImplementation((id) => { const targetFeed = feeds.filter((feed) => feed.id === id)[0]; - + console.log(targetFeed); + console.log(feeds); return Promise.resolve(targetFeed.flagged); }), }; diff --git a/src/api/parser/test/feed.test.js b/src/api/parser/test/feed.test.js index dd3a0fca83..c6172a33cb 100644 --- a/src/api/parser/test/feed.test.js +++ b/src/api/parser/test/feed.test.js @@ -8,7 +8,7 @@ const { search } = require('../src/utils/indexer'); const urlToId = (url) => hash(normalizeUrl(url)); jest.mock('../src/utils/supabase'); -const { __setMockFeeds } = require('../src/utils/supabase'); +const { __setMockFeeds } = require('../src/utils/__mocks__/supabase'); describe('Post data class tests', () => { const data = { @@ -95,7 +95,11 @@ describe('Post data class tests', () => { describe('Get and Set Feed objects from database', () => { const { mock } = Elastic(); - beforeAll(() => createFeed().save()); + beforeAll(async () => { + const feed = new Feed(data.author, data.url, data.user, data.link, null, null); + __setMockFeeds([feed]); + await feed.save(); + }); afterEach(() => mock.clearAll()); test('Feed.byId() for a valid id should return a Feed', async () => { @@ -131,6 +135,7 @@ describe('Post data class tests', () => { test('Setting etag on a feed should persist', async () => { const feed = new Feed('author', 'http://url.com/with/etag'); feed.etag = 'etag'; + __setMockFeeds([feed]); await feed.save(); const persisted = await Feed.byId(feed.id); expect(persisted.etag).toEqual('etag'); @@ -142,6 +147,7 @@ describe('Post data class tests', () => { test('Setting lastModified on a feed should persist', async () => { const feed = new Feed('author', 'http://url.com/with/lastModified'); feed.lastModified = 'lastModified'; + __setMockFeeds([feed]); await feed.save(); const persisted = await Feed.byId(feed.id); expect(persisted.lastModified).toEqual('lastModified'); @@ -161,6 +167,7 @@ describe('Post data class tests', () => { const feed = new Feed(data.author, data.url, data.user, data.link, null, null); feed.author = 'Author Post'; feed.url = 'https://modified.user.feed.com/feed.rss'; + __setMockFeeds([feed]); await feed.update(); const modifiedFeed = await Feed.byId(feed.id); // modifiedFeed.id should be different from feed.id as feed hasn't been reassigned to updated feed.id value @@ -239,7 +246,7 @@ describe('Post data class tests', () => { let feed = new Feed(data.author, data.url, data.user, data.link, 'etag', 'lastModified'); let feed2 = new Feed(data2.author, data2.url, data2.user, data2.link, 'etag', 'lastModified'); let feed3 = new Feed(data3.author, data3.url, data3.user, data3.link, 'etag', 'lastModified'); - + __setMockFeeds([feed, feed2, feed3]); feed = await Feed.byId(await Feed.create(feed)); feed2 = await Feed.byId(await Feed.create(feed2)); feed3 = await Feed.byId(await Feed.create(feed3));