From 569f67ffbaf83d0dc8a9b4642246f0f249647576 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Fri, 20 Mar 2020 12:05:45 +0100 Subject: [PATCH 01/14] path unstable --- e2e/helpers/selectors.js | 7 ++ e2e/paths/05-ticket/18_index_payout.spec.js | 115 ++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 e2e/paths/05-ticket/18_index_payout.spec.js diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 0cee79405..0e8ffbfb8 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -368,6 +368,13 @@ export default { advancedSearchInvoiceOut: 'vn-ticket-search-panel vn-textfield[ng-model="filter.refFk"]', newTicketButton: 'vn-ticket-index a', searchResult: 'vn-ticket-index vn-card > vn-table > div > vn-tbody > a.vn-tr', + secondTicketCheckbox: 'vn-ticket-index vn-tbody > a:nth-child(2) > vn-td:nth-child(1) > vn-check', + thirdTicketCheckbox: 'vn-ticket-index vn-tbody > a:nth-child(3) > vn-td:nth-child(1) > vn-check', + sixthTicketCheckbox: 'vn-ticket-index vn-tbody > a:nth-child(6) > vn-td:nth-child(1) > vn-check', + payoutButton: 'vn-ticket-index vn-button[icon="icon-recovery"]', + payoutCompany: '.vn-dialog vn-autocomplete[ng-model="$ctrl.receipt.companyFk"]', + payoutBank: '.vn-dialog vn-autocomplete[ng-model="$ctrl.receipt.bankFk"]', + submitPayout: '.vn-dialog vn-button[label="Save"]', searchWeeklyResult: 'vn-ticket-weekly-index vn-table vn-tbody > vn-tr', searchResultDate: 'vn-ticket-index vn-table vn-tbody > a:nth-child(1) > vn-td:nth-child(5)', topbarSearch: 'vn-searchbar', diff --git a/e2e/paths/05-ticket/18_index_payout.spec.js b/e2e/paths/05-ticket/18_index_payout.spec.js new file mode 100644 index 000000000..46619b5ae --- /dev/null +++ b/e2e/paths/05-ticket/18_index_payout.spec.js @@ -0,0 +1,115 @@ +import selectors from '../../helpers/selectors.js'; +import getBrowser from '../../helpers/puppeteer'; + +xdescribe('Ticket index payout path', () => { + let browser; + let page; + + beforeAll(async() => { + browser = await getBrowser(); + page = browser.page; + }); + + afterAll(async() => { + await browser.close(); + }); + + it('should navigate to the ticket index', async() => { + await page.loginAndModule('administrative', 'ticket'); + let url = await page.expectURL('#!/ticket/index'); + + expect(url).toBe(true); + }); + + it('should check three tickets 2 of a clinet and 1 of another', async() => { + await page.keyboard.press('Enter'); + await page.waitToClick(selectors.ticketsIndex.secondTicketCheckbox); + await page.waitToClick(selectors.ticketsIndex.sixthTicketCheckbox); + await page.waitToClick(selectors.ticketsIndex.payoutButton); + const result = await page.waitForLastSnackbar(); + + expect(result).toEqual('You cannot make a payment on account from multiple clients'); + }); + + it('should uncheck the sixth ticket result and check the third which is from the same client then open the payout form', async() => { + await page.waitToClick(selectors.ticketsIndex.sixthTicketCheckbox); + await page.waitToClick(selectors.ticketsIndex.thirdTicketCheckbox); + await page.waitToClick(selectors.ticketsIndex.payoutButton); + + await page.waitForSelector(selectors.ticketsIndex.payoutCompany); + }); + + it('should fill the company and bank to perform a payout', async() => { + await page.autocompleteSearch(selectors.ticketsIndex.payoutBank, 'cash'); + await page.waitToClick(selectors.ticketsIndex.submitPayout); + const result = await page.waitForLastSnackbar(); + + expect(result).toEqual('Data saved!'); + }); + + it('should navigate to the client balance section', async() => { + await page.waitToClick(selectors.globalItems.homeButton); + // await page.selectModule('client'); + // await page.accessToSearchResult('Bruce Wayne'); + // await page.accessToSection('client.card.balance.index'); + // await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); + // let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); + + // expect(result).toEqual(4); + }); + + it('should B', async() => { + // await page.waitToClick(selectors.globalItems.homeButton); + await page.selectModule('client'); + // await page.accessToSearchResult('Bruce Wayne'); + // await page.accessToSection('client.card.balance.index'); + // await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); + // let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); + + // expect(result).toEqual(4); + }); + + it('should C', async() => { + // await page.waitToClick(selectors.globalItems.homeButton); + // await page.selectModule('client'); + await page.accessToSearchResult('Bruce Wayne'); + // await page.accessToSection('client.card.balance.index'); + // await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); + // let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); + + // expect(result).toEqual(4); + }); + + it('should D', async() => { + // await page.waitToClick(selectors.globalItems.homeButton); + // await page.selectModule('client'); + // await page.accessToSearchResult('Bruce Wayne'); + await page.accessToSection('client.card.balance.index'); + // await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); + // let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); + + // expect(result).toEqual(4); + }); + + it('should E', async() => { + // await page.waitToClick(selectors.globalItems.homeButton); + // await page.selectModule('client'); + // await page.accessToSearchResult('Bruce Wayne'); + // await page.accessToSection('client.card.balance.index'); + await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); + // let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); + + // expect(result).toEqual(4); + }); + + it('should F', async() => { + // await page.waitToClick(selectors.globalItems.homeButton); + // await page.selectModule('client'); + // await page.accessToSearchResult('Bruce Wayne'); + // await page.accessToSection('client.card.balance.index'); + // await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); + let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); + + expect(result).toEqual(4); + }); +}); From 27b13767993b5a71d47eac314c04b6eef4e78cb5 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 23 Mar 2020 11:21:25 +0100 Subject: [PATCH 02/14] changes --- db/dump/fixtures.sql | 22 +++++++++ modules/item/back/model-config.json | 3 ++ .../item/back/models/item-shelving-sale.json | 5 ++ modules/item/back/models/item-shelving.json | 40 +++++++++++++++ .../ticket/back/methods/ticket/setDeleted.js | 21 ++++++-- .../methods/ticket/specs/setDeleted.spec.js | 49 +++++++++++++++++-- modules/ticket/back/models/sale.json | 2 +- 7 files changed, 134 insertions(+), 8 deletions(-) create mode 100644 modules/item/back/models/item-shelving.json diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 7b2fd1cae..227291a68 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -101,6 +101,16 @@ INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `isPreviousPrepare (1, 'First sector', 1, 1, 'FIRST', 999, 999), (2, 'Second sector', 2, 0, 'SECOND', 100, 150); +INSERT INTO `vn`.`parking` (`id`, `column`, `row`, `sectorFk`, `code`, `pickingOrder`) + VALUES + ('1', '700', '01', '1', '700-01', '70001'), + ('2', '700', '02', '2', '700-02', '70002'); + +INSERT INTO `vn`.`shelving` (`code`, `parkingFk`, `isPrinted`, `priority`, `parked`, `userFk`) + VALUES + ('GVC', '1', '0', '1', '0', '106'), + ('HEJ', '2', '0', '1', '0', '106'); + INSERT INTO `vn`.`warehouseAlias`(`id`, `name`) VALUES (1, 'Main Warehouse'); @@ -928,6 +938,18 @@ INSERT INTO `vn`.`saleComponent`(`saleFk`, `componentFk`, `value`) (32, 36, -92.324), (32, 39, 0.994); +INSERT INTO `vn`.`itemShelving` (`id`, `itemFk`, `shelvingFk`, `shelve`, `deep`, `quantity`, `visible`, `available`, `grouping`, `packing`, `level`, `userFk`) + VALUES + ('1', '2', 'GVC', 'A', '0', '1', '1', '1', '1', '1', '1', '106'), + ('2', '4', 'HEJ', 'A', '0', '2', '1', '1', '1', '1', '1', '106'); + +INSERT INTO `vn`.`itemShelvingSale` (`itemShelvingFk`, `saleFk`, `quantity`, `created`, `userFk`) + VALUES + ('1', '1', '1', '', '106'), + ('2', '2', '5', '', '106'), + ('1', '7', '1', '', '106'), + ('2', '8', '5', '', '106'); + INSERT INTO `vncontrol`.`accion`(`accion_id`, `accion`) VALUES (3, 'ACTION ONE'), diff --git a/modules/item/back/model-config.json b/modules/item/back/model-config.json index d8ec5914a..c085e075a 100644 --- a/modules/item/back/model-config.json +++ b/modules/item/back/model-config.json @@ -44,6 +44,9 @@ "ItemTypeTag": { "dataSource": "vn" }, + "ItemShelving": { + "dataSource": "vn" + }, "ItemShelvingSale": { "dataSource": "vn" }, diff --git a/modules/item/back/models/item-shelving-sale.json b/modules/item/back/models/item-shelving-sale.json index 547c882a0..04f505ddd 100644 --- a/modules/item/back/models/item-shelving-sale.json +++ b/modules/item/back/models/item-shelving-sale.json @@ -25,6 +25,11 @@ "model": "Sale", "foreignKey": "saleFk" }, + "itemShelving": { + "type": "belongsTo", + "model": "ItemShelving", + "foreignKey": "itemShelvingFk" + }, "user": { "type": "belongsTo", "model": "Account", diff --git a/modules/item/back/models/item-shelving.json b/modules/item/back/models/item-shelving.json new file mode 100644 index 000000000..0fcc00f7e --- /dev/null +++ b/modules/item/back/models/item-shelving.json @@ -0,0 +1,40 @@ +{ + "name": "ItemShelving", + "base": "VnModel", + "options": { + "mysql": { + "table": "itemShelving" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Identifier" + }, + "shelve": { + "type": "string" + }, + "deep": { + "type": "number" + }, + "quantity": { + "type": "number" + }, + "created": { + "type": "Date" + } + }, + "relations": { + "item": { + "type": "belongsTo", + "model": "Item", + "foreignKey": "itemFk" + }, + "user": { + "type": "belongsTo", + "model": "Account", + "foreignKey": "userFk" + } + } +} diff --git a/modules/ticket/back/methods/ticket/setDeleted.js b/modules/ticket/back/methods/ticket/setDeleted.js index 6daad7c39..0f7e0b57f 100644 --- a/modules/ticket/back/methods/ticket/setDeleted.js +++ b/modules/ticket/back/methods/ticket/setDeleted.js @@ -23,6 +23,7 @@ module.exports = Self => { Self.setDeleted = async(ctx, id) => { const models = Self.app.models; + const userId = ctx.req.accessToken.userId; const isEditable = await Self.isEditable(ctx, id); const $t = ctx.req.__; // $translate @@ -30,16 +31,30 @@ module.exports = Self => { throw new UserError(`The sales of this ticket can't be modified`); // Check if has sales with shelving + const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant'); const sales = await models.Sale.find({ - include: {relation: 'itemShelving'}, + include: {relation: 'itemShelvingSale'}, where: {ticketFk: id} }); const hasItemShelvingSales = sales.some(sale => { - return sale.itemShelving(); + return sale.itemShelvingSale(); }); - if (hasItemShelvingSales) + + if (hasItemShelvingSales && !isSalesAssistant) throw new UserError(`You cannot delete a ticket that part of it is being prepared`); + if (hasItemShelvingSales && isSalesAssistant) { + const promises = []; + for (let sale of sales) { + if (sale.itemShelvingSale()) { + const itemShelvingSale = sale.itemShelvingSale(); + const destroyedShelving = models.ItemShelvingSale.destroyById(itemShelvingSale.id); + promises.push(destroyedShelving); + } + } + await Promise.all(promises); + } + // Check for existing claim const claimOfATicket = await models.Claim.findOne({where: {ticketFk: id}}); if (claimOfATicket) diff --git a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js index 890fc6c45..f756db771 100644 --- a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js +++ b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js @@ -1,13 +1,28 @@ const app = require('vn-loopback/server/server'); +const models = app.models; -describe('ticket deleted()', () => { +fdescribe('ticket deleted()', () => { let ticket; + let sale; let ctx; beforeAll(async done => { - let originalTicket = await app.models.Ticket.findOne({where: {id: 16}}); + let originalTicket = await models.Ticket.findOne({where: {id: 16}}); originalTicket.id = null; - ticket = await app.models.Ticket.create(originalTicket); + ticket = await models.Ticket.create(originalTicket); + sale = await models.Sale.create({ + ticketFk: ticket.id, + itemFk: 4, + concept: 'Melee weapon', + quantity: 10 + }); + + await models.ItemShelvingSale.create({ + itemShelvingFk: 1, + saleFk: sale.id, + quantity: 10, + userFk: 106 + }); ctx = { req: { @@ -23,7 +38,7 @@ describe('ticket deleted()', () => { }); afterAll(async done => { - await app.models.Ticket.destroyById(ticket.id); + await models.Ticket.destroyById(ticket.id); done(); }); @@ -32,6 +47,20 @@ describe('ticket deleted()', () => { expect(ticket.isDeleted).toEqual(false); }); + it('should make sure the ticket sale has an item shelving', async() => { + const sales = await models.Sale.find({ + include: {relation: 'itemShelvingSale'}, + where: {ticketFk: ticket.id} + }); + const hasItemShelvingSales = sales.some(sale => { + return sale.itemShelvingSale(); + }); + + expect(hasItemShelvingSales).toEqual(true); + }); + + // Try to delete ticket as userid 106, throws prepared error + // Try to delete ticket as userid 9 and succeed: it('should set a ticket to deleted', async() => { await app.models.Ticket.setDeleted(ctx, ticket.id); @@ -40,6 +69,18 @@ describe('ticket deleted()', () => { expect(deletedTicket.isDeleted).toEqual(true); }); + it('should not have any item shelving', async() => { + const sales = await models.Sale.find({ + include: {relation: 'itemShelvingSale'}, + where: {ticketFk: ticket.id} + }); + const hasItemShelvingSales = sales.some(sale => { + return sale.itemShelvingSale(); + }); + + expect(hasItemShelvingSales).toEqual(false); + }); + it('should throw an error if the given ticket has a claim', async() => { let ticketId = 16; let error; diff --git a/modules/ticket/back/models/sale.json b/modules/ticket/back/models/sale.json index 1f2ea4bbf..767a3e59e 100644 --- a/modules/ticket/back/models/sale.json +++ b/modules/ticket/back/models/sale.json @@ -73,7 +73,7 @@ "model": "SaleTracking", "foreignKey": "saleFk" }, - "itemShelving": { + "itemShelvingSale": { "type": "hasOne", "model": "ItemShelvingSale", "foreignKey": "saleFk" From 9bae89a6728f679d87eb97fbbca2dbf825edf87c Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 23 Mar 2020 16:03:27 +0100 Subject: [PATCH 03/14] Updated unit test --- .../methods/ticket/specs/setDeleted.spec.js | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js index f756db771..2713bd700 100644 --- a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js +++ b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js @@ -1,10 +1,9 @@ const app = require('vn-loopback/server/server'); const models = app.models; -fdescribe('ticket deleted()', () => { +describe('ticket deleted()', () => { let ticket; let sale; - let ctx; beforeAll(async done => { let originalTicket = await models.Ticket.findOne({where: {id: 16}}); @@ -24,16 +23,6 @@ fdescribe('ticket deleted()', () => { userFk: 106 }); - ctx = { - req: { - accessToken: {userId: 106}, - headers: { - origin: 'http://localhost:5000' - }, - __: () => {} - } - }; - done(); }); @@ -59,12 +48,23 @@ fdescribe('ticket deleted()', () => { expect(hasItemShelvingSales).toEqual(true); }); - // Try to delete ticket as userid 106, throws prepared error - // Try to delete ticket as userid 9 and succeed: - it('should set a ticket to deleted', async() => { + it('should set a ticket to deleted and remove all item shelvings', async() => { + const salesAssistantId = 21; + const ctx = { + req: { + accessToken: {userId: salesAssistantId}, + headers: { + origin: 'http://localhost:5000' + }, + __: () => {} + } + }; await app.models.Ticket.setDeleted(ctx, ticket.id); - let deletedTicket = await app.models.Ticket.findOne({where: {id: ticket.id}, fields: ['isDeleted']}); + let deletedTicket = await app.models.Ticket.findOne({ + where: {id: ticket.id}, + fields: ['isDeleted'] + }); expect(deletedTicket.isDeleted).toEqual(true); }); @@ -82,7 +82,16 @@ fdescribe('ticket deleted()', () => { }); it('should throw an error if the given ticket has a claim', async() => { - let ticketId = 16; + const ticketId = 16; + const ctx = { + req: { + accessToken: {userId: 106}, + headers: { + origin: 'http://localhost:5000' + }, + __: () => {} + } + }; let error; try { From 61c85cfb9e1364cf1b60cb627eb37c955db8c232 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 25 Mar 2020 09:20:26 +0100 Subject: [PATCH 04/14] Updated tests --- modules/order/front/catalog/index.html | 10 +++- modules/order/front/catalog/index.js | 60 ++++++++++++++++------- modules/order/front/catalog/index.spec.js | 22 +++++++-- modules/order/front/routes.json | 2 +- 4 files changed, 70 insertions(+), 24 deletions(-) diff --git a/modules/order/front/catalog/index.html b/modules/order/front/catalog/index.html index 7131d6a6e..0349c1358 100644 --- a/modules/order/front/catalog/index.html +++ b/modules/order/front/catalog/index.html @@ -11,6 +11,12 @@ limit="50" data="$ctrl.items"> + + + + + @@ -77,13 +83,13 @@ - - + --> { - if (this.$stateParams.itemId) - this.itemId = parseInt(this.$stateParams.itemId); + if (this.$params.categoryId) + this.categoryId = parseInt(this.$params.categoryId); - if (this.$stateParams.categoryId) - this.categoryId = parseInt(this.$stateParams.categoryId); + if (this.$params.typeId) + this.typeId = parseInt(this.$params.typeId); - if (this.$stateParams.typeId) - this.typeId = parseInt(this.$stateParams.typeId); - - if (this.$stateParams.tags) - this.tags = JSON.parse(this.$stateParams.tags); + if (this.$params.tags) + this.tags = JSON.parse(this.$params.tags); }); } @@ -126,6 +120,17 @@ class Controller { this.applyFilters(); } + get itemName() { + return this._itemName; + } + + set itemName(value) { + this._itemName = value; + + this.updateStateParams(); + this.applyFilters(); + } + get tags() { return this._tags; } @@ -248,8 +253,11 @@ class Controller { if (this.itemId) newFilter = {'i.id': this.itemId}; + if (this.itemName) + newFilter = {'i.name': {like: `%${this.itemName}%`}}; + newParams = { - orderFk: this.order.id, + orderFk: this.$params.id, orderBy: this.getOrderBy(), tags: this.tags, }; @@ -290,6 +298,10 @@ class Controller { if (this.itemId) params.itemId = this.itemId; + params.itemName = undefined; + if (this.itemName) + params.itemName = this.itemName; + params.tags = undefined; if (this.tags.length) { const tags = []; @@ -348,9 +360,21 @@ class Controller { newFilterList = newFilterList.concat(tags); this.orderFields = newFilterList; } + + onSearch(params) { + if (params.search) { + if (/^\d+$/.test(params.search)) { + this.itemId = params.search; + this.itemName = null; + } else { + this.itemId = null; + this.itemName = params.search; + } + } + } } -Controller.$inject = ['$http', '$scope', '$state', '$compile', '$transitions']; +Controller.$inject = ['$element', '$scope', '$transitions']; ngModule.component('vnOrderCatalog', { template: require('./index.html'), diff --git a/modules/order/front/catalog/index.spec.js b/modules/order/front/catalog/index.spec.js index e2d2d0aff..86fb7c179 100644 --- a/modules/order/front/catalog/index.spec.js +++ b/modules/order/front/catalog/index.spec.js @@ -17,11 +17,15 @@ describe('Order', () => { $scope.search = {}; $scope.itemId = {}; $state = _$state_; - $state.params.categoryId = 1; - $state.params.typeId = 2; $state.current.name = 'my.current.state'; - controller = $componentController('vnOrderCatalog', {$scope, $state}); + const $element = angular.element(''); + controller = $componentController('vnOrderCatalog', {$element, $scope, $state}); controller._order = {id: 4}; + controller.$params = { + categoryId: 1, + typeId: 2, + id: 4 + }; })); describe('order() setter', () => { @@ -123,6 +127,18 @@ describe('Order', () => { }); }); + describe('itemName() setter', () => { + it(`should set itemName property and then call updateStateParams() and applyFilters() methods`, () => { + jest.spyOn(controller, 'updateStateParams'); + jest.spyOn(controller, 'applyFilters'); + + controller.itemName = 'Bow'; + + expect(controller.updateStateParams).toHaveBeenCalledWith(); + expect(controller.applyFilters).toHaveBeenCalledWith(); + }); + }); + describe('tags() setter', () => { it(`should set tags property and then call updateStateParams() and applyFilters() methods`, () => { jest.spyOn(controller, 'updateStateParams'); diff --git a/modules/order/front/routes.json b/modules/order/front/routes.json index b607aef9d..2f7c2c63a 100644 --- a/modules/order/front/routes.json +++ b/modules/order/front/routes.json @@ -41,7 +41,7 @@ "order": "$ctrl.order" } }, { - "url": "/catalog?categoryId&typeId&itemId&tags", + "url": "/catalog?q&categoryId&typeId&itemId&itemName&tags", "state": "order.card.catalog", "component": "vn-order-catalog", "description": "Catalog", From c8b6c3f7f3aaedafb43e8994a1f2d8298fef2e3e Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 25 Mar 2020 13:44:51 +0100 Subject: [PATCH 05/14] Fixed conflicts --- e2e/paths/07-order/02_basic_data.spec.js | 2 +- e2e/paths/07-order/04_catalog.spec.js | 5 +- modules/order/front/catalog/index.html | 28 +++++----- modules/order/front/catalog/index.js | 67 ++++++++++------------- modules/order/front/catalog/locale/es.yml | 2 + 5 files changed, 50 insertions(+), 54 deletions(-) create mode 100644 modules/order/front/catalog/locale/es.yml diff --git a/e2e/paths/07-order/02_basic_data.spec.js b/e2e/paths/07-order/02_basic_data.spec.js index d7bd01208..2c3292b61 100644 --- a/e2e/paths/07-order/02_basic_data.spec.js +++ b/e2e/paths/07-order/02_basic_data.spec.js @@ -81,7 +81,7 @@ describe('Order edit basic data path', () => { await page.waitToClick(selectors.orderBasicData.saveButton); const result = await page.waitForLastSnackbar(); - expect(result).toEqual('Data saved!'); + expect(result).toContain('Data saved!'); }); it('should now confirm the client have been edited', async() => { diff --git a/e2e/paths/07-order/04_catalog.spec.js b/e2e/paths/07-order/04_catalog.spec.js index 0db313088..bd502ce5b 100644 --- a/e2e/paths/07-order/04_catalog.spec.js +++ b/e2e/paths/07-order/04_catalog.spec.js @@ -69,8 +69,9 @@ describe('Order catalog', () => { }); it('should search for an item by id', async() => { - await page.write(selectors.orderCatalog.itemId, '2'); - await page.keyboard.press('Enter'); + // await page.write(selectors.orderCatalog.itemId, '2'); + await page.accessToSearchResult('2'); + // await page.keyboard.press('Enter'); await page.waitForNumberOfElements('section.product', 1); const result = await page.countElement('section.product'); diff --git a/modules/order/front/catalog/index.html b/modules/order/front/catalog/index.html index 0349c1358..06ccfb1dd 100644 --- a/modules/order/front/catalog/index.html +++ b/modules/order/front/catalog/index.html @@ -12,11 +12,12 @@ data="$ctrl.items"> - + + - - @@ -83,14 +84,6 @@ - - Id: {{$ctrl.itemId}} + + Name + : {{$ctrl.itemName}} + Date: Wed, 25 Mar 2020 14:06:13 +0100 Subject: [PATCH 06/14] Updated unit tests --- modules/order/front/catalog/index.js | 20 --------- modules/order/front/catalog/index.spec.js | 49 +++++++---------------- 2 files changed, 14 insertions(+), 55 deletions(-) diff --git a/modules/order/front/catalog/index.js b/modules/order/front/catalog/index.js index 5ebbba3d3..00913caa4 100644 --- a/modules/order/front/catalog/index.js +++ b/modules/order/front/catalog/index.js @@ -182,18 +182,6 @@ class Controller extends Section { this.itemTypes = res.data); } - /** - * Search by item id filter - * @param {object} event - */ - onSearchById(event) { - const value = this.$.itemId.value; - if (event.key === 'Enter' && value) { - this.itemId = value; - this.$.itemId.value = null; - } - } - /** * Search by tag value * @param {object} event @@ -238,20 +226,12 @@ class Controller extends Section { if (this.typeId) newFilter.typeFk = this.typeId; - /* if (this.itemId) - newFilter = {'i.id': this.itemId}; - - if (this.itemName) - newFilter = {'i.name': {like: `%${this.itemName}%`}}; */ - newParams = { orderFk: this.$params.id, orderBy: this.getOrderBy(), tags: this.tags, }; - console.log(newFilter); - return model.applyFilter({where: newFilter}, newParams); } diff --git a/modules/order/front/catalog/index.spec.js b/modules/order/front/catalog/index.spec.js index 86fb7c179..9a9742f7f 100644 --- a/modules/order/front/catalog/index.spec.js +++ b/modules/order/front/catalog/index.spec.js @@ -115,30 +115,6 @@ describe('Order', () => { }); }); - describe('itemId() setter', () => { - it(`should set itemId property and then call updateStateParams() and applyFilters() methods`, () => { - jest.spyOn(controller, 'updateStateParams'); - jest.spyOn(controller, 'applyFilters'); - - controller.itemId = 1; - - expect(controller.updateStateParams).toHaveBeenCalledWith(); - expect(controller.applyFilters).toHaveBeenCalledWith(); - }); - }); - - describe('itemName() setter', () => { - it(`should set itemName property and then call updateStateParams() and applyFilters() methods`, () => { - jest.spyOn(controller, 'updateStateParams'); - jest.spyOn(controller, 'applyFilters'); - - controller.itemName = 'Bow'; - - expect(controller.updateStateParams).toHaveBeenCalledWith(); - expect(controller.applyFilters).toHaveBeenCalledWith(); - }); - }); - describe('tags() setter', () => { it(`should set tags property and then call updateStateParams() and applyFilters() methods`, () => { jest.spyOn(controller, 'updateStateParams'); @@ -173,23 +149,27 @@ describe('Order', () => { }); }); - describe('onSearchById()', () => { - it(`should not filter by id if the event key code doesn't equals to 'Enter'`, () => { + describe('onSearch()', () => { + it(`should apply a filter by item id an then call the applyFilters method`, () => { jest.spyOn(controller, 'applyFilters'); - controller.$.itemId.value = 1; - controller.onSearchById({key: 'Tab'}); + const itemId = 1; + controller.onSearch({search: itemId}); - expect(controller.applyFilters).not.toHaveBeenCalledWith(); + expect(controller.applyFilters).toHaveBeenCalledWith({ + 'i.id': itemId + }); }); - it(`should filter by id if the event key code equals to 'Enter' an then call applyFilters()`, () => { + it(`should apply a filter by item name an then call the applyFilters method`, () => { jest.spyOn(controller, 'applyFilters'); - controller.$.itemId.value = 1; - controller.onSearchById({key: 'Enter'}); + const itemName = 'Bow'; + controller.onSearch({search: itemName}); - expect(controller.applyFilters).toHaveBeenCalledWith(); + expect(controller.applyFilters).toHaveBeenCalledWith({ + 'i.name': {like: `%${itemName}%`} + }); }); }); @@ -239,7 +219,6 @@ describe('Order', () => { controller._categoryId = 2; controller._typeId = 4; - controller._itemId = 1; controller._tags = [ {tagFk: 11, value: 'Precission', tagSelection: {name: 'Category'}} ]; @@ -247,7 +226,7 @@ describe('Order', () => { value: 'Precission', tagFk: 11, tagSelection: {name: 'Category'}} ]); - let result = {categoryId: 2, typeId: 4, itemId: 1, tags: tags}; + let result = {categoryId: 2, typeId: 4, tags: tags}; controller.updateStateParams(); expect(controller.$state.go).toHaveBeenCalledWith('my.current.state', result); From e94cb7fecd713d1b9ecabf5d42e9800f26ad3443 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 25 Mar 2020 14:07:35 +0100 Subject: [PATCH 07/14] Removed commented lines --- e2e/paths/07-order/04_catalog.spec.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/e2e/paths/07-order/04_catalog.spec.js b/e2e/paths/07-order/04_catalog.spec.js index bd502ce5b..34fdbbec0 100644 --- a/e2e/paths/07-order/04_catalog.spec.js +++ b/e2e/paths/07-order/04_catalog.spec.js @@ -69,9 +69,7 @@ describe('Order catalog', () => { }); it('should search for an item by id', async() => { - // await page.write(selectors.orderCatalog.itemId, '2'); await page.accessToSearchResult('2'); - // await page.keyboard.press('Enter'); await page.waitForNumberOfElements('section.product', 1); const result = await page.countElement('section.product'); From 2b7ff6fec006445a665d4e70cfff4502d8f72051 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 25 Mar 2020 14:08:45 +0100 Subject: [PATCH 08/14] Removed state vars --- modules/order/front/routes.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/order/front/routes.json b/modules/order/front/routes.json index 2f7c2c63a..eec628b89 100644 --- a/modules/order/front/routes.json +++ b/modules/order/front/routes.json @@ -41,7 +41,7 @@ "order": "$ctrl.order" } }, { - "url": "/catalog?q&categoryId&typeId&itemId&itemName&tags", + "url": "/catalog?q&categoryId&typeId&tags", "state": "order.card.catalog", "component": "vn-order-catalog", "description": "Catalog", From 9b4546edadbfaff47d1c808673ea96581a40fedc Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Wed, 25 Mar 2020 14:18:51 +0100 Subject: [PATCH 09/14] minor refactor plus path fix after merge --- e2e/paths/05-ticket/18_index_payout.spec.js | 61 +-------------------- modules/ticket/front/index/index.js | 2 +- 2 files changed, 4 insertions(+), 59 deletions(-) diff --git a/e2e/paths/05-ticket/18_index_payout.spec.js b/e2e/paths/05-ticket/18_index_payout.spec.js index 46619b5ae..749428c44 100644 --- a/e2e/paths/05-ticket/18_index_payout.spec.js +++ b/e2e/paths/05-ticket/18_index_payout.spec.js @@ -1,7 +1,7 @@ import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; -xdescribe('Ticket index payout path', () => { +describe('Ticket index payout path', () => { let browser; let page; @@ -47,67 +47,12 @@ xdescribe('Ticket index payout path', () => { expect(result).toEqual('Data saved!'); }); - it('should navigate to the client balance section', async() => { + it('should navigate to the client balance section and check a new balance line was entered', async() => { await page.waitToClick(selectors.globalItems.homeButton); - // await page.selectModule('client'); - // await page.accessToSearchResult('Bruce Wayne'); - // await page.accessToSection('client.card.balance.index'); - // await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); - // let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); - - // expect(result).toEqual(4); - }); - - it('should B', async() => { - // await page.waitToClick(selectors.globalItems.homeButton); await page.selectModule('client'); - // await page.accessToSearchResult('Bruce Wayne'); - // await page.accessToSection('client.card.balance.index'); - // await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); - // let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); - - // expect(result).toEqual(4); - }); - - it('should C', async() => { - // await page.waitToClick(selectors.globalItems.homeButton); - // await page.selectModule('client'); - await page.accessToSearchResult('Bruce Wayne'); - // await page.accessToSection('client.card.balance.index'); - // await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); - // let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); - - // expect(result).toEqual(4); - }); - - it('should D', async() => { - // await page.waitToClick(selectors.globalItems.homeButton); - // await page.selectModule('client'); - // await page.accessToSearchResult('Bruce Wayne'); + await page.accessToSearchResult('101'); await page.accessToSection('client.card.balance.index'); - // await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); - // let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); - - // expect(result).toEqual(4); - }); - - it('should E', async() => { - // await page.waitToClick(selectors.globalItems.homeButton); - // await page.selectModule('client'); - // await page.accessToSearchResult('Bruce Wayne'); - // await page.accessToSection('client.card.balance.index'); await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); - // let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); - - // expect(result).toEqual(4); - }); - - it('should F', async() => { - // await page.waitToClick(selectors.globalItems.homeButton); - // await page.selectModule('client'); - // await page.accessToSearchResult('Bruce Wayne'); - // await page.accessToSection('client.card.balance.index'); - // await page.waitForSelector('vn-client-balance-index vn-tbody > vn-tr'); let result = await page.countElement('vn-client-balance-index vn-tbody > vn-tr'); expect(result).toEqual(4); diff --git a/modules/ticket/front/index/index.js b/modules/ticket/front/index/index.js index e9f522839..3f0146846 100644 --- a/modules/ticket/front/index/index.js +++ b/modules/ticket/front/index/index.js @@ -37,7 +37,7 @@ export default class Controller { } get checked() { - const tickets = this.$.tickets || []; + const tickets = this.$.model.data || []; const checkedLines = []; for (let ticket of tickets) { if (ticket.checked) From f06c7d3d479242dbddfcf08983718a329d3e3095 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Wed, 25 Mar 2020 15:17:43 +0100 Subject: [PATCH 10/14] front test --- modules/ticket/front/index/index.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/ticket/front/index/index.spec.js b/modules/ticket/front/index/index.spec.js index 6b0b42ffd..d66c9f49d 100644 --- a/modules/ticket/front/index/index.spec.js +++ b/modules/ticket/front/index/index.spec.js @@ -87,7 +87,7 @@ describe('Component vnTicketIndex', () => { controller.$.balanceCreateDialog = {show: () => {}}; jest.spyOn(controller.$.balanceCreateDialog, 'show').mockReturnThis(); - controller.$.tickets = tickets; + controller.$.model = {data: tickets}; controller.$.balanceCreateDialog.amountPaid = 0; controller.openBalanceDialog(); @@ -101,7 +101,7 @@ describe('Component vnTicketIndex', () => { describe('checked()', () => { it('should return an array of checked tickets', () => { - controller.$.tickets = tickets; + controller.$.model = {data: tickets}; const result = controller.checked; const firstRow = result[0]; const secondRow = result[1]; @@ -114,7 +114,7 @@ describe('Component vnTicketIndex', () => { describe('totalChecked()', () => { it('should return the total number of checked tickets', () => { - controller.$.tickets = tickets; + controller.$.model = {data: tickets}; const result = controller.checked; expect(result.length).toEqual(2); From 92ffccc9a2f7726189f792f9a60baec5debc3497 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 26 Mar 2020 09:07:17 +0100 Subject: [PATCH 11/14] 2206 - Refactor popover table --- modules/zone/front/delivery-days/index.html | 53 ++++++++++++++++++- modules/zone/front/delivery-days/index.js | 9 +++- .../zone/front/delivery-days/index.spec.js | 8 +-- modules/zone/front/delivery-days/style.scss | 6 +-- 4 files changed, 61 insertions(+), 15 deletions(-) diff --git a/modules/zone/front/delivery-days/index.html b/modules/zone/front/delivery-days/index.html index 589208caf..b0874c66c 100644 --- a/modules/zone/front/delivery-days/index.html +++ b/modules/zone/front/delivery-days/index.html @@ -33,10 +33,59 @@ + + +
Zones
- + + + + + + Id + Name + Agency + Closing + Price + + + + + + {{::zone.id}} + {{::zone.name}} + {{::zone.agencyMode.name}} + {{::zone.hour | date: 'HH:mm'}} + {{::zone.price | currency: 'EUR':2}} + + + + + + + + + + +
-
\ No newline at end of file + + + + \ No newline at end of file diff --git a/modules/zone/front/delivery-days/index.js b/modules/zone/front/delivery-days/index.js index 006252a69..363186543 100644 --- a/modules/zone/front/delivery-days/index.js +++ b/modules/zone/front/delivery-days/index.js @@ -26,8 +26,7 @@ class Controller extends Section { zones.push(event.zoneFk); this.$.zoneEvents.show($event.target); - const zoneIndex = this.$.zoneIndex; - const zoneModel = zoneIndex.$scope.model; + const zoneModel = this.$.zoneModel; zoneModel.applyFilter({ include: { relation: 'agencyMode', @@ -38,6 +37,12 @@ class Controller extends Section { } }); } + + preview(event, zone) { + this.stopEvent(event); + this.selectedZone = zone; + this.$.summary.show(); + } } ngModule.component('vnZoneDeliveryDays', { diff --git a/modules/zone/front/delivery-days/index.spec.js b/modules/zone/front/delivery-days/index.spec.js index 125e14f2d..6dc270b9a 100644 --- a/modules/zone/front/delivery-days/index.spec.js +++ b/modules/zone/front/delivery-days/index.spec.js @@ -14,11 +14,7 @@ describe('Zone Component vnZoneDeliveryDays', () => { $element = angular.element(' { @@ -60,7 +56,7 @@ describe('Zone Component vnZoneDeliveryDays', () => { }); it('should call the show() method and then call the applyFilter() method with the expected ids', () => { - const zoneModel = controller.$.zoneIndex.$scope.model; + const zoneModel = controller.$.zoneModel; jest.spyOn(controller.$.zoneEvents, 'show'); jest.spyOn(zoneModel, 'applyFilter'); diff --git a/modules/zone/front/delivery-days/style.scss b/modules/zone/front/delivery-days/style.scss index 531b51795..a279ca0b9 100644 --- a/modules/zone/front/delivery-days/style.scss +++ b/modules/zone/front/delivery-days/style.scss @@ -19,11 +19,7 @@ vn-zone-delivery-days { .zoneEvents { width: 700px; max-height: 450px; - - vn-float-button { - display: none - } - + vn-data-viewer { margin-bottom: 0; vn-pagination { From 69280925944e03f1db0006ca2b60aaf3017caf63 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Thu, 26 Mar 2020 12:00:07 +0100 Subject: [PATCH 12/14] fix ticket.sale state autocomplete --- modules/ticket/back/methods/state/editableStates.js | 8 ++++++-- .../ticket/back/methods/state/specs/editableState.spec.js | 8 +++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/ticket/back/methods/state/editableStates.js b/modules/ticket/back/methods/state/editableStates.js index 4979f4819..c1cbda799 100644 --- a/modules/ticket/back/methods/state/editableStates.js +++ b/modules/ticket/back/methods/state/editableStates.js @@ -3,6 +3,10 @@ module.exports = Self => { Self.remoteMethodCtx('editableStates', { description: 'Gets the editable states according the user role ', accessType: 'READ', + accepts: { + arg: 'filter', + type: 'object' + }, returns: { type: ['Object'], root: true @@ -13,10 +17,10 @@ module.exports = Self => { } }); - Self.editableStates = async ctx => { + Self.editableStates = async(ctx, filter) => { let userId = ctx.req.accessToken.userId; let models = Self.app.models; - let statesList = await models.State.find(); + let statesList = await models.State.find({where: filter.where}); let isProduction = await models.Account.hasRole(userId, 'production'); let isSalesPerson = await models.Account.hasRole(userId, 'salesPerson'); diff --git a/modules/ticket/back/methods/state/specs/editableState.spec.js b/modules/ticket/back/methods/state/specs/editableState.spec.js index 54dbdfcae..03cb7616c 100644 --- a/modules/ticket/back/methods/state/specs/editableState.spec.js +++ b/modules/ticket/back/methods/state/specs/editableState.spec.js @@ -1,10 +1,12 @@ const app = require('vn-loopback/server/server'); describe('ticket editableStates()', () => { + const filter = {where: {name: {like: '%%'}}}; it('should return the expected state for the given role', async() => { const productionRole = 49; const ctx = {req: {accessToken: {userId: productionRole}}}; - let result = await app.models.State.editableStates(ctx); + + let result = await app.models.State.editableStates(ctx, filter); let deliveredState = result.some(state => state.code == 'DELIVERED'); expect(deliveredState).toBeTruthy(); @@ -13,7 +15,7 @@ describe('ticket editableStates()', () => { it(`should returns the expected states by a specific role`, async() => { const productionRole = 18; const ctx = {req: {accessToken: {userId: productionRole}}}; - let result = await app.models.State.editableStates(ctx); + let result = await app.models.State.editableStates(ctx, filter); let deliveredState = result.some(state => state.code == 'DELIVERED'); let pickerDesignedState = result.some(state => state.code == 'PICKER_DESIGNED'); @@ -24,7 +26,7 @@ describe('ticket editableStates()', () => { it(`should return again the expected state by a specific role`, async() => { const employeeRole = 1; const ctx = {req: {accessToken: {userId: employeeRole}}}; - let result = await app.models.State.editableStates(ctx); + let result = await app.models.State.editableStates(ctx, filter); let pickerDesignedState = result.some(state => state.code == 'PICKER_DESIGNED'); expect(pickerDesignedState).toBeFalsy(); From 835c415ba7e952b5e4b6f3a2fa173405b29d2966 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 26 Mar 2020 14:45:38 +0100 Subject: [PATCH 13/14] 1934 - Moved procedure logic to method --- loopback/locale/en.json | 1 + loopback/locale/es.json | 1 + .../back/methods/ticket/deleteStowaway.js | 61 ++++++++++++++++--- 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index b8c31020b..dc62e35f4 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -62,6 +62,7 @@ "MESSAGE_INSURANCE_CHANGE": "I have changed the insurence credit of client [{{clientName}} (#{{clientId}})]({{{url}}}) to *{{credit}} €*", "MESSAGE_CHANGED_PAYMETHOD": "I have changed the pay method for client [{{clientName}} (#{{clientId}})]({{{url}}})", "Sent units from ticket": "I sent *{{quantity}}* units of [{{concept}} (#{{itemId}})]({{{itemUrl}}}) to *\"{{nickname}}\"* coming from ticket id [#{{ticketId}}]({{{ticketUrl}}})", + "This ticket is not an stowaway anymore": "The ticket id [#{{ticketId}}]({{{ticketUrl}}}) is not an stowaway anymore", "Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member", "Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member", "Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}", diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 5f41c9931..da62a6a7d 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -125,6 +125,7 @@ "MESSAGE_INSURANCE_CHANGE": "He cambiado el crédito asegurado del cliente [{{clientName}} (#{{clientId}})]({{{url}}}) a *{{credit}} €*", "MESSAGE_CHANGED_PAYMETHOD": "He cambiado la forma de pago del cliente [{{clientName}} (#{{clientId}})]({{{url}}})", "Sent units from ticket": "Envio *{{quantity}}* unidades de [{{concept}} (#{{itemId}})]({{{itemUrl}}}) a *\"{{nickname}}\"* provenientes del ticket id [#{{ticketId}}]({{{ticketUrl}}})", + "This ticket is not an stowaway anymore": "El ticket id [#{{ticketId}}]({{{ticketUrl}}}) ha dejado de ser un polizón", "Client checked as validated despite of duplication": "Cliente comprobado a pesar de que existe el cliente id {{clientId}}", "ORDER_ROW_UNAVAILABLE": "No hay disponibilidad de este producto", "Distance must be lesser than 1000": "La distancia debe ser inferior a 1000", diff --git a/modules/ticket/back/methods/ticket/deleteStowaway.js b/modules/ticket/back/methods/ticket/deleteStowaway.js index 6f3a1760f..cf9626c14 100644 --- a/modules/ticket/back/methods/ticket/deleteStowaway.js +++ b/modules/ticket/back/methods/ticket/deleteStowaway.js @@ -1,6 +1,6 @@ module.exports = Self => { - Self.remoteMethod('deleteStowaway', { + Self.remoteMethodCtx('deleteStowaway', { description: 'Deletes an stowaway', accessType: 'WRITE', accepts: [{ @@ -19,21 +19,66 @@ module.exports = Self => { } }); - Self.deleteStowaway = async id => { + Self.deleteStowaway = async(ctx, id) => { + const models = Self.app.models; + const $t = ctx.req.__; // $translate const ticket = await Self.findById(id, { include: [{ relation: 'ship' }, { relation: 'stowaway' + }, { + relation: 'client', + scope: { + include: { + relation: 'salesPerson' + } + } }] }); - let params; - if (ticket.stowaway()) - params = [ticket.stowaway().shipFk, ticket.stowaway().id]; - else if (ticket.ship()) - params = [ticket.ship().shipFk, ticket.ship().id]; + let stowawayFk; + let shipFk; + if (ticket.stowaway()) { + shipFk = ticket.stowaway().shipFk; + stowawayFk = ticket.stowaway().id; + } else if (ticket.ship()) { + shipFk = ticket.ship().shipFk; + stowawayFk = ticket.ship().id; + } - return Self.rawSql(`CALL vn.stowaway_unboarding(?, ?)`, params); + const stowaway = await models.Stowaway.findOne({ + where: { + id: stowawayFk, + shipFk: shipFk + } + }); + const result = await stowaway.destroy(); + + const state = await models.State.findOne({ + where: { + code: 'BOARDING' + } + }); + const ticketTracking = await models.TicketTracking.findOne({ + where: { + ticketFk: shipFk, + stateFk: state.id + } + }); + + await ticketTracking.destroy(); + + const salesPerson = ticket.client().salesPerson(); + if (salesPerson) { + const origin = ctx.req.headers.origin; + const message = $t('This ticket is not an stowaway anymore', { + ticketId: stowawayFk, + ticketUrl: `${origin}/#!/ticket/${stowawayFk}/summary` + }); + await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message); + } + + return result; }; }; From d4ca58edad0cba6c827415d5e32582ba70a9f0da Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 27 Mar 2020 09:10:30 +0100 Subject: [PATCH 14/14] Updated back unit test --- db/dump/fixtures.sql | 4 ++ .../ticket/specs/deleteStowaway.spec.js | 72 +++++++++++++++++-- modules/ticket/back/model-config.json | 3 + .../ticket/back/models/ticket-last-state.json | 34 +++++++++ 4 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 modules/ticket/back/models/ticket-last-state.json diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 331d115a3..4218e15d1 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -554,6 +554,10 @@ INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `des (10, 23, 4, 'Reclama ticket: 8'), (11, 24, 4, 'Reclama ticket: 7'); +-- FIX for state hours on local, inter_afterInsert +UPDATE vncontrol.inter SET odbc_date = DATE_ADD(CURDATE(), INTERVAL -10 SECOND); + + INSERT INTO `vn`.`ticketTracking`(`ticketFk`, `stateFk`, `workerFk`, `created`) VALUES (1, 16, 5 , DATE_ADD(NOW(), INTERVAL -1 MONTH)), diff --git a/modules/ticket/back/methods/ticket/specs/deleteStowaway.spec.js b/modules/ticket/back/methods/ticket/specs/deleteStowaway.spec.js index 3c8097e37..bd6fd327a 100644 --- a/modules/ticket/back/methods/ticket/specs/deleteStowaway.spec.js +++ b/modules/ticket/back/methods/ticket/specs/deleteStowaway.spec.js @@ -3,40 +3,100 @@ const app = require('vn-loopback/server/server'); describe('ticket deleteStowaway()', () => { const shipId = 16; const stowawayId = 17; + const ctx = { + req: { + accessToken: {userId: 18}, + headers: {origin: 'http://localhost'} + } + }; + ctx.req.__ = (value, params) => { + return params.nickname; + }; + + afterAll(async() => { + await app.models.Stowaway.rawSql( + `CALL ticketStateUpdate(?, ?)`, [shipId, 'OK']); + await app.models.Stowaway.rawSql( + `CALL ticketStateUpdate(?, ?)`, [stowawayId, 'OK']); + }); it('should create an stowaway', async() => { await app.models.Stowaway.rawSql(` INSERT INTO stowaway (id, shipFk) VALUES (?, ?) `, [stowawayId, shipId]); + await app.models.Stowaway.rawSql( + `CALL ticketStateUpdate(?, ?)`, [shipId, 'BOARDING']); const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId}); expect(stowawayExists).toEqual(1); }); + it('should confirm that the ship ticket is on "BOARDING" state', async() => { + const shipState = await app.models.TicketLastState.findOne({ + where: { + ticketFk: shipId + } + }); + + expect(shipState.name).toEqual('Embarcando'); + }); + it('should delete the stowaway from the ship ticket', async() => { - await app.models.Ticket.deleteStowaway(shipId); + await app.models.Ticket.deleteStowaway(ctx, shipId); const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId}); expect(stowawayExists).toEqual(0); }); + it('should confirm that the ship ticket is not on "BOARDING" state anymore', async() => { + const shipState = await app.models.TicketLastState.findOne({ + where: { + ticketFk: shipId + } + }); + + expect(shipState.name).toEqual('OK'); + }); + it('should create again an stowaway', async() => { await app.models.Stowaway.rawSql(` INSERT INTO stowaway (id, shipFk) VALUES (?, ?) - `, [stowawayId, shipId]); + `, [shipId, stowawayId]); + await app.models.Stowaway.rawSql( + `CALL ticketStateUpdate(?, ?)`, [stowawayId, 'BOARDING']); - const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId}); + const stowawayExists = await app.models.Stowaway.count({id: shipId, shipFk: stowawayId}); expect(stowawayExists).toEqual(1); }); - it('should delete the stowaway from the stowaway ticket', async() => { - await app.models.Ticket.deleteStowaway(stowawayId); + it('should confirm that the stowaway ticket is on "BOARDING" state', async() => { + const shipState = await app.models.TicketLastState.findOne({ + where: { + ticketFk: stowawayId + } + }); - const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId}); + expect(shipState.name).toEqual('Embarcando'); + }); + + it('should delete the stowaway from the stowaway ticket', async() => { + await app.models.Ticket.deleteStowaway(ctx, stowawayId); + + const stowawayExists = await app.models.Stowaway.count({id: shipId, shipFk: stowawayId}); expect(stowawayExists).toEqual(0); }); + + it('should confirm that the stowaway ticket is not on "BOARDING" state anymore', async() => { + const shipState = await app.models.TicketLastState.findOne({ + where: { + ticketFk: stowawayId + } + }); + + expect(shipState.name).toEqual('OK'); + }); }); diff --git a/modules/ticket/back/model-config.json b/modules/ticket/back/model-config.json index 10c10b134..ac6f4f100 100644 --- a/modules/ticket/back/model-config.json +++ b/modules/ticket/back/model-config.json @@ -56,6 +56,9 @@ "TicketState":{ "dataSource": "vn" }, + "TicketLastState":{ + "dataSource": "vn" + }, "TicketService":{ "dataSource": "vn" }, diff --git a/modules/ticket/back/models/ticket-last-state.json b/modules/ticket/back/models/ticket-last-state.json new file mode 100644 index 000000000..890d800af --- /dev/null +++ b/modules/ticket/back/models/ticket-last-state.json @@ -0,0 +1,34 @@ +{ + "name": "TicketLastState", + "base": "VnModel", + "options": { + "mysql": { + "table": "ticketLastState" + } + }, + "properties": { + "name": { + "type": "string" + }, + "ticketFk": { + "id": 1, + "type": "Number" + }, + "ticketTrackingFk": { + "id": 2, + "type": "Number" + } + }, + "relations": { + "ticket": { + "type": "belongsTo", + "model": "Ticket", + "foreignKey": "ticketFk" + }, + "ticketTracking": { + "type": "belongsTo", + "model": "TicketTracking", + "foreignKey": "ticketTrackingFk" + } + } +}