From 5847b246efe82288da2b1140526ba4546fe1892b Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Tue, 13 Aug 2024 22:05:03 +1200 Subject: [PATCH] Add getCSS test --- server/homebrew.api.spec.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/server/homebrew.api.spec.js b/server/homebrew.api.spec.js index 5f1739b97..287e68ce4 100644 --- a/server/homebrew.api.spec.js +++ b/server/homebrew.api.spec.js @@ -916,4 +916,31 @@ brew`); expect(saved.googleId).toEqual(brew.googleId); }); }); + describe('Get CSS tests', ()=>{ + it('should return CSS for a brew', 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 })); + api.getId = jest.fn(()=>({ id: '1', googleId: undefined })); + model.get = jest.fn(()=>toBrewPromise(testBrew)); + + 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' }); + }); + }); });