2018-04-19 13:48:19 +00:00
|
|
|
const app = require(`${servicesDir}/item/server/server`);
|
2018-04-18 12:37:17 +00:00
|
|
|
|
|
|
|
describe('item clone()', () => {
|
2018-04-19 13:48:19 +00:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
2018-08-06 10:00:29 +00:00
|
|
|
it('should clone the given item and it should have the expected id', async() => {
|
2018-04-19 13:48:19 +00:00
|
|
|
let itemFk = 1;
|
|
|
|
let result = await app.models.Item.clone(itemFk);
|
2018-04-18 12:42:30 +00:00
|
|
|
|
2018-04-19 13:48:19 +00:00
|
|
|
expect(result).toEqual(nextItemId);
|
2018-04-18 12:37:17 +00:00
|
|
|
});
|
2018-08-06 10:00:29 +00:00
|
|
|
|
|
|
|
it('should attempt to clone the given item but give an error as it doesnt exist', async() => {
|
|
|
|
try {
|
|
|
|
let itemFk = 999;
|
|
|
|
await app.models.Item.clone(itemFk);
|
|
|
|
} catch (error) {
|
|
|
|
expect(error.toString()).toContain('Cannot convert undefined or null to object');
|
|
|
|
}
|
|
|
|
});
|
2018-04-18 12:37:17 +00:00
|
|
|
});
|