-
Notifications
You must be signed in to change notification settings - Fork 0
Replace Bad Instance of databaseTiny.find()
#474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -84,8 +84,29 @@ export const updateLayerAndProject = async (layer, project, userId) => { | |||||||||||||||
| const pageOverwrites = updatedLayer.pages | ||||||||||||||||
| .filter(page => page.id.startsWith(process.env.RERUMIDPREFIX)) | ||||||||||||||||
| .map(async page => { | ||||||||||||||||
| const oldPage = await databaseTiny.find({_id: page.id.split("/").pop()}) | ||||||||||||||||
| if(!oldPage) throw new Error(`Page with ID ${page.id} not found in RERUM`) | ||||||||||||||||
| const oldPage = await fetch(page.id).then(async (resp) => { | ||||||||||||||||
| if (resp.ok) return resp.json() | ||||||||||||||||
| let rerumErrorMessage | ||||||||||||||||
| try { | ||||||||||||||||
| rerumErrorMessage = `${resp.status ?? 500}: ${page.id} - ${await resp.text()}` | ||||||||||||||||
| } catch (e) { | ||||||||||||||||
| rerumErrorMessage = `500: ${page.id} - A RERUM error occurred` | ||||||||||||||||
| } | ||||||||||||||||
| const err = new Error(rerumErrorMessage) | ||||||||||||||||
| err.status = 502 | ||||||||||||||||
| throw err | ||||||||||||||||
| }) | ||||||||||||||||
| .catch(err => { | ||||||||||||||||
| if (err.status === 502) throw err | ||||||||||||||||
| const genericRerumNetworkError = new Error(`500: ${page.id} - A RERUM error occurred`) | ||||||||||||||||
| genericRerumNetworkError.status = 502 | ||||||||||||||||
| throw genericRerumNetworkError | ||||||||||||||||
| }) | ||||||||||||||||
| if (!(oldPage?.id || oldPage?.["@id"])) { | ||||||||||||||||
|
||||||||||||||||
| if (!(oldPage?.id || oldPage?.["@id"])) { | |
| if ( | |
| !oldPage || | |
| typeof oldPage !== "object" || | |
| Array.isArray(oldPage) || | |
| !(oldPage.id || oldPage["@id"]) | |
| ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new RERUM page overwrite path (fetching the page by URL, handling non-OK responses/network failures, then overwriting with updated
partOf) isn’t covered by tests. Sinceutilities/shared.jsalready has unit tests, add targeted unit tests forupdateLayerAndProject()that mockfetch()anddatabaseTiny.overwrite()to cover success, 404/non-OK responses, and network error handling.