0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-04 14:42:40 +00:00

fix them?

This commit is contained in:
Víctor Losada Hernández
2025-05-24 22:43:06 +02:00
parent a7f8ff5212
commit 4ec6ea0f84

View File

@@ -765,8 +765,8 @@ brew`);
it('should handle case where fetching the brew returns an error', async ()=>{ it('should handle case where fetching the brew returns an error', async ()=>{
api.getBrew = jest.fn(()=>async ()=>{ throw { message: 'err', HBErrorCode: '02' }; }); api.getBrew = jest.fn(()=>async ()=>{ throw { message: 'err', HBErrorCode: '02' }; });
api.getId = jest.fn(()=>({ id: '1', googleId: '2' })); api.getId = jest.fn(()=>({ id: '1', googleId: '2' }));
model.deleteOne = jest.fn(async ()=>{}); model.deleteOne = jest.fn(async ()=>{ });
const next = jest.fn(()=>{}); const next = jest.fn();
await api.deleteBrew(null, null, next); await api.deleteBrew(null, null, next);
@@ -777,19 +777,25 @@ brew`);
it('should remove one author', async ()=>{ it('should remove one author', async ()=>{
const brew = { const brew = {
...hbBrew, ...hbBrew,
authors : ['test', 'test2'] _id : 'some-id',
authors : ['test', 'test2'],
markModified : markModifiedFunc,
save : saveFunc
}; };
api.getBrew = jest.fn(()=>async (req)=>{ api.getBrew = jest.fn(()=>async (req)=>{
req.brew = brew; req.brew = brew;
}); });
model.findOne = jest.fn(async ()=>modelBrew(brew)); model.findOne = jest.fn(async ()=>modelBrew(brew));
model.deleteOne = jest.fn(async ()=>{}); model.deleteOne = jest.fn(async ()=>{ });
const req = { const req = {
account : { username: 'test' }, account : { username: 'test' },
params : { author: 'test' } params : { author: 'test2' }
}; };
const res = { status: jest.fn(()=>res), send: jest.fn() };
await api.deleteAuthor(req, res); await api.deleteAuthor(req, res);
expect(api.getBrew).toHaveBeenCalled(); expect(api.getBrew).toHaveBeenCalled();
@@ -797,9 +803,10 @@ brew`);
expect(model.findOne).toHaveBeenCalled(); expect(model.findOne).toHaveBeenCalled();
expect(model.deleteOne).not.toHaveBeenCalled(); expect(model.deleteOne).not.toHaveBeenCalled();
expect(saveFunc).toHaveBeenCalled(); expect(saveFunc).toHaveBeenCalled();
expect(saved.authors).toEqual(['test2']); expect(saved.authors).toEqual(['test']);
}); });
}); });
describe('deleteGoogleBrew', ()=>{ describe('deleteGoogleBrew', ()=>{
it('should check auth and delete brew', async ()=>{ it('should check auth and delete brew', async ()=>{
const result = await api.deleteGoogleBrew({ username: 'test user' }, 'id', 'editId', res); const result = await api.deleteGoogleBrew({ username: 'test user' }, 'id', 'editId', res);