mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-04 12:32:39 +00:00
reorder one test
This commit is contained in:
@@ -830,6 +830,84 @@ brew`);
|
|||||||
status : 422 });
|
status : 422 });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('updateBrew', ()=>{
|
||||||
|
it('should return error on version mismatch', async ()=>{
|
||||||
|
const brewFromClient = { version: 1 };
|
||||||
|
const brewFromServer = { version: 1000, text: '' };
|
||||||
|
|
||||||
|
const req = {
|
||||||
|
brew : brewFromServer,
|
||||||
|
body : brewFromClient
|
||||||
|
};
|
||||||
|
|
||||||
|
await api.updateBrew(req, res);
|
||||||
|
|
||||||
|
expect(res.status).toHaveBeenCalledWith(409);
|
||||||
|
expect(res.send).toHaveBeenCalledWith('{\"message\":\"The server version is out of sync with the saved brew. Please save your changes elsewhere, refresh, and try again.\"}');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return error on hash mismatch', async ()=>{
|
||||||
|
const brewFromClient = { version: 1, hash: '1234' };
|
||||||
|
const brewFromServer = { version: 1, text: 'test' };
|
||||||
|
|
||||||
|
const req = {
|
||||||
|
brew : brewFromServer,
|
||||||
|
body : brewFromClient
|
||||||
|
};
|
||||||
|
|
||||||
|
await api.updateBrew(req, res);
|
||||||
|
|
||||||
|
expect(req.brew.hash).toBe('098f6bcd4621d373cade4e832627b4f6');
|
||||||
|
expect(res.status).toHaveBeenCalledWith(409);
|
||||||
|
expect(res.send).toHaveBeenCalledWith('{\"message\":\"The server copy is out of sync with the saved brew. Please save your changes elsewhere, refresh, and try again.\"}');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Commenting this one out for now, since we are no longer throwing this error while we monitor
|
||||||
|
// it('should return error on applying patches', async ()=>{
|
||||||
|
// const brewFromClient = { version: 1, hash: '098f6bcd4621d373cade4e832627b4f6', patches: 'not a valid patch string' };
|
||||||
|
// const brewFromServer = { version: 1, text: 'test', title: 'Test Title', description: 'Test Description' };
|
||||||
|
|
||||||
|
// const req = {
|
||||||
|
// brew : brewFromServer,
|
||||||
|
// body : brewFromClient,
|
||||||
|
// };
|
||||||
|
|
||||||
|
// let err;
|
||||||
|
// try {
|
||||||
|
// await api.updateBrew(req, res);
|
||||||
|
// } catch (e) {
|
||||||
|
// err = e;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// expect(err).toEqual(Error('Invalid patch string: not a valid patch string'));
|
||||||
|
// });
|
||||||
|
|
||||||
|
it('should save brew, no ID', async ()=>{
|
||||||
|
const brewFromClient = { version: 1, hash: '098f6bcd4621d373cade4e832627b4f6', patches: '' };
|
||||||
|
const brewFromServer = { version: 1, text: 'test', title: 'Test Title', description: 'Test Description' };
|
||||||
|
|
||||||
|
model.save = jest.fn((brew)=>{return brew;});
|
||||||
|
|
||||||
|
const req = {
|
||||||
|
brew : brewFromServer,
|
||||||
|
body : brewFromClient,
|
||||||
|
query : { saveToGoogle: false, removeFromGoogle: false }
|
||||||
|
};
|
||||||
|
|
||||||
|
await api.updateBrew(req, res);
|
||||||
|
|
||||||
|
expect(res.status).toHaveBeenCalledWith(200);
|
||||||
|
expect(res.send).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
_id : '1',
|
||||||
|
description : 'Test Description',
|
||||||
|
hash : '098f6bcd4621d373cade4e832627b4f6',
|
||||||
|
title : 'Test Title',
|
||||||
|
version : 2
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
describe('deleteBrewAuthor', ()=>{
|
describe('deleteBrewAuthor', ()=>{
|
||||||
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' }; });
|
||||||
@@ -875,7 +953,6 @@ brew`);
|
|||||||
expect(saved.authors).toEqual(['test']);
|
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);
|
||||||
@@ -1105,7 +1182,7 @@ brew`);
|
|||||||
expect(saved.googleId).toEqual(brew.googleId);
|
expect(saved.googleId).toEqual(brew.googleId);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Split Text, Style, and Metadata', ()=>{
|
describe('Split Text, Style, and Metadata', ()=>{
|
||||||
|
|
||||||
it('basic splitting', async ()=>{
|
it('basic splitting', async ()=>{
|
||||||
@@ -1159,83 +1236,5 @@ brew`);
|
|||||||
expect(testBrew.tags).toEqual(['tag a']);
|
expect(testBrew.tags).toEqual(['tag a']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('updateBrew', ()=>{
|
|
||||||
it('should return error on version mismatch', async ()=>{
|
|
||||||
const brewFromClient = { version: 1 };
|
|
||||||
const brewFromServer = { version: 1000, text: '' };
|
|
||||||
|
|
||||||
const req = {
|
|
||||||
brew : brewFromServer,
|
|
||||||
body : brewFromClient
|
|
||||||
};
|
|
||||||
|
|
||||||
await api.updateBrew(req, res);
|
|
||||||
|
|
||||||
expect(res.status).toHaveBeenCalledWith(409);
|
|
||||||
expect(res.send).toHaveBeenCalledWith('{\"message\":\"The server version is out of sync with the saved brew. Please save your changes elsewhere, refresh, and try again.\"}');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return error on hash mismatch', async ()=>{
|
|
||||||
const brewFromClient = { version: 1, hash: '1234' };
|
|
||||||
const brewFromServer = { version: 1, text: 'test' };
|
|
||||||
|
|
||||||
const req = {
|
|
||||||
brew : brewFromServer,
|
|
||||||
body : brewFromClient
|
|
||||||
};
|
|
||||||
|
|
||||||
await api.updateBrew(req, res);
|
|
||||||
|
|
||||||
expect(req.brew.hash).toBe('098f6bcd4621d373cade4e832627b4f6');
|
|
||||||
expect(res.status).toHaveBeenCalledWith(409);
|
|
||||||
expect(res.send).toHaveBeenCalledWith('{\"message\":\"The server copy is out of sync with the saved brew. Please save your changes elsewhere, refresh, and try again.\"}');
|
|
||||||
});
|
|
||||||
|
|
||||||
// Commenting this one out for now, since we are no longer throwing this error while we monitor
|
|
||||||
// it('should return error on applying patches', async ()=>{
|
|
||||||
// const brewFromClient = { version: 1, hash: '098f6bcd4621d373cade4e832627b4f6', patches: 'not a valid patch string' };
|
|
||||||
// const brewFromServer = { version: 1, text: 'test', title: 'Test Title', description: 'Test Description' };
|
|
||||||
|
|
||||||
// const req = {
|
|
||||||
// brew : brewFromServer,
|
|
||||||
// body : brewFromClient,
|
|
||||||
// };
|
|
||||||
|
|
||||||
// let err;
|
|
||||||
// try {
|
|
||||||
// await api.updateBrew(req, res);
|
|
||||||
// } catch (e) {
|
|
||||||
// err = e;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// expect(err).toEqual(Error('Invalid patch string: not a valid patch string'));
|
|
||||||
// });
|
|
||||||
|
|
||||||
it('should save brew, no ID', async ()=>{
|
|
||||||
const brewFromClient = { version: 1, hash: '098f6bcd4621d373cade4e832627b4f6', patches: '' };
|
|
||||||
const brewFromServer = { version: 1, text: 'test', title: 'Test Title', description: 'Test Description' };
|
|
||||||
|
|
||||||
model.save = jest.fn((brew)=>{return brew;});
|
|
||||||
|
|
||||||
const req = {
|
|
||||||
brew : brewFromServer,
|
|
||||||
body : brewFromClient,
|
|
||||||
query : { saveToGoogle: false, removeFromGoogle: false }
|
|
||||||
};
|
|
||||||
|
|
||||||
await api.updateBrew(req, res);
|
|
||||||
|
|
||||||
expect(res.status).toHaveBeenCalledWith(200);
|
|
||||||
expect(res.send).toHaveBeenCalledWith(
|
|
||||||
expect.objectContaining({
|
|
||||||
_id : '1',
|
|
||||||
description : 'Test Description',
|
|
||||||
hash : '098f6bcd4621d373cade4e832627b4f6',
|
|
||||||
title : 'Test Title',
|
|
||||||
version : 2
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user