mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 16:22:44 +00:00
Add extra getCSS tests
This commit is contained in:
@@ -50,6 +50,7 @@ describe('Tests for api', ()=>{
|
||||
res = {
|
||||
status : jest.fn(()=>res),
|
||||
send : jest.fn(()=>{}),
|
||||
set : jest.fn(()=>{}),
|
||||
setHeader : jest.fn(()=>{})
|
||||
};
|
||||
|
||||
@@ -917,7 +918,7 @@ brew`);
|
||||
});
|
||||
});
|
||||
describe('Get CSS tests', ()=>{
|
||||
it('should return CSS for a brew', async ()=>{
|
||||
it('get CSS - successful', async ()=>{
|
||||
const testBrew = { title: 'test brew', text: '```css\n\nI Have a style!\n````\n\n' };
|
||||
|
||||
const toBrewPromise = (brew)=>new Promise((res)=>res({ toObject: ()=>brew }));
|
||||
@@ -926,21 +927,54 @@ brew`);
|
||||
|
||||
const fn = api.getBrew('share', true);
|
||||
const req = { brew: {} };
|
||||
const res = {
|
||||
status : jest.fn(()=>res),
|
||||
send : jest.fn(()=>{}),
|
||||
set : jest.fn(()=>{}),
|
||||
setHeader : jest.fn(()=>{})
|
||||
};
|
||||
const next = jest.fn();
|
||||
await fn(req, null, next);
|
||||
await api.getCSS(req, res);
|
||||
|
||||
expect(req.brew).toEqual(testBrew);
|
||||
expect(req.brew).toHaveProperty('style', '\nI Have a style!\n');
|
||||
expect(next).toHaveBeenCalled();
|
||||
expect(api.getId).toHaveBeenCalledWith(req);
|
||||
expect(model.get).toHaveBeenCalledWith({ shareId: '1' });
|
||||
expect(res.set).toHaveBeenCalledWith({
|
||||
'Cache-Control' : 'no-cache',
|
||||
'Content-Type' : 'text/css'
|
||||
});
|
||||
});
|
||||
|
||||
it('get CSS - no style in brew', async ()=>{
|
||||
const testBrew = { title: 'test brew', text: 'I don\'t have a style!' };
|
||||
|
||||
const toBrewPromise = (brew)=>new Promise((res)=>res({ toObject: ()=>brew }));
|
||||
api.getId = jest.fn(()=>({ id: '1', googleId: undefined }));
|
||||
model.get = jest.fn(()=>toBrewPromise(testBrew));
|
||||
|
||||
const fn = api.getBrew('share', true);
|
||||
const req = { brew: {} };
|
||||
const next = jest.fn();
|
||||
await fn(req, null, next);
|
||||
await api.getCSS(req, res);
|
||||
|
||||
expect(req.brew).toEqual(testBrew);
|
||||
expect(req.brew).toHaveProperty('style');
|
||||
expect(res.status).toHaveBeenCalledWith(404);
|
||||
expect(res.send).toHaveBeenCalledWith('');
|
||||
});
|
||||
|
||||
it('get CSS - no brew', async ()=>{
|
||||
const testBrew = { };
|
||||
|
||||
const toBrewPromise = (brew)=>new Promise((res)=>res({ toObject: ()=>brew }));
|
||||
api.getId = jest.fn(()=>({ id: '1', googleId: undefined }));
|
||||
model.get = jest.fn(()=>toBrewPromise(testBrew));
|
||||
|
||||
const fn = api.getBrew('share', true);
|
||||
const req = { brew: {} };
|
||||
const next = jest.fn();
|
||||
await fn(req, null, next);
|
||||
await api.getCSS(req, res);
|
||||
|
||||
expect(req.brew).toEqual(testBrew);
|
||||
expect(req.brew).toHaveProperty('style');
|
||||
expect(res.status).toHaveBeenCalledWith(404);
|
||||
expect(res.send).toHaveBeenCalledWith('');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user