From b9599829111e308fd9da3ec5af61a85c82061e8c Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Thu, 19 Apr 2018 15:48:19 +0200 Subject: [PATCH] #192 item clone test CR Joan --- .../item/common/models/specs/item.spec.js | 11 ------- .../common/methods/item/specs/clone.spec.js | 33 +++++++++---------- 2 files changed, 16 insertions(+), 28 deletions(-) delete mode 100644 services/item/common/models/specs/item.spec.js diff --git a/services/item/common/models/specs/item.spec.js b/services/item/common/models/specs/item.spec.js deleted file mode 100644 index f78c1f066..000000000 --- a/services/item/common/models/specs/item.spec.js +++ /dev/null @@ -1,11 +0,0 @@ -const app = require('../../../../item/server/server'); -let ctx = {isNewInstance: true, instance: {}}; -describe('Item availableId()', () => { - it('should define ctx.instance.id with the expected id', async() => { - let Item = app.models.Item; - - await Item.availableId(ctx); - - expect(ctx.instance.id).toEqual(6); - }); -}); diff --git a/services/loopback/common/methods/item/specs/clone.spec.js b/services/loopback/common/methods/item/specs/clone.spec.js index f91f1b1e3..cad4edf31 100644 --- a/services/loopback/common/methods/item/specs/clone.spec.js +++ b/services/loopback/common/methods/item/specs/clone.spec.js @@ -1,22 +1,21 @@ -const clone = require('../clone'); -const model = { - remoteMethod: () => {} -}; -let Loopback = require('../../../test-helpers/loopback'); -Loopback.init(model); +const app = require(`${servicesDir}/item/server/server`); -Loopback.rawSql(model); -clone(model); - -// disabled test while loopback findOne method isnt extended to model yet. describe('item clone()', () => { - it('should', () => { + let nextItemId; - // let itemFk = 1; - // model.clone(itemFk) - // .then(response => { - // expect(response).toEqual('whatever'); - // done(); - // }); + 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', async() => { + let itemFk = 1; + let result = await app.models.Item.clone(itemFk); + + expect(result).toEqual(nextItemId); }); });