5bb26cc53a
Signed-off-by: mikesir87 <mikesir87@gmail.com> Imported from dockersamples/101-tutorial, removed other languages for now, and replaced PWD references with Docker Desktop.
31 lines
873 B
JavaScript
31 lines
873 B
JavaScript
const db = require('../../src/persistence');
|
|
const addItem = require('../../src/routes/addItem');
|
|
const ITEM = { id: 12345 };
|
|
const uuid = require('uuid/v4');
|
|
|
|
jest.mock('uuid/v4', () => jest.fn());
|
|
|
|
jest.mock('../../src/persistence', () => ({
|
|
removeItem: jest.fn(),
|
|
storeItem: jest.fn(),
|
|
getItem: jest.fn(),
|
|
}));
|
|
|
|
test('it stores item correctly', async () => {
|
|
const id = 'something-not-a-uuid';
|
|
const name = 'A sample item';
|
|
const req = { body: { name } };
|
|
const res = { send: jest.fn() };
|
|
|
|
uuid.mockReturnValue(id);
|
|
|
|
await addItem(req, res);
|
|
|
|
const expectedItem = { id, name, completed: false };
|
|
|
|
expect(db.storeItem.mock.calls.length).toBe(1);
|
|
expect(db.storeItem.mock.calls[0][0]).toEqual(expectedItem);
|
|
expect(res.send.mock.calls[0].length).toBe(1);
|
|
expect(res.send.mock.calls[0][0]).toEqual(expectedItem);
|
|
});
|