forked from Seneca-CDOT/telescope
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Feed in parser service to talk to Supabase instead of Redis
- Change any invalid/flagged feed code to use supabase - Add more methods to supabase modules - Add supabase mock test - Fix unit/e2e test accordingly
- Loading branch information
1 parent
2700016
commit dd67daf
Showing
13 changed files
with
256 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const { hash } = require('@senecacdot/satellite'); | ||
const normalizeUrl = require('normalize-url'); | ||
|
||
const urlToId = (url) => hash(normalizeUrl(url)); | ||
|
||
let feeds = []; | ||
let feedIds = new Set(); | ||
|
||
module.exports = { | ||
__resetMockFeeds: () => { | ||
feeds = []; | ||
feedIds = new Set(); | ||
}, | ||
/** | ||
* @param {Array<Feed | { url: string }>} feedObjects | ||
*/ | ||
__setMockFeeds: (feedObjects) => { | ||
const mockFeeds = feedObjects.reduce((uniqueFeeds, feed) => { | ||
const id = feed.id || urlToId(feed.url); | ||
if (!feedIds.has(id)) { | ||
feedIds.add(id); | ||
return uniqueFeeds.concat({ id, invalid: false, flagged: false }); | ||
} | ||
return uniqueFeeds; | ||
}, []); | ||
feeds = feeds.concat(mockFeeds); | ||
}, | ||
|
||
// Invalid feed related functions | ||
setInvalidFeed: (id) => { | ||
feeds.forEach((feed) => { | ||
if (feed.id === id) { | ||
feed.invalid = true; | ||
} | ||
}); | ||
return Promise.resolve(); | ||
}, | ||
getInvalidFeeds: () => { | ||
const invalidFeedIds = feeds.filter((feed) => feed.flagged).map((feed) => ({ id: feed.id })); | ||
return Promise.resolve(invalidFeedIds); | ||
}, | ||
isInvalid: (id) => { | ||
const targetFeed = feeds.find((feed) => feed.id === id); | ||
return Promise.resolve(!!targetFeed.invalid); | ||
}, | ||
// Flagged feed related functions | ||
getAllFeeds: jest.fn().mockImplementation(() => Promise.resolve(feeds)), | ||
setFlaggedFeed: jest.fn().mockImplementation((id) => { | ||
feeds.forEach((feed) => { | ||
if (feed.id === id) { | ||
feed.flagged = true; | ||
} | ||
}); | ||
return Promise.resolve(); | ||
}), | ||
unsetFlaggedFeed: jest.fn().mockImplementation((id) => { | ||
feeds.forEach((feed) => { | ||
if (feed.id === id) { | ||
feed.flagged = false; | ||
} | ||
}); | ||
return Promise.resolve(); | ||
}), | ||
|
||
getFlaggedFeeds: jest.fn().mockImplementation(() => { | ||
const flaggedFeedIds = feeds.filter((feed) => feed.flagged).map((feed) => feed.id); | ||
return Promise.resolve(flaggedFeedIds); | ||
}), | ||
isFlagged: jest.fn().mockImplementation((id) => { | ||
const targetFeed = feeds.find((feed) => feed.id === id); | ||
return Promise.resolve(!!targetFeed.flagged); | ||
}), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.