mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 16:22:44 +00:00
Fix Jest issues I was able to understand
This commit is contained in:
@@ -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 (
|
||||
<>
|
||||
|
||||
@@ -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 <div>
|
||||
<Meta name='robots' content='noindex, nofollow' />
|
||||
|
||||
@@ -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) : {};
|
||||
|
||||
@@ -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()=>{
|
||||
|
||||
Reference in New Issue
Block a user