0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 20:42:43 +00:00

Remove unused CSS endpoints in favor of #3075

Now that we have a dedicated /theme/ route for the recursive theming, the CSS endpoint can be simpler for only getting the `style` of a single brew. #3075 already has this simpler version, but no testing, so I have copied this into a comment there for implementation when it is ready.
This commit is contained in:
Trevor Buckner
2024-07-28 17:53:25 -04:00
parent 2870caaae6
commit ee9f2c8c83
2 changed files with 0 additions and 84 deletions

View File

@@ -306,31 +306,6 @@ const api = {
res.setHeader('Content-Type', 'application/json');
return res.status(200).send(returnObj);
},
//Return CSS for a brew theme, with @include endpoint for its parent theme if any
getBrewThemeCSS : async (req, res)=>{
const brew = req.brew;
splitTextStyleAndMetadata(brew);
res.setHeader('Content-Type', 'text/css');
let rendererPath = '';
if(isStaticTheme(req.brew.renderer, req.brew.theme)) //Check if parent is staticBrew
rendererPath = `${_.upperFirst(req.brew.renderer)}/`;
const parentThemeImport = `@import url(\"/css/${rendererPath}${req.brew.theme}\");\n\n`;
const themeLocationComment = `/* From Brew: ${req.protocol}://${req.get('host')}/share/${req.brew.shareId} */\n\n`;
return res.status(200).send(`${parentThemeImport}${themeLocationComment}${req.brew.style}`);
},
//Return CSS for a static theme, with @include endpoint for its parent theme if any
getStaticThemeCSS : async(req, res)=>{
if(!isStaticTheme(req.params.renderer, req.params.id))
res.status(404).send(`Invalid Theme - Renderer: ${req.params.renderer}, Name: ${req.params.id}`);
else {
res.setHeader('Content-Type', 'text/css');
res.setHeader('Cache-Control', 'public, max-age: 43200, must-revalidate');
const themeParent = Themes[req.params.renderer][req.params.id].baseTheme;
const parentThemeImport = themeParent ? `@import url(\"/css/${req.params.renderer}/${themeParent}\");\n/* Static Theme ${Themes[req.params.renderer][themeParent].name} */\n` : '';
return res.status(200).send(`${parentThemeImport}@import url(\"/themes/${req.params.renderer}/${req.params.id}/style.css\");\n/* Static Theme ${Themes[req.params.renderer][req.params.id].name} */\n`);
}
},
updateBrew : async (req, res)=>{
// Initialize brew from request and body, destructure query params, and set the initial value for the after-save method
const brewFromClient = api.excludePropsFromUpdate(req.body);

View File

@@ -696,65 +696,6 @@ brew`);
});
});
describe('getBrewThemeWithStaticParent', ()=>{
it('should collect parent theme and brew style - returning as css with static parent imported.', async ()=>{
const toBrewPromise = (brew)=>new Promise((res)=>res({ toObject: ()=>brew }));
model.get = jest.fn(()=>toBrewPromise({ title: 'test brew', renderer: 'V3', theme: '5eDMG', shareId: 'iAmAUserTheme', style: 'I Have a style!' }));
const fn = api.getBrew('share', true);
const req = { brew: {}, get: ()=>{return 'localhost';}, protocol: 'https' };
const next = jest.fn();
await fn(req, null, next);
api.getBrewThemeCSS(req, res);
const sent = res.send.mock.calls[0][0];
expect(sent).toBe(`@import url("/css/V3/5eDMG");\n\n/* From Brew: https://localhost/share/iAmAUserTheme */\n\nI Have a style!`);
expect(res.status).toHaveBeenCalledWith(200);
});
});
describe('getBrewThemeWithUserParent', ()=>{
it('should collect parent theme and brew style - returning as css with user-theme parent imported.', async ()=>{
const toBrewPromise = (brew)=>new Promise((res)=>res({ toObject: ()=>brew }));
model.get = jest.fn(()=>toBrewPromise({ title: 'test brew', renderer: 'V3', shareId: 'iAmAUserTheme', theme: 'IamATheme', style: 'I Have a style!' }));
const fn = api.getBrew('share', true);
const req = { brew: {}, get: ()=>{return 'localhost';}, protocol: 'https' };
const next = jest.fn();
await fn(req, null, next);
api.getBrewThemeCSS(req, res);
const sent = res.send.mock.calls[0][0];
expect(sent).toBe(`@import url("/css/IamATheme");\n\n/* From Brew: https://localhost/share/iAmAUserTheme */\n\nI Have a style!`);
expect(res.status).toHaveBeenCalledWith(200);
});
});
describe('getStaticThemeCSS', ()=>{
it('should return an import of the theme including a parent.', async ()=>{
const req = {
params : {
renderer : 'V3',
id : '5eDMG'
}
};
api.getStaticThemeCSS(req, res);
const sent = res.send.mock.calls[0][0];
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()=>{
const req = {
params : {
renderer : 'V3',
id : '5eDMGGGG'
}
};
api.getStaticThemeCSS(req, res);
const sent = res.send.mock.calls[0][0];
expect(sent).toBe('Invalid Theme - Renderer: V3, Name: 5eDMGGGG');
expect(res.status).toHaveBeenCalledWith(404);
});
});
describe('deleteBrew', ()=>{
it('should handle case where fetching the brew returns an error', async ()=>{
api.getBrew = jest.fn(()=>async ()=>{ throw { message: 'err', HBErrorCode: '02' }; });