From eb4ecf853b43b4979bed6646924f11dd6e3d9152 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Wed, 6 Mar 2024 22:50:24 -0600 Subject: [PATCH] Fix Jest issues I was able to understand --- client/homebrew/brewRenderer/brewRenderer.jsx | 2 +- client/homebrew/pages/printPage/printPage.jsx | 2 +- server/homebrew.api.js | 6 +++--- server/homebrew.api.spec.js | 9 +++++---- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/client/homebrew/brewRenderer/brewRenderer.jsx b/client/homebrew/brewRenderer/brewRenderer.jsx index 2d3e5136e..9ab09301b 100644 --- a/client/homebrew/brewRenderer/brewRenderer.jsx +++ b/client/homebrew/brewRenderer/brewRenderer.jsx @@ -207,7 +207,7 @@ const BrewRenderer = (props)=>{ baseRendererPath += '/'; } - const staticOrUserParent = props?.theme[0] == '#' ? `/cssParent/${themePath}` : `/css/${baseRendererPath}${baseThemePath}`; + const staticOrUserParent = (props.theme && props?.theme[0] == '#') ? `/cssParent/${themePath}` : `/css/${baseRendererPath}${baseThemePath}`; return ( <> diff --git a/client/homebrew/pages/printPage/printPage.jsx b/client/homebrew/pages/printPage/printPage.jsx index cfd3c2318..d9ff2ca1a 100644 --- a/client/homebrew/pages/printPage/printPage.jsx +++ b/client/homebrew/pages/printPage/printPage.jsx @@ -117,7 +117,7 @@ const PrintPage = createClass({ baseRendererPath += '/'; } - const staticOrUserParent = this.state.brew.theme[0] == '#' ? `/cssParent/${themePath}` : `/css/${baseRendererPath}${baseThemePath}`; + const staticOrUserParent = (this.state.brew.theme && this.state.brew?.theme[0] == '#') ? `/cssParent/${themePath}` : `/css/${baseRendererPath}${baseThemePath}`; return
diff --git a/server/homebrew.api.js b/server/homebrew.api.js index b2f5f941c..af5ef259e 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -82,8 +82,7 @@ const api = { } }; - const brews = await HomebrewModel.getByUser(username, true, fields, { tags: { $in: ['theme', 'Theme', 'type:theme', 'type:Theme'] }, editId: { $ne: id } }) //lean() converts results to JSObjects - .catch((error)=>{throw 'Can not find brews';}); + const brews = await HomebrewModel.getByUser(username, true, fields, { tags: { $in: ['theme', 'Theme', 'type:theme', 'type:Theme'] }, editId: { $ne: id } }); for await (const brew of brews) { userThemes.Brew[`#${brew.editId}`] = { @@ -150,7 +149,8 @@ const api = { throw { name: 'BrewLoad Error', message: 'Brew not found', status: 404, HBErrorCode: '05', accessType: accessType, brewId: id }; } - const userID = req?.account?.username && (accessType === 'edit') ? req.account.username : stub.authors[0]; + const mainAuthor = stub.authors ? stub.authors[0] : ''; + const userID = req?.account?.username && (accessType === 'edit') ? req.account.username : mainAuthor; // Clean up brew: fill in missing fields with defaults / fix old invalid values const userThemes = accessType != 'themes' ? await api.getUsersBrewThemes(userID, id, req, res, next) : {}; diff --git a/server/homebrew.api.spec.js b/server/homebrew.api.spec.js index c82ce5227..c0c2619a2 100644 --- a/server/homebrew.api.spec.js +++ b/server/homebrew.api.spec.js @@ -45,8 +45,9 @@ describe('Tests for api', ()=>{ model.mockImplementation((brew)=>modelBrew(brew)); res = { - status : jest.fn(()=>res), - send : jest.fn(()=>{}) + status : jest.fn(()=>res), + send : jest.fn(()=>{}), + setHeader : jest.fn(()=>{}) }; api = require('./homebrew.api'); @@ -611,7 +612,7 @@ brew`); }; api.getStaticTheme(req, res); const sent = res.send.mock.calls[0][0]; - expect(sent).toBe('@import /themes/V3/5ePHB/style.css\n'); + expect(sent).toBe('@import url("/themes/V3/5ePHB/style.css");\n/* Static Theme 5e PHB */\n'); expect(res.status).toHaveBeenCalledWith(200); }); it('should return an import of the theme including a parent.', async ()=>{ @@ -623,7 +624,7 @@ brew`); }; api.getStaticTheme(req, res); const sent = res.send.mock.calls[0][0]; - expect(sent).toBe('@import /api/css/V3/5ePHB\n@import /themes/V3/5eDMG/style.css\n'); + expect(sent).toBe('@import url("/css/V3/5ePHB");\n/* Static Theme 5e PHB */\n@import url("/themes/V3/5eDMG/style.css");\n/* Static Theme 5e DMG */\n'); expect(res.status).toHaveBeenCalledWith(200); }); it('should fail for an invalid static theme.', async()=>{