mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-29 22:02:46 +00:00
Consolidate and add theme parent walking
This consolidates the style/theme endpoint to a singular method, adds interpretation of static themes, and allow parent theme recursion. I am not 100% sure this will order styles correctly.
This commit is contained in:
@@ -569,64 +569,8 @@ brew`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getBrewTheme', ()=>{
|
||||
it('should collect parent theme and brew style', async ()=>{
|
||||
const toBrewPromise = (brew)=>new Promise((res)=>res({ toObject: ()=>brew }));
|
||||
model.get = jest.fn(()=>toBrewPromise({ title: 'test brew', style: 'I Have a style!' }));
|
||||
const brewResults = {
|
||||
authors : [],
|
||||
createdAt : undefined,
|
||||
description : '',
|
||||
editId : undefined,
|
||||
gDrive : false,
|
||||
lang : 'en',
|
||||
pageCount : 1,
|
||||
published : false,
|
||||
renderer : 'legacy',
|
||||
shareId : undefined,
|
||||
style : 'I Have a style!',
|
||||
systems : [],
|
||||
tags : [],
|
||||
text : '',
|
||||
theme : '5ePHB',
|
||||
thumbnail : '',
|
||||
title : 'test brew',
|
||||
trashed : false,
|
||||
updatedAt : undefined,
|
||||
views : 0
|
||||
};
|
||||
const fn = api.getBrew('share', true);
|
||||
const req = { brew: {} };
|
||||
const next = jest.fn();
|
||||
await fn(req, null, next);
|
||||
|
||||
api.getBrewTheme(req, res);
|
||||
const sent = res.send.mock.calls[0][0];
|
||||
expect(req.brew).toStrictEqual(brewResults);
|
||||
expect(res.status).toHaveBeenCalledWith(200);
|
||||
expect(sent.parent).toBe('5ePHB');
|
||||
expect(sent.theme).toBe('I Have a style!');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getBrewAsThemeCSS', ()=>{
|
||||
it('should collect the brew style - returning as css', async ()=>{
|
||||
const toBrewPromise = (brew)=>new Promise((res)=>res({ toObject: ()=>brew }));
|
||||
model.get = jest.fn(()=>toBrewPromise({ title: 'test brew', style: 'I Have a style!' }));
|
||||
const fn = api.getBrew('share', true);
|
||||
const req = { brew: {} };
|
||||
const next = jest.fn();
|
||||
await fn(req, null, next);
|
||||
|
||||
api.getBrewThemeAsCSS(req, res);
|
||||
const sent = res.send.mock.calls[0][0];
|
||||
expect(sent).toBe('I Have a style!');
|
||||
expect(res.status).toHaveBeenCalledWith(200);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getBrewThemeWithCSS', ()=>{
|
||||
it('should collect parent theme and brew style - returning as css with parent imported.', async ()=>{
|
||||
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', style: 'I Have a style!' }));
|
||||
const fn = api.getBrew('share', true);
|
||||
@@ -636,11 +580,67 @@ brew`);
|
||||
|
||||
api.getBrewThemeWithCSS(req, res);
|
||||
const sent = res.send.mock.calls[0][0];
|
||||
expect(sent).toBe(`@import /themes/V3/5ePHB/styles.css\n\nI Have a style!`);
|
||||
expect(sent).toBe(`// From Theme: test brew\n\n@import /api/css/V3/5ePHB/styles.css\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', theme: '#IamATheme', style: 'I Have a style!' }));
|
||||
const fn = api.getBrew('share', true);
|
||||
const req = { brew: {} };
|
||||
const next = jest.fn();
|
||||
await fn(req, null, next);
|
||||
|
||||
api.getBrewThemeWithCSS(req, res);
|
||||
const sent = res.send.mock.calls[0][0];
|
||||
expect(sent).toBe(`// From Theme: test brew\n\n@import /api/css/IamATheme\n\nI Have a style!`);
|
||||
expect(res.status).toHaveBeenCalledWith(200);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getStaticTheme', ()=>{
|
||||
it('should return an import of the theme without including a parent.', async ()=>{
|
||||
const req = {
|
||||
params : {
|
||||
engine : 'V3',
|
||||
id : '5ePHB'
|
||||
}
|
||||
};
|
||||
api.getStaticTheme(req, res);
|
||||
const sent = res.send.mock.calls[0][0];
|
||||
expect(sent).toBe('@import /themes/V3/5ePHB\n');
|
||||
expect(res.status).toHaveBeenCalledWith(200);
|
||||
});
|
||||
it('should return an import of the theme including a parent.', async ()=>{
|
||||
const req = {
|
||||
params : {
|
||||
engine : 'V3',
|
||||
id : '5eDMG'
|
||||
}
|
||||
};
|
||||
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\n');
|
||||
expect(res.status).toHaveBeenCalledWith(200);
|
||||
});
|
||||
it('should fail for an invalid static theme.', async()=>{
|
||||
const req = {
|
||||
params : {
|
||||
engine : 'V3',
|
||||
id : '5eDMGGGG'
|
||||
}
|
||||
};
|
||||
api.getStaticTheme(req, res);
|
||||
const sent = res.send.mock.calls[0][0];
|
||||
expect(sent).toBe('Invalid Theme - Engine: 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' }; });
|
||||
|
||||
Reference in New Issue
Block a user