mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-10 07:02:39 +00:00
Add extra getCSS tests
This commit is contained in:
@@ -50,6 +50,7 @@ describe('Tests for api', ()=>{
|
|||||||
res = {
|
res = {
|
||||||
status : jest.fn(()=>res),
|
status : jest.fn(()=>res),
|
||||||
send : jest.fn(()=>{}),
|
send : jest.fn(()=>{}),
|
||||||
|
set : jest.fn(()=>{}),
|
||||||
setHeader : jest.fn(()=>{})
|
setHeader : jest.fn(()=>{})
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -917,7 +918,7 @@ brew`);
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('Get CSS tests', ()=>{
|
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 testBrew = { title: 'test brew', text: '```css\n\nI Have a style!\n````\n\n' };
|
||||||
|
|
||||||
const toBrewPromise = (brew)=>new Promise((res)=>res({ toObject: ()=>brew }));
|
const toBrewPromise = (brew)=>new Promise((res)=>res({ toObject: ()=>brew }));
|
||||||
@@ -926,21 +927,54 @@ brew`);
|
|||||||
|
|
||||||
const fn = api.getBrew('share', true);
|
const fn = api.getBrew('share', true);
|
||||||
const req = { brew: {} };
|
const req = { brew: {} };
|
||||||
const res = {
|
|
||||||
status : jest.fn(()=>res),
|
|
||||||
send : jest.fn(()=>{}),
|
|
||||||
set : jest.fn(()=>{}),
|
|
||||||
setHeader : jest.fn(()=>{})
|
|
||||||
};
|
|
||||||
const next = jest.fn();
|
const next = jest.fn();
|
||||||
await fn(req, null, next);
|
await fn(req, null, next);
|
||||||
await api.getCSS(req, res);
|
await api.getCSS(req, res);
|
||||||
|
|
||||||
expect(req.brew).toEqual(testBrew);
|
expect(req.brew).toEqual(testBrew);
|
||||||
expect(req.brew).toHaveProperty('style', '\nI Have a style!\n');
|
expect(req.brew).toHaveProperty('style', '\nI Have a style!\n');
|
||||||
expect(next).toHaveBeenCalled();
|
expect(res.set).toHaveBeenCalledWith({
|
||||||
expect(api.getId).toHaveBeenCalledWith(req);
|
'Cache-Control' : 'no-cache',
|
||||||
expect(model.get).toHaveBeenCalledWith({ shareId: '1' });
|
'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