diff options
Diffstat (limited to 'app/spec/routes/updateItem.spec.js')
-rw-r--r-- | app/spec/routes/updateItem.spec.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/spec/routes/updateItem.spec.js b/app/spec/routes/updateItem.spec.js new file mode 100644 index 0000000..640e56e --- /dev/null +++ b/app/spec/routes/updateItem.spec.js @@ -0,0 +1,33 @@ +const db = require('../../src/persistence'); +const updateItem = require('../../src/routes/updateItem'); +const ITEM = { id: 12345 }; + +jest.mock('../../src/persistence', () => ({ + getItem: jest.fn(), + updateItem: jest.fn(), +})); + +test('it updates items correctly', async () => { + const req = { + params: { id: 1234 }, + body: { name: 'New title', completed: false }, + }; + const res = { send: jest.fn() }; + + db.getItem.mockReturnValue(Promise.resolve(ITEM)); + + await updateItem(req, res); + + expect(db.updateItem.mock.calls.length).toBe(1); + expect(db.updateItem.mock.calls[0][0]).toBe(req.params.id); + expect(db.updateItem.mock.calls[0][1]).toEqual({ + name: 'New title', + completed: false, + }); + + expect(db.getItem.mock.calls.length).toBe(1); + expect(db.getItem.mock.calls[0][0]).toBe(req.params.id); + + expect(res.send.mock.calls[0].length).toBe(1); + expect(res.send.mock.calls[0][0]).toEqual(ITEM); +}); |