mirror of
https://github.com/docker/getting-started-app.git
synced 2024-11-17 07:51:30 -05:00
31 lines
884 B
JavaScript
31 lines
884 B
JavaScript
const db = require('../../src/persistence');
|
|
const addItem = require('../../src/routes/addItem');
|
|
const ITEM = { id: 12345 };
|
|
const {v4 : uuid} = require('uuid');
|
|
|
|
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);
|
|
});
|