const app = require(`${servicesDir}/item/server/server`); describe('item clone()', () => { let nextItemId; beforeEach(async() => { let query = `SELECT i1.id + 1 as id FROM vn.item i1 LEFT JOIN vn.item i2 ON i1.id + 1 = i2.id WHERE i2.id IS NULL ORDER BY i1.id LIMIT 1`; [nextAvailableId] = await app.models.Item.rawSql(query); nextItemId = nextAvailableId.id; }); it('should clone the given item and it should have the expected id', async() => { let itemFk = 1; let result = await app.models.Item.clone(itemFk); expect(result).toEqual(nextItemId); }); it('should attempt to clone the given item but give an error as it doesnt exist', async() => { let error; let itemFk = 999; await app.models.Item.clone(itemFk) .catch(e => { expect(e.message).toContain('Cannot convert undefined or null to object'); error = e; }); expect(error).toBeDefined(); }); });