From f39719cc460ccf8097f266c04334837f199f82ad Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 3 Jun 2020 14:46:58 +0200 Subject: [PATCH 1/5] 2281 - Added claim pickup checkbox --- e2e/helpers/selectors.js | 4 +-- e2e/paths/06-claim/01_basic_data.spec.js | 17 +++++++++++- e2e/paths/06-claim/04_claim_action.spec.js | 13 +++++++--- .../back/methods/claim/regularizeClaim.js | 23 +--------------- .../claim/back/methods/claim/updateClaim.js | 26 +++++++++++++++++-- .../back/methods/claim/updateClaimAction.js | 4 --- modules/claim/front/action/index.html | 5 ---- modules/claim/front/action/locale/es.yml | 3 +-- modules/claim/front/basic-data/index.html | 6 +++++ modules/claim/front/basic-data/locale/es.yml | 3 ++- 10 files changed, 62 insertions(+), 42 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index e8435eadf..5cd24cda5 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -585,6 +585,7 @@ export default { claimState: 'vn-claim-basic-data vn-autocomplete[ng-model="$ctrl.claim.claimStateFk"]', responsabilityInputRange: 'vn-range', observation: 'vn-textarea[ng-model="$ctrl.claim.observation"]', + hasToPickUpCheckbox: 'vn-claim-basic-data vn-check[ng-model="$ctrl.claim.hasToPickUp"]', saveButton: `button[type=submit]` }, claimDetail: { @@ -619,8 +620,7 @@ export default { firstLineDestination: 'vn-claim-action vn-tr:nth-child(1) vn-autocomplete[ng-model="saleClaimed.claimDestinationFk"]', secondLineDestination: 'vn-claim-action vn-tr:nth-child(2) vn-autocomplete[ng-model="saleClaimed.claimDestinationFk"]', firstDeleteLine: 'vn-claim-action vn-tr:nth-child(1) vn-icon-button[icon="delete"]', - isPaidWithManaCheckbox: 'vn-claim-action vn-check[ng-model="$ctrl.claim.isChargedToMana"]', - hasToPickUpCheckbox: 'vn-claim-action vn-check[ng-model="$ctrl.claim.hasToPickUp"]' + isPaidWithManaCheckbox: 'vn-claim-action vn-check[ng-model="$ctrl.claim.isChargedToMana"]' }, ordersIndex: { searchResult: 'vn-order-index vn-card > vn-table > div > vn-tbody > a.vn-tr', diff --git a/e2e/paths/06-claim/01_basic_data.spec.js b/e2e/paths/06-claim/01_basic_data.spec.js index a255188e2..ecf79ccf0 100644 --- a/e2e/paths/06-claim/01_basic_data.spec.js +++ b/e2e/paths/06-claim/01_basic_data.spec.js @@ -1,7 +1,7 @@ import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; -describe('Claim edit basic data path', () => { +fdescribe('Claim edit basic data path', () => { let browser; let page; @@ -34,6 +34,15 @@ describe('Claim edit basic data path', () => { await page.waitForState('claim.card.detail'); }); + it('should check the "Pick up" checkbox', async() => { + await page.reloadSection('claim.card.basicData'); + await page.waitToClick(selectors.claimBasicData.hasToPickUpCheckbox); + await page.waitToClick(selectors.claimBasicData.saveButton); + const message = await page.waitForSnackbar(); + + expect(message.type).toBe('success'); + }); + it('should confirm the claim state was edited', async() => { await page.reloadSection('claim.card.basicData'); await page.wait(selectors.claimBasicData.claimState); @@ -42,6 +51,12 @@ describe('Claim edit basic data path', () => { expect(result).toEqual('Gestionado'); }); + it('should confirm the "is paid with mana" and "Pick up" checkbox are checked', async() => { + const hasToPickUpCheckbox = await page.checkboxState(selectors.claimBasicData.hasToPickUpCheckbox); + + expect(hasToPickUpCheckbox).toBe('checked'); + }); + it('should confirm the claim observation was edited', async() => { const result = await page .waitToGetProperty(selectors.claimBasicData.observation, 'value'); diff --git a/e2e/paths/06-claim/04_claim_action.spec.js b/e2e/paths/06-claim/04_claim_action.spec.js index 67c936898..34a9c6102 100644 --- a/e2e/paths/06-claim/04_claim_action.spec.js +++ b/e2e/paths/06-claim/04_claim_action.spec.js @@ -72,19 +72,26 @@ describe('Claim action path', () => { expect(message.type).toBe('success'); }); - it('should check the "Pick up" checkbox', async() => { + /* it('should check the "Pick up" checkbox', async() => { await page.waitToClick(selectors.claimAction.hasToPickUpCheckbox); const message = await page.waitForSnackbar(); expect(message.type).toBe('success'); + }); */ + + it('should confirm the "is paid with mana" is checked', async() => { + await page.reloadSection('claim.card.action'); + const isPaidWithManaCheckbox = await page.checkboxState(selectors.claimAction.isPaidWithManaCheckbox); + + expect(isPaidWithManaCheckbox).toBe('checked'); }); - it('should confirm the "is paid with mana" and "Pick up" checkbox are checked', async() => { + /* it('should confirm the "is paid with mana" and "Pick up" checkbox are checked', async() => { await page.reloadSection('claim.card.action'); const isPaidWithManaCheckbox = await page.checkboxState(selectors.claimAction.isPaidWithManaCheckbox); const hasToPickUpCheckbox = await page.checkboxState(selectors.claimAction.hasToPickUpCheckbox); expect(isPaidWithManaCheckbox).toBe('checked'); expect(hasToPickUpCheckbox).toBe('checked'); - }); + }); */ }); diff --git a/modules/claim/back/methods/claim/regularizeClaim.js b/modules/claim/back/methods/claim/regularizeClaim.js index 77e5f6504..7c5c2a3d4 100644 --- a/modules/claim/back/methods/claim/regularizeClaim.js +++ b/modules/claim/back/methods/claim/regularizeClaim.js @@ -88,32 +88,11 @@ module.exports = Self => { }, options); } - let claim = await Self.findById(claimFk, { - include: { - relation: 'client', - scope: { - include: { - relation: 'salesPerson' - } - } - } - }, options); + let claim = await Self.findById(claimFk, null, options); claim = await claim.updateAttributes({ claimStateFk: resolvedState }, options); - // Get sales person from claim client - const salesPerson = claim.client().salesPerson(); - if (salesPerson && claim.hasToPickUp) { - const origin = ctx.req.headers.origin; - const message = $t('Claim will be picked', { - claimId: claim.id, - clientName: claim.client().name, - claimUrl: `${origin}/#!/claim/${claim.id}/summary` - }); - await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message); - } - await tx.commit(); return claim; diff --git a/modules/claim/back/methods/claim/updateClaim.js b/modules/claim/back/methods/claim/updateClaim.js index 51623a7a8..1df745cd2 100644 --- a/modules/claim/back/methods/claim/updateClaim.js +++ b/modules/claim/back/methods/claim/updateClaim.js @@ -27,8 +27,18 @@ module.exports = Self => { }); Self.updateClaim = async(ctx, id, data) => { - let models = Self.app.models; - let claim = await models.Claim.findById(id); + const models = Self.app.models; + const $t = ctx.req.__; // $translate + const claim = await models.Claim.findById(id, { + include: { + relation: 'client', + scope: { + include: { + relation: 'salesPerson' + } + } + } + }); let canUpdate = await canChangeState(ctx, claim.claimStateFk); let hasRights = await canChangeState(ctx, data.claimStateFk); @@ -36,6 +46,18 @@ module.exports = Self => { if (!canUpdate || !hasRights) throw new UserError(`You don't have enough privileges to change that field`); + // Get sales person from claim client + const salesPerson = claim.client().salesPerson(); + if (salesPerson && claim.hasToPickUp) { + const origin = ctx.req.headers.origin; + const message = $t('Claim will be picked', { + claimId: claim.id, + clientName: claim.client().name, + claimUrl: `${origin}/#!/claim/${claim.id}/summary` + }); + await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message); + } + return await claim.updateAttributes(data); }; diff --git a/modules/claim/back/methods/claim/updateClaimAction.js b/modules/claim/back/methods/claim/updateClaimAction.js index 69691897c..d11e2ed08 100644 --- a/modules/claim/back/methods/claim/updateClaimAction.js +++ b/modules/claim/back/methods/claim/updateClaimAction.js @@ -17,10 +17,6 @@ module.exports = Self => { arg: 'isChargedToMana', type: 'boolean', required: false - }, { - arg: 'hasToPickUp', - type: 'boolean', - required: false }], returns: { type: 'object', diff --git a/modules/claim/front/action/index.html b/modules/claim/front/action/index.html index 69dfd255b..f7a43bd2e 100644 --- a/modules/claim/front/action/index.html +++ b/modules/claim/front/action/index.html @@ -43,11 +43,6 @@ on-change="$ctrl.save({responsibility: value})"> - - + + + + diff --git a/modules/claim/front/basic-data/locale/es.yml b/modules/claim/front/basic-data/locale/es.yml index 221b17cdc..d6bae25f6 100644 --- a/modules/claim/front/basic-data/locale/es.yml +++ b/modules/claim/front/basic-data/locale/es.yml @@ -3,4 +3,5 @@ Claim state: Estado de la reclamación Is paid with mana: Cargado al maná Responsability: Responsabilidad Company: Empresa -Sales/Client: Comercial/Cliente \ No newline at end of file +Sales/Client: Comercial/Cliente +Pick up: Recoger \ No newline at end of file From 0695ec01bc552763fcc8cf4d87f6e7b6cac6e776 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 4 Jun 2020 07:53:06 +0200 Subject: [PATCH 2/5] Updated unit test --- .../methods/claim/specs/regularizeClaim.spec.js | 4 +--- .../methods/claim/specs/updateClaim.spec.js | 17 ++++++++++++----- modules/claim/back/methods/claim/updateClaim.js | 6 ++++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js b/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js index 8ebe41f25..1d3bff26d 100644 --- a/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js @@ -103,11 +103,9 @@ describe('regularizeClaim()', () => { claimEnd.updateAttributes({claimDestinationFk: okDestination}); }); - const claim = await app.models.Claim.findById(claimFk); - await claim.updateAttribute('hasToPickUp', true); await app.models.Claim.regularizeClaim(ctx, claimFk); expect(chatModel.sendCheckingPresence).toHaveBeenCalledWith(ctx, 18, 'Bueno'); - expect(chatModel.sendCheckingPresence).toHaveBeenCalledTimes(5); + expect(chatModel.sendCheckingPresence).toHaveBeenCalledTimes(4); }); }); diff --git a/modules/claim/back/methods/claim/specs/updateClaim.spec.js b/modules/claim/back/methods/claim/specs/updateClaim.spec.js index 095e374bd..8cab7a156 100644 --- a/modules/claim/back/methods/claim/specs/updateClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/updateClaim.spec.js @@ -70,19 +70,25 @@ describe('Update Claim', () => { }); it('should change some sensible fields as salesAssistant', async() => { + const chatModel = app.models.Chat; + spyOn(chatModel, 'sendCheckingPresence').and.callThrough(); + const salesAssistantId = 21; let data = { claimStateFk: 3, workerFk: 5, - observation: 'another valid observation' + observation: 'another valid observation', + hasToPickUp: true }; - let ctx = { + const ctx = { req: { - accessToken: { - userId: salesAssistantId - } + accessToken: {userId: salesAssistantId}, + headers: {origin: 'http://localhost'} } }; + ctx.req.__ = (value, params) => { + return params.nickname; + }; await app.models.Claim.updateClaim(ctx, newInstance.id, data); let claimUpdated = await app.models.Claim.findById(newInstance.id); @@ -90,5 +96,6 @@ describe('Update Claim', () => { expect(claimUpdated.observation).toEqual(data.observation); expect(claimUpdated.claimStateFk).toEqual(data.claimStateFk); expect(claimUpdated.workerFk).toEqual(data.workerFk); + expect(chatModel.sendCheckingPresence).toHaveBeenCalled(); }); }); diff --git a/modules/claim/back/methods/claim/updateClaim.js b/modules/claim/back/methods/claim/updateClaim.js index 1df745cd2..62fb66803 100644 --- a/modules/claim/back/methods/claim/updateClaim.js +++ b/modules/claim/back/methods/claim/updateClaim.js @@ -46,9 +46,11 @@ module.exports = Self => { if (!canUpdate || !hasRights) throw new UserError(`You don't have enough privileges to change that field`); + const updatedClaim = await claim.updateAttributes(data); + // Get sales person from claim client const salesPerson = claim.client().salesPerson(); - if (salesPerson && claim.hasToPickUp) { + if (salesPerson && updatedClaim.hasToPickUp) { const origin = ctx.req.headers.origin; const message = $t('Claim will be picked', { claimId: claim.id, @@ -58,7 +60,7 @@ module.exports = Self => { await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message); } - return await claim.updateAttributes(data); + return updatedClaim; }; async function canChangeState(ctx, id) { From 30c721b0e2efc7199ea26e2b4cb8ada14fb6131f Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 4 Jun 2020 08:21:08 +0200 Subject: [PATCH 3/5] Added ACL --- .../methods/claim/specs/updateClaim.spec.js | 1 + .../claim/back/methods/claim/updateClaim.js | 10 +++-- modules/claim/front/basic-data/index.html | 3 +- package-lock.json | 37 +++++++++++++++---- package.json | 2 +- 5 files changed, 40 insertions(+), 13 deletions(-) diff --git a/modules/claim/back/methods/claim/specs/updateClaim.spec.js b/modules/claim/back/methods/claim/specs/updateClaim.spec.js index 8cab7a156..0222164ec 100644 --- a/modules/claim/back/methods/claim/specs/updateClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/updateClaim.spec.js @@ -54,6 +54,7 @@ describe('Update Claim', () => { let data = { observation: 'valid observation', claimStateFk: correctState, + hasToPickUp: false }; let ctx = { req: { diff --git a/modules/claim/back/methods/claim/updateClaim.js b/modules/claim/back/methods/claim/updateClaim.js index 62fb66803..de74c54e8 100644 --- a/modules/claim/back/methods/claim/updateClaim.js +++ b/modules/claim/back/methods/claim/updateClaim.js @@ -28,6 +28,8 @@ module.exports = Self => { Self.updateClaim = async(ctx, id, data) => { const models = Self.app.models; + const userId = ctx.req.accessToken.userId; + const $t = ctx.req.__; // $translate const claim = await models.Claim.findById(id, { include: { @@ -40,10 +42,12 @@ module.exports = Self => { } }); - let canUpdate = await canChangeState(ctx, claim.claimStateFk); - let hasRights = await canChangeState(ctx, data.claimStateFk); + const canUpdate = await canChangeState(ctx, claim.claimStateFk); + const hasRights = await canChangeState(ctx, data.claimStateFk); + const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant'); + const changedHasToPickUp = claim.hasToPickUp != data.hasToPickUp; - if (!canUpdate || !hasRights) + if (!canUpdate || !hasRights || changedHasToPickUp && !isSalesAssistant) throw new UserError(`You don't have enough privileges to change that field`); const updatedClaim = await claim.updateAttributes(data); diff --git a/modules/claim/front/basic-data/index.html b/modules/claim/front/basic-data/index.html index 0f8bcc51f..710068196 100644 --- a/modules/claim/front/basic-data/index.html +++ b/modules/claim/front/basic-data/index.html @@ -56,7 +56,8 @@ + ng-model="$ctrl.claim.hasToPickUp" + vn-acl="salesAssistant"> diff --git a/package-lock.json b/package-lock.json index 4a597175a..4a34836a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11410,9 +11410,9 @@ } }, "loopback-connector-mysql": { - "version": "5.4.2", - "resolved": "https://registry.npmjs.org/loopback-connector-mysql/-/loopback-connector-mysql-5.4.2.tgz", - "integrity": "sha512-f5iIIcJdfUuBUkScGcK7m4dLZnpjFjl1iFG5OHTk8pFwDq7+Xap/0H99ulueRp2ljfqbULTUvt3Rg1y/W5smtw==", + "version": "5.4.3", + "resolved": "https://registry.npmjs.org/loopback-connector-mysql/-/loopback-connector-mysql-5.4.3.tgz", + "integrity": "sha512-HQ0Nnscyhhk+4zsDhXyR8dYdkhxIBN8r8N1futX5xznWjCZ4dpkG5svoPOMUjoNaDEtZuLr1I2E4CKb6f5u9Mw==", "requires": { "async": "^2.6.1", "debug": "^3.1.0", @@ -12231,14 +12231,35 @@ } }, "mysql": { - "version": "2.17.1", - "resolved": "https://registry.npmjs.org/mysql/-/mysql-2.17.1.tgz", - "integrity": "sha512-7vMqHQ673SAk5C8fOzTG2LpPcf3bNt0oL3sFpxPEEFp1mdlDcrLK0On7z8ZYKaaHrHwNcQ/MTUz7/oobZ2OyyA==", + "version": "2.18.1", + "resolved": "https://registry.npmjs.org/mysql/-/mysql-2.18.1.tgz", + "integrity": "sha512-Bca+gk2YWmqp2Uf6k5NFEurwY/0td0cpebAucFpY/3jhrwrVGuxU2uQFCHjU19SJfje0yQvi+rVWdq78hR5lig==", "requires": { - "bignumber.js": "7.2.1", - "readable-stream": "2.3.6", + "bignumber.js": "9.0.0", + "readable-stream": "2.3.7", "safe-buffer": "5.1.2", "sqlstring": "2.3.1" + }, + "dependencies": { + "bignumber.js": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz", + "integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==" + }, + "readable-stream": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + } } }, "mysql2": { diff --git a/package.json b/package.json index 0195aaa9e..c24022e5e 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "loopback-boot": "^2.27.1", "loopback-component-explorer": "^6.5.0", "loopback-component-storage": "^3.6.1", - "loopback-connector-mysql": "^5.4.2", + "loopback-connector-mysql": "^5.4.3", "loopback-connector-remote": "^3.4.1", "loopback-context": "^3.4.0", "md5": "^2.2.1", From 0637302a0bb922e2156f64a315f09a62754d7ded Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 4 Jun 2020 09:49:13 +0200 Subject: [PATCH 4/5] Removed focus --- db/tests/vn/zone_getEvents.spec.js | 3 +-- e2e/paths/06-claim/01_basic_data.spec.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/db/tests/vn/zone_getEvents.spec.js b/db/tests/vn/zone_getEvents.spec.js index bfd11b4b2..fe49b60be 100644 --- a/db/tests/vn/zone_getEvents.spec.js +++ b/db/tests/vn/zone_getEvents.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; -fdescribe('zone zone_getEvents()', () => { +describe('zone zone_getEvents()', () => { it(`should return data for a agencyMode with deliveryMethod pickup`, async() => { let stmts = []; let stmt; @@ -18,7 +18,6 @@ fdescribe('zone zone_getEvents()', () => { ]); stmts.push(stmt); - let firstResultIndex = stmts.push(stmt) - 1; stmts.push('ROLLBACK'); diff --git a/e2e/paths/06-claim/01_basic_data.spec.js b/e2e/paths/06-claim/01_basic_data.spec.js index ecf79ccf0..dd55d0053 100644 --- a/e2e/paths/06-claim/01_basic_data.spec.js +++ b/e2e/paths/06-claim/01_basic_data.spec.js @@ -1,7 +1,7 @@ import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; -fdescribe('Claim edit basic data path', () => { +describe('Claim edit basic data path', () => { let browser; let page; From e2391e559547374192e3306c08801acc40649460 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 4 Jun 2020 10:12:54 +0200 Subject: [PATCH 5/5] Changes made --- e2e/paths/06-claim/04_claim_action.spec.js | 16 ---------------- modules/claim/back/methods/claim/updateClaim.js | 2 +- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/e2e/paths/06-claim/04_claim_action.spec.js b/e2e/paths/06-claim/04_claim_action.spec.js index 34a9c6102..e7ab8638c 100644 --- a/e2e/paths/06-claim/04_claim_action.spec.js +++ b/e2e/paths/06-claim/04_claim_action.spec.js @@ -72,26 +72,10 @@ describe('Claim action path', () => { expect(message.type).toBe('success'); }); - /* it('should check the "Pick up" checkbox', async() => { - await page.waitToClick(selectors.claimAction.hasToPickUpCheckbox); - const message = await page.waitForSnackbar(); - - expect(message.type).toBe('success'); - }); */ - it('should confirm the "is paid with mana" is checked', async() => { await page.reloadSection('claim.card.action'); const isPaidWithManaCheckbox = await page.checkboxState(selectors.claimAction.isPaidWithManaCheckbox); expect(isPaidWithManaCheckbox).toBe('checked'); }); - - /* it('should confirm the "is paid with mana" and "Pick up" checkbox are checked', async() => { - await page.reloadSection('claim.card.action'); - const isPaidWithManaCheckbox = await page.checkboxState(selectors.claimAction.isPaidWithManaCheckbox); - const hasToPickUpCheckbox = await page.checkboxState(selectors.claimAction.hasToPickUpCheckbox); - - expect(isPaidWithManaCheckbox).toBe('checked'); - expect(hasToPickUpCheckbox).toBe('checked'); - }); */ }); diff --git a/modules/claim/back/methods/claim/updateClaim.js b/modules/claim/back/methods/claim/updateClaim.js index de74c54e8..61b8085d3 100644 --- a/modules/claim/back/methods/claim/updateClaim.js +++ b/modules/claim/back/methods/claim/updateClaim.js @@ -54,7 +54,7 @@ module.exports = Self => { // Get sales person from claim client const salesPerson = claim.client().salesPerson(); - if (salesPerson && updatedClaim.hasToPickUp) { + if (salesPerson && changedHasToPickUp && updatedClaim.hasToPickUp) { const origin = ctx.req.headers.origin; const message = $t('Claim will be picked', { claimId: claim.id,