#555 item model back unit test

This commit is contained in:
Carlos Jimenez 2018-08-20 10:06:00 +02:00
parent 065f2126bf
commit f942732d48
2 changed files with 23 additions and 0 deletions

View File

@ -26,6 +26,7 @@ module.exports = Self => {
let newId = await Self.rawSql(query);
ctx.instance.id = newId[0].id;
return ctx.instance.id;
} catch (e) {
throw new UserError(e);
}

View File

@ -0,0 +1,22 @@
const app = require(`${servicesDir}/ticket/server/server`);
describe('loopback model Item', () => {
describe('availableId()', () => {
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 return the next available id for an item', async() => {
let context = {isNewInstance: true, instance: {}};
let result = await app.models.Item.availableId(context);
expect(result).toEqual(nextItemId);
});
});
});