From 18b6efe8f16886be023d476934e298c48269fb4a Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 21 Dec 2021 20:58:58 +0100 Subject: [PATCH] test(ticket_basic-data): test and fixtures --- db/dump/fixtures.sql | 9 ++- e2e/helpers/selectors.js | 4 ++ .../05-ticket/06_basic_data_steps.spec.js | 61 +++++++++++++++++++ loopback/locale/en.json | 3 +- .../back/methods/ticket/componentUpdate.js | 7 +-- .../ticket/specs/componentUpdate.spec.js | 6 +- .../ticket/specs/priceDifference.spec.js | 6 +- .../front/basic-data/step-two/index.html | 3 +- .../ticket/front/basic-data/step-two/index.js | 1 + .../front/basic-data/step-two/index.spec.js | 20 ++++-- .../front/basic-data/step-two/locale/es.yml | 3 +- 11 files changed, 103 insertions(+), 20 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 3e99bd39e..ed50225b9 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -622,6 +622,7 @@ INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeF (25 ,NULL, 8, 1, NULL, CURDATE(), CURDATE(), 1101, 'Bruce Wayne', 1, NULL, 0, 1, 5, 1, CURDATE()), (26 ,NULL, 8, 1, NULL, CURDATE(), CURDATE(), 1101, 'An incredibly long alias for testing purposes', 1, NULL, 0, 1, 5, 1, CURDATE()), (27 ,NULL, 8, 1, NULL, CURDATE(), CURDATE(), 1101, 'Wolverine', 1, NULL, 0, 1, 5, 1, CURDATE()); + INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `description`) VALUES (1, 11, 1, 'ready'), @@ -665,7 +666,9 @@ INSERT INTO `vn`.`ticketTracking`(`ticketFk`, `stateFk`, `workerFk`, `created`) (21, 1, 19, DATE_ADD(NOW(), INTERVAL +1 MONTH)), (22, 1, 19, DATE_ADD(NOW(), INTERVAL +1 MONTH)), (23, 16, 21, NOW()), - (24, 16, 21, NOW()); + (24, 16, 21, NOW()), + (27, 3, 21, NOW()); + INSERT INTO `vn`.`stowaway`(`id`, `shipFk`, `created`) VALUES @@ -896,7 +899,9 @@ INSERT INTO `vn`.`sale`(`id`, `itemFk`, `ticketFk`, `concept`, `quantity`, `pric (29, 4, 17, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, CURDATE()), (30, 4, 18, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, CURDATE()), (31, 2, 23, 'Melee weapon combat fist 15cm', -5, 7.08, 0, 0, 0, CURDATE()), - (32, 1, 24, 'Ranged weapon longbow 2m', -1, 8.07, 0, 0, 0, CURDATE()); + (32, 1, 24, 'Ranged weapon longbow 2m', -1, 8.07, 0, 0, 0, CURDATE()), + (33, 4, 27, 'Melee weapon combat fist 15cm', 1, 8.07, 0, 0, 0, CURDATE()), + (34, 5, 27, 'Ranged weapon pistol 9mm', 50, 1.79, 0, 0, 0, CURDATE()); INSERT INTO `vn`.`saleChecked`(`saleFk`, `isChecked`) VALUES diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 8675797e7..b4720f4c7 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -525,6 +525,7 @@ export default { acceptDialog: '.vn-dialog.shown button[response="accept"]', acceptChangeHourButton: '.vn-dialog.shown button[response="accept"]', descriptorDeliveryDate: 'vn-ticket-descriptor slot-body > .attributes > vn-label-value:nth-child(4) > section > span', + descriptorDeliveryAgency: 'vn-ticket-descriptor slot-body > .attributes > vn-label-value:nth-child(5) > section > span', acceptInvoiceOutButton: '.vn-confirm.shown button[response="accept"]', acceptDeleteStowawayButton: '.vn-dialog.shown button[response="accept"]' }, @@ -562,6 +563,7 @@ export default { transferQuantityInput: '.vn-popover.shown vn-table > div > vn-tbody > vn-tr > vn-td-editable > span > text', transferQuantityCell: '.vn-popover.shown vn-table > div > vn-tbody > vn-tr > vn-td-editable', firstSaleId: 'vn-ticket-sale vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(6) > span', + firstSaleText: 'vn-table div > vn-tbody > vn-tr:nth-child(1)', firstSaleClaimIcon: 'vn-ticket-sale vn-table vn-tbody > vn-tr:nth-child(1) vn-icon[icon="icon-claims"]', firstSaleDescriptorImage: '.vn-popover.shown vn-item-descriptor img', firstSaleThumbnailImage: 'vn-ticket-sale:nth-child(1) vn-tr:nth-child(1) vn-td:nth-child(3) > img', @@ -601,10 +603,12 @@ export default { ticketBasicData: { agency: 'vn-autocomplete[ng-model="$ctrl.agencyModeId"]', zone: 'vn-autocomplete[ng-model="$ctrl.zoneId"]', + shipped: 'vn-date-picker[ng-model="$ctrl.shipped"]', nextStepButton: 'vn-step-control .buttons > section:last-child vn-button', finalizeButton: 'vn-step-control .buttons > section:last-child button[type=submit]', stepTwoTotalPriceDif: 'vn-ticket-basic-data-step-two > vn-side-menu div:nth-child(4)', chargesReason: 'vn-ticket-basic-data-step-two div:nth-child(3) > vn-radio', + withoutNegatives: 'vn-check[ng-model="$ctrl.ticket.withoutNegatives"]', }, ticketComponents: { base: 'vn-ticket-components > vn-side-menu div:nth-child(1) > div:nth-child(2)' diff --git a/e2e/paths/05-ticket/06_basic_data_steps.spec.js b/e2e/paths/05-ticket/06_basic_data_steps.spec.js index a5f9a60cf..cca63cd6f 100644 --- a/e2e/paths/05-ticket/06_basic_data_steps.spec.js +++ b/e2e/paths/05-ticket/06_basic_data_steps.spec.js @@ -83,4 +83,65 @@ describe('Ticket Edit basic data path', () => { await page.waitToClick(selectors.ticketBasicData.finalizeButton); await page.waitForState('ticket.card.summary'); }); + + it(`should not find ticket`, async() => { + await page.doSearch('28'); + const count = await page.countElement(selectors.ticketsIndex.searchResult); + + expect(count).toEqual(0); + }); + + it(`should split ticket without negatives`, async() => { + const tomorrow = new Date(); + tomorrow.setDate(tomorrow.getDate() + 1); + + await page.accessToSearchResult('14'); + await page.accessToSection('ticket.card.basicData.stepOne'); + + const originalDate = await page + .waitToGetProperty(selectors.ticketDescriptor.descriptorDeliveryDate, 'innerText'); + const originalAgency = await page + .waitToGetProperty(selectors.ticketDescriptor.descriptorDeliveryAgency, 'innerText'); + + await page.autocompleteSearch(selectors.ticketBasicData.agency, 'Silla247'); + await page.pickDate(selectors.ticketBasicData.shipped, tomorrow); + await page.waitToClick(selectors.ticketBasicData.nextStepButton); + + await page.waitToClick(selectors.ticketBasicData.withoutNegatives); + await page.waitToClick(selectors.ticketBasicData.finalizeButton); + + const resultDate = await page + .waitToGetProperty(selectors.ticketDescriptor.descriptorDeliveryDate, 'innerText'); + const resultAgency = await page + .waitToGetProperty(selectors.ticketDescriptor.descriptorDeliveryAgency, 'innerText'); + + expect(resultDate).toEqual(originalDate); + expect(resultAgency).toEqual(originalAgency); + }); + + it(`should new ticket have one line from splited ticket`, async() => { + const tomorrow = new Date(); + tomorrow.setDate(tomorrow.getDate() + 1); + const expectedDay = tomorrow.getDate(); + const expectedMonth = tomorrow.getMonth() + 1; + const expectedYear = tomorrow.getFullYear(); + + await page.accessToSearchResult('28'); + await page.accessToSection('ticket.card.sale'); + + const item = await page.waitToGetProperty(selectors.ticketSales.firstSaleId, 'innerText'); + const agency = await page + .waitToGetProperty(selectors.ticketDescriptor.descriptorDeliveryAgency, 'innerText'); + let date = await page + .waitToGetProperty(selectors.ticketDescriptor.descriptorDeliveryDate, 'innerText'); + + date = date.split(' '); + date = date[0].split('/'); + + expect(item).toEqual('4'); + expect(agency).toEqual('Silla247'); + expect(date[0]).toContain(expectedDay); + expect(date[1]).toContain(expectedMonth); + expect(date[2]).toContain(expectedYear); + }); }); diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 15c65fd89..7f3e18d72 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -119,5 +119,6 @@ "The PDF document does not exists": "The PDF document does not exists. Try regenerating it from 'Regenerate invoice PDF' option", "This item is not available": "This item is not available", "Deny buy request": "Purchase request for ticket id [{{ticketId}}]({{{url}}}) has been rejected. Reason: {{observation}}", - "The type of business must be filled in basic data": "The type of business must be filled in basic data" + "The type of business must be filled in basic data": "The type of business must be filled in basic data", + "isWithoutNegatives": "isWithoutNegatives" } \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js index f620adb45..3bccebdfe 100644 --- a/modules/ticket/back/methods/ticket/componentUpdate.js +++ b/modules/ticket/back/methods/ticket/componentUpdate.js @@ -118,15 +118,14 @@ module.exports = Self => { const isProductionBoss = await models.Account.hasRole(userId, 'productionBoss', myOptions); if (!isProductionBoss) { - const params = [args.landed, args.addressFk, args.agencyModeFk, args.warehouseFk]; - const zoneShipped = await models.Agency.getShipped(params, myOptions); + const zoneShipped = await models.Agency.getShipped(args.landed, args.addressFk, args.agencyModeFk, args.warehouseFk, myOptions); if (!zoneShipped || zoneShipped.zoneFk != args.zoneFk) throw new UserError(`You don't have privileges to change the zone`); } if (args.isWithoutNegatives) { - let query = `CALL ticket_getVisibleAvailable(?,?)`; - let params = [args.id, args.shipped]; + const query = `CALL ticket_getVisibleAvailable(?,?)`; + const params = [args.id, args.shipped]; const [salesAvailable] = await Self.rawSql(query, params, myOptions); let salesNewTicket = []; diff --git a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js index 9fa69b595..38e6ce6a7 100644 --- a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js +++ b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js @@ -45,7 +45,8 @@ describe('ticket componentUpdate()', () => { shipped: today, landed: tomorrow, isDeleted: false, - option: 1 + option: 1, + isWithoutNegatives: false }; let ctx = { @@ -94,7 +95,8 @@ describe('ticket componentUpdate()', () => { shipped: today, landed: tomorrow, isDeleted: false, - option: 1 + option: 1, + isWithoutNegatives: false }; const ctx = { diff --git a/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js b/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js index e9648cebe..8fe906bcf 100644 --- a/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js +++ b/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js @@ -60,7 +60,7 @@ describe('sale priceDifference()', () => { expect(error).toEqual(new UserError(`The sales of this ticket can't be modified`)); }); - it('should return ticket visible', async() => { + it('should return ticket available', async() => { const tx = await models.Ticket.beginTransaction({}); try { @@ -83,8 +83,8 @@ describe('sale priceDifference()', () => { const firstItem = result.items[0]; const secondtItem = result.items[1]; - expect(firstItem.visible).toEqual(445); - expect(secondtItem.visible).toEqual(1980); + expect(firstItem.available).toEqual(410); + expect(secondtItem.available).toEqual(1870); await tx.rollback(); } catch (e) { diff --git a/modules/ticket/front/basic-data/step-two/index.html b/modules/ticket/front/basic-data/step-two/index.html index 27569b909..74b160fda 100644 --- a/modules/ticket/front/basic-data/step-two/index.html +++ b/modules/ticket/front/basic-data/step-two/index.html @@ -77,7 +77,8 @@
+ label="Without create negatives" + info="Clone this ticket with the changes and only sales availables">
diff --git a/modules/ticket/front/basic-data/step-two/index.js b/modules/ticket/front/basic-data/step-two/index.js index ec527abf0..d77090781 100644 --- a/modules/ticket/front/basic-data/step-two/index.js +++ b/modules/ticket/front/basic-data/step-two/index.js @@ -75,6 +75,7 @@ class Controller extends Component { haveNotNegatives = true; }); + this.ticket.withoutNegatives = false; this.haveNegatives = (haveNegatives && haveNotNegatives); } diff --git a/modules/ticket/front/basic-data/step-two/index.spec.js b/modules/ticket/front/basic-data/step-two/index.spec.js index 556176d05..fcd1d7e49 100644 --- a/modules/ticket/front/basic-data/step-two/index.spec.js +++ b/modules/ticket/front/basic-data/step-two/index.spec.js @@ -65,14 +65,22 @@ describe('Ticket', () => { }); }); - fdescribe('ticketHaveNegatives()', () => { - it('should show if ticket have any negative', () => { + describe('ticketHaveNegatives()', () => { + it('should show if ticket have any negative and any not negative', () => { controller.ticket = { sale: { - items: [{ - quantity: 2, - visible: 1 - }] + items: [ + { + item: 1, + quantity: 2, + available: 1 + }, + { + item: 2, + quantity: 1, + available: 5 + } + ] } }; diff --git a/modules/ticket/front/basic-data/step-two/locale/es.yml b/modules/ticket/front/basic-data/step-two/locale/es.yml index 4f68d33e2..08bef3b09 100644 --- a/modules/ticket/front/basic-data/step-two/locale/es.yml +++ b/modules/ticket/front/basic-data/step-two/locale/es.yml @@ -6,4 +6,5 @@ The ticket has been unrouted: El ticket ha sido desenrutado Price: Precio New price: Nuevo precio Price difference: Diferencia de precio -Without create negatives: Sin crear negativos \ No newline at end of file +Without create negatives: Sin crear negativos +Clone this ticket with the changes and only sales availables: Clona este ticket con los cambios y solo las ventas disponibles. \ No newline at end of file