diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 9f09b3b73..f5dd5e6e0 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -294,12 +294,18 @@ export default { }, ticketPackages: { packagesButton: `${components.vnMenuItem}[ui-sref="ticket.card.package.index"]`, - firstPackageSelect: `${components.vnAutocomplete}[label="Package"] input` + firstPackageSelect: `${components.vnAutocomplete}[label="Package"] > div > div > input`, + firstPackageSelectOptionThree: `${components.vnAutocomplete}[label="Package"] vn-drop-down ul > li:nth-child(3)`, + firstQuantityInput: `vn-textfield[label="Quantity"] > div > input`, + firstRemovePackageButton: `vn-icon[vn-tooltip="Remove package"]`, + addPackageButton: `vn-icon[vn-tooltip="Add package"]`, + clearPackageSelectButton: `${components.vnAutocomplete}[label="Package"] > div > div > div > vn-icon > i`, + savePackagesButton: `${components.vnSubmit}` }, ticketSales: { saleButton: `${components.vnMenuItem}[ui-sref="ticket.card.sale"]`, - firstPackageSelect: `${components.vnAutocomplete}[label="Package"] input`, firstSaleText: `table > tbody > tr:nth-child(1)`, secondSaleText: `table > tbody > tr:nth-child(2)` } }; + diff --git a/e2e/paths/ticket-module/04_create_ticket_packages.spec.js b/e2e/paths/ticket-module/04_create_ticket_packages.spec.js new file mode 100644 index 000000000..a7aabd411 --- /dev/null +++ b/e2e/paths/ticket-module/04_create_ticket_packages.spec.js @@ -0,0 +1,126 @@ +import selectors from '../../helpers/selectors.js'; +import createNightmare from '../../helpers/helpers'; + +describe('create ticket packages path', () => { + const nightmare = createNightmare(); + + beforeAll(() => { + return nightmare + .waitForLogin('developer'); + }); + + it('should click on the Tickets button of the top bar menu', () => { + return nightmare + .waitToClick(selectors.globalItems.applicationsMenuButton) + .wait(selectors.globalItems.applicationsMenuVisible) + .waitToClick(selectors.globalItems.ticketsButton) + .wait(selectors.ticketsIndex.createTicketButton) + .parsedUrl() + .then(url => { + expect(url.hash).toEqual('#!/ticket/list'); + }); + }); + + it('should search for the ticket 1', () => { + return nightmare + .wait(selectors.ticketsIndex.searchResult) + .type(selectors.ticketsIndex.searchTicketInput, 1) + .click(selectors.ticketsIndex.searchButton) + .waitForNumberOfElements(selectors.ticketsIndex.searchResult, 1) + .countSearchResults(selectors.ticketsIndex.searchResult) + .then(result => { + expect(result).toEqual(1); + }); + }); + + it(`should click on the search result to access to the ticket packages`, () => { + return nightmare + .waitForTextInElement(selectors.ticketsIndex.searchResult, 'Batman') + .waitToClick(selectors.ticketsIndex.searchResult) + .waitToClick(selectors.ticketPackages.packagesButton) + .waitForURL('package/index') + .url() + .then(url => { + expect(url).toContain('package/index'); + }); + }); + + it(`should delete the first package and receive and error to save a new one with blank quantity`, () => { + return nightmare + .waitToClick(selectors.ticketPackages.firstRemovePackageButton) + .waitToClick(selectors.ticketPackages.addPackageButton) + .waitToClick(selectors.ticketPackages.firstPackageSelect) + .waitToClick(selectors.ticketPackages.firstPackageSelectOptionThree) + .click(selectors.ticketPackages.savePackagesButton) + .waitForSnackbar() + .then(result => { + expect(result).toContain('Some fields are invalid'); + }); + }); + + it(`should attempt create a new package but receive an error if quantity is a string`, () => { + return nightmare + .type(selectors.ticketPackages.firstQuantityInput, 'ninety 9') + .click(selectors.ticketPackages.savePackagesButton) + .waitForSnackbar() + .then(result => { + expect(result).toContain('Some fields are invalid'); + }); + }); + + it(`should attempt create a new package but receive an error if quantity is 0`, () => { + return nightmare + .clearInput(selectors.ticketPackages.firstQuantityInput) + .type(selectors.ticketPackages.firstQuantityInput, '0') + .click(selectors.ticketPackages.savePackagesButton) + .waitForSnackbar() + .then(result => { + expect(result).toContain('Some fields are invalid'); + }); + }); + + it(`should attempt create a new package but receive an error if package is blank`, () => { + return nightmare + .clearInput(selectors.ticketPackages.firstQuantityInput) + .type(selectors.ticketPackages.firstQuantityInput, '99') + .click(selectors.ticketPackages.clearPackageSelectButton) + .click(selectors.ticketPackages.savePackagesButton) + .waitForSnackbar() + .then(result => { + expect(result).toContain('Package cannot be blank'); + }); + }); + + it(`should create a new package with correct data`, () => { + return nightmare + .waitToClick(selectors.ticketPackages.firstPackageSelect) + .waitToClick(selectors.ticketPackages.firstPackageSelectOptionThree) + .waitForTextInInput(selectors.ticketPackages.firstPackageSelect, 'Iron Patriot') + .click(selectors.ticketPackages.savePackagesButton) + .waitForSnackbar() + .then(result => { + expect(result).toContain('Data saved!'); + }); + }); + + it(`should confirm the first select is the expected one`, () => { + return nightmare + .click(selectors.ticketSales.saleButton) + .wait(selectors.ticketSales.firstPackageSelect) + .click(selectors.ticketPackages.packagesButton) + .waitForTextInInput(selectors.ticketPackages.firstPackageSelect, 'Iron Patriot') + .getInputValue(selectors.ticketPackages.firstPackageSelect) + .then(result => { + expect(result).toEqual('Iron Patriot'); + }); + }); + + it(`should confirm the first quantity is the expected one`, () => { + return nightmare + .waitForTextInInput(selectors.ticketPackages.firstQuantityInput, '99') + .getInputValue(selectors.ticketPackages.firstQuantityInput) + .then(result => { + expect(result).toEqual('99'); + }); + }); +}); diff --git a/services/loopback/common/locale/es.json b/services/loopback/common/locale/es.json index f4442b3c6..4c2c33c60 100644 --- a/services/loopback/common/locale/es.json +++ b/services/loopback/common/locale/es.json @@ -9,6 +9,6 @@ "DNI Incorrecto": "DNI Incorrecto", "Ya existe un usuario con ese nombre": "Ya existe un usuario con ese nombre", "is invalid": "is invalid", - "Quantity cannot be zero": "La cantidad no puede ser cero", + "Enter an integer different to zero": "Introduce un entero distinto de cero", "Package cannot be blank": "Package cannot be blank" } \ No newline at end of file diff --git a/services/loopback/common/methods/vnModel/installCrudModel.js b/services/loopback/common/methods/vnModel/installCrudModel.js index a9227ce21..c45f4817d 100644 --- a/services/loopback/common/methods/vnModel/installCrudModel.js +++ b/services/loopback/common/methods/vnModel/installCrudModel.js @@ -39,7 +39,7 @@ module.exports = function(Self) { await tx.commit(); } catch (e) { await tx.rollback(); - throw e; + throw Array.isArray(e) ? e[0] : e; } }; }; diff --git a/services/ticket/common/models/ticketPackaging.js b/services/ticket/common/models/ticketPackaging.js index 610dca7ad..8edf743d5 100644 --- a/services/ticket/common/models/ticketPackaging.js +++ b/services/ticket/common/models/ticketPackaging.js @@ -2,7 +2,7 @@ module.exports = function(Self) { require('../methods/packaging/crudTicketPackaging')(Self); Self.validateBinded('quantity', validateQuantity, { - message: 'Quantity cannot be zero', + message: 'Enter an integer different to zero', allowNull: false, allowBlank: false });