From f95a2f646b1b070984d7f970e5b35fcea2ac6c70 Mon Sep 17 00:00:00 2001 From: Joan Date: Tue, 17 Apr 2018 13:38:40 +0200 Subject: [PATCH] Refactor back-end unit test + helpers --- e2e/helpers/components_selectors.js | 3 ++- e2e/helpers/selectors.js | 8 +++---- .../client/specs/getAverageInvoiced.spec.js | 2 +- .../methods/client/specs/getMana.spec.js | 2 +- .../methods/ticket/specs/get-volume.spec.js | 21 +++++++++++-------- .../helpers.js => test-helpers/rawSql.js} | 2 +- 6 files changed, 21 insertions(+), 17 deletions(-) rename services/loopback/common/{methods/client/specs/helpers.js => test-helpers/rawSql.js} (83%) diff --git a/e2e/helpers/components_selectors.js b/e2e/helpers/components_selectors.js index 7aae5042c..ae4b9a481 100644 --- a/e2e/helpers/components_selectors.js +++ b/e2e/helpers/components_selectors.js @@ -14,5 +14,6 @@ export default { vnAutocomplete: 'vn-autocomplete', vnCheck: 'vn-check', vnIconButton: 'vn-icon-button', - vnItemSummary: 'vn-item-summary > vn-card > div > vn-vertical' + vnItemSummary: 'vn-item-summary > vn-card > div > vn-vertical', + vnLabelValue: 'vn-label-value' }; diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 7e846c609..44f145bb7 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -264,11 +264,11 @@ export default { submitBotanicalButton: `${components.vnSubmit}` }, itemSummary: { - basicData: `${components.vnItemSummary} > vn-horizontal:nth-child(1) > vn-one:nth-child(2) > vn-vertical > p:nth-child(2)`, + basicData: `${components.vnItemSummary} > vn-horizontal:nth-child(1) > vn-one:nth-child(2) > vn-vertical`, vat: `${components.vnItemSummary} > vn-horizontal:nth-child(1) > vn-one:nth-child(3) > vn-vertical > p`, - tags: `${components.vnItemSummary} > vn-horizontal:nth-child(2) > vn-one:nth-child(1) > p`, - niche: `${components.vnItemSummary} > vn-horizontal:nth-child(2) > vn-one:nth-child(2) > vn-vertical > p:nth-child(2)`, - botanical: `${components.vnItemSummary} > vn-horizontal:nth-child(2) > vn-one:nth-child(3) > vn-vertical > p`, + tags: `${components.vnItemSummary} > vn-horizontal:nth-child(2) > vn-one:nth-child(1) > vn-vertical:nth-child(1) > vn-label-value:nth-child(2)`, + niche: `${components.vnItemSummary} > vn-horizontal:nth-child(2) > vn-one:nth-child(2) > vn-vertical > vn-label-value:nth-child(2)`, + botanical: `${components.vnItemSummary} > vn-horizontal:nth-child(2) > vn-one:nth-child(3) > vn-vertical > vn-label-value:nth-child(2)`, barcode: `${components.vnItemSummary} > vn-horizontal:nth-child(2) > vn-one:nth-child(4) > vn-vertical > p` }, ticketsIndex: { diff --git a/services/loopback/common/methods/client/specs/getAverageInvoiced.spec.js b/services/loopback/common/methods/client/specs/getAverageInvoiced.spec.js index 46072461a..0775423e0 100644 --- a/services/loopback/common/methods/client/specs/getAverageInvoiced.spec.js +++ b/services/loopback/common/methods/client/specs/getAverageInvoiced.spec.js @@ -1,5 +1,5 @@ const getAverageInvoiced = require('../getAverageInvoiced'); -const {rawSql} = require('./helpers'); +const {rawSql} = require('../../../test-helpers/rawSql'); const model = { remoteMethod: () => {} }; diff --git a/services/loopback/common/methods/client/specs/getMana.spec.js b/services/loopback/common/methods/client/specs/getMana.spec.js index f9b634c62..942eaaca0 100644 --- a/services/loopback/common/methods/client/specs/getMana.spec.js +++ b/services/loopback/common/methods/client/specs/getMana.spec.js @@ -1,5 +1,5 @@ const getMana = require('../getMana'); -const {rawSql} = require('./helpers'); +const {rawSql} = require('../../../test-helpers/rawSql'); const model = { remoteMethod: () => {} }; diff --git a/services/loopback/common/methods/ticket/specs/get-volume.spec.js b/services/loopback/common/methods/ticket/specs/get-volume.spec.js index c45421e2a..dcb01ac7f 100644 --- a/services/loopback/common/methods/ticket/specs/get-volume.spec.js +++ b/services/loopback/common/methods/ticket/specs/get-volume.spec.js @@ -1,16 +1,19 @@ const getVolume = require('../get-volume'); +const {rawSql} = require('../../../test-helpers/rawSql'); +const model = { + remoteMethod: () => {} +}; -describe('client getVolume()', () => { +rawSql(model); +getVolume(model); + +describe('ticket getVolume()', () => { it('should call the getVolume method', done => { let ticketFk = 1; - let self = jasmine.createSpyObj('self', ['remoteMethod', 'rawSql']); - self.rawSql.and.returnValue(Promise.resolve([{volumeData: 100}])); - getVolume(self); - - self.getVolume(ticketFk) - .then(result => { - expect(result).toEqual([{volumeData: 100}]); + model.getVolume(ticketFk) + .then(response => { + expect(response[0][0].m3_total).toEqual(0.008); done(); }); }); -}); +}); \ No newline at end of file diff --git a/services/loopback/common/methods/client/specs/helpers.js b/services/loopback/common/test-helpers/rawSql.js similarity index 83% rename from services/loopback/common/methods/client/specs/helpers.js rename to services/loopback/common/test-helpers/rawSql.js index 56034b206..880520321 100644 --- a/services/loopback/common/methods/client/specs/helpers.js +++ b/services/loopback/common/test-helpers/rawSql.js @@ -1,6 +1,6 @@ module.exports.rawSql = Self => { const DataSource = require('loopback-datasource-juggler').DataSource; - const rawSql = require('../../../../common/methods/vnModel/rawSql.js'); + const rawSql = require('../methods/vnModel/rawSql.js'); const dataSourceConfig = { connector: 'mysql', host: 'localhost',