diff --git a/Jenkinsfile b/Jenkinsfile index e61547070c..06f77ffed9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,22 +3,24 @@ def branchName = "${env.BRANCH_NAME}"; def branchProduction = "master" def branchTest = "test"; -def dockerHost = "${env.DOCKER_HOST}"; -env.NODE_ENV = branchName; env.BRANCH_NAME = branchName; env.TAG = "${env.BUILD_NUMBER}"; -if (branchName == "test") - env.NODE_ENV = "development"; - -if (branchName == branchProduction) - dockerHost = "tcp://172.16.255.29:2375"; +switch (branchName){ + case branchTest: + env.NODE_ENV = "development"; + break; + case branchProduction: + env.DOCKER_HOST = "tcp://172.16.255.29:2375"; + env.NODE_ENV = "production" + break; +} node { stage ('Print environment variables'){ - echo "Branch ${branchName}, Build ${env.TAG}, NODE_ENV ${env.NODE_ENV} en docker Host ${dockerHost}" + echo "Branch ${branchName}, Build ${env.TAG}, NODE_ENV ${env.NODE_ENV} en docker Host ${env.DOCKER_HOST}" } stage ('Checkout') { checkout scm diff --git a/client/client/src/fiscal-data/fiscal-data.html b/client/client/src/fiscal-data/fiscal-data.html index 73d9a96cca..1443b0a11b 100644 --- a/client/client/src/fiscal-data/fiscal-data.html +++ b/client/client/src/fiscal-data/fiscal-data.html @@ -18,18 +18,18 @@ - - + + - + + label="Province"> + label="Country"> - + diff --git a/client/client/src/locale/es.json b/client/client/src/locale/es.json index c3bc8aac5f..4dd110d725 100644 --- a/client/client/src/locale/es.json +++ b/client/client/src/locale/es.json @@ -4,5 +4,10 @@ "Fiscal data": "Datos Fiscales", "Has to invoice": "Factura", "Invoice by mail": "Factura impresa", - "CountryFk": "País" -} \ No newline at end of file + "Country": "País", + "Street": "Domicilio fiscal", + "City": "Municipio", + "Postcode": "Código postal", + "Province": "Provincia", + "Save": "Guardar" +} diff --git a/client/salix/src/configroutes.js b/client/salix/src/configroutes.js index 9a30b3180b..1d79c5bc24 100644 --- a/client/salix/src/configroutes.js +++ b/client/salix/src/configroutes.js @@ -11,8 +11,8 @@ function loader(moduleName, validations) { return load; } -config.$inject = ['$stateProvider', '$urlRouterProvider', 'aclServiceProvider']; -function config($stateProvider, $urlRouterProvider, aclServiceProvider) { +config.$inject = ['$stateProvider', '$urlRouterProvider', 'aclServiceProvider', 'modulesFactoryProvider']; +function config($stateProvider, $urlRouterProvider, aclServiceProvider, modulesFactory) { splitingRegister.registerGraph(deps); let aclService = aclServiceProvider.$get(); @@ -41,21 +41,28 @@ function config($stateProvider, $urlRouterProvider, aclServiceProvider) { let fileRoutes = window.routes[file].routes; let moduleName = window.routes[file].module; let validations = window.routes[file].validations || false; - fileRoutes.forEach(function(route) { - if (aclService.routeHasPermission(route)) { - $stateProvider.state(route.state, { - url: route.url, - abstract: route.abstract || false, - template: `<${route.component} ${getParams(route)}>`, - resolve: { - loader: loader(moduleName, validations) - }, - data: { - routes: fileRoutes - } - }); + let mainModule = modulesFactory.$get().getMainRoute(fileRoutes); + if (mainModule) { + let count = fileRoutes.length; + for (let i = 0; i < count; i++) { + let route = fileRoutes[i]; + if (aclService.routeHasPermission(route)) { + $stateProvider.state(route.state, { + url: route.url, + abstract: route.abstract || false, + template: `<${route.component} ${getParams(route)}>`, + resolve: { + loader: loader(moduleName, validations) + }, + data: { + routes: fileRoutes + } + }); + } else if (route.state === mainModule.state) { + break; + } } - }); + } } } ngModule.config(config); diff --git a/client/salix/src/modulesFactory.js b/client/salix/src/modulesFactory.js index a36b301aca..02c3e845cf 100644 --- a/client/salix/src/modulesFactory.js +++ b/client/salix/src/modulesFactory.js @@ -1,7 +1,7 @@ import ngModule from './module'; function modulesFactory(aclService) { - function _getMainRoute(routeCollection) { + function getMainRoute(routeCollection) { let cant = routeCollection.length; for (let i = 0; i < cant; i++) { if (!routeCollection[i].abstract) { @@ -18,7 +18,7 @@ function modulesFactory(aclService) { name: routes[file].name || routes[file].module, icon: routes[file].icon || '' }; - let mainRoute = _getMainRoute(window.routes[file].routes); + let mainRoute = getMainRoute(window.routes[file].routes); if (mainRoute && aclService.routeHasPermission(mainRoute)) { card.route = mainRoute; modules.push(card); @@ -28,7 +28,8 @@ function modulesFactory(aclService) { } return { - getModules: getModules + getModules: getModules, + getMainRoute: getMainRoute }; } modulesFactory.$inject = ['aclService']; diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 1b772561c6..0e47740efc 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -54,6 +54,9 @@ export default { invoiceByMailCheckboxInput: `${components.vnCheck}[label='Invoice by mail'] > label > label > input`, addressInput: `${components.vnTextfield}[name="street"]`, cityInput: `${components.vnTextfield}[name="city"]`, + postcodeInput: `${components.vnTextfield}[name="postcode"]`, + provinceInput: `${components.vnAutocomplete}[field="$ctrl.client.provinceFk"] > vn-vertical > ${components.vnTextfield}`, + provinceFifthOption: `${components.vnAutocomplete}[field="$ctrl.client.provinceFk"] > vn-vertical > vn-drop-down > vn-vertical > vn-one:nth-child(2) > ul > li:nth-child(5)`, saveButton: 'body > vn-app > vn-vertical > vn-vertical > vn-client-card > vn-horizontal > vn-auto > vn-vertical > vn-client-fiscal-data > form > vn-button-bar > vn-submit > input' } }; diff --git a/e2e/paths/edit_basic_data.spec.js.js b/e2e/paths/edit_basic_data.spec.js similarity index 84% rename from e2e/paths/edit_basic_data.spec.js.js rename to e2e/paths/edit_basic_data.spec.js index 0c8436a0c3..6ebaeeaf18 100644 --- a/e2e/paths/edit_basic_data.spec.js.js +++ b/e2e/paths/edit_basic_data.spec.js @@ -45,7 +45,7 @@ describe('Edit basicData path', () => { .catch(catchErrors(done)); }); - it(`should search for the user Bruce Wayne`, done => { + it('should search for the user Bruce Wayne', done => { nightmare .wait(selectors.clientsIndex.searchResult) .type(selectors.clientsIndex.searchClientInput, 'Bruce Wayne') @@ -59,7 +59,7 @@ describe('Edit basicData path', () => { .catch(catchErrors(done)); }); - it(`should click on the search result to access to the client's basic data`, done => { + it('should click on the search result to access to the clients basic data', done => { nightmare .waitForTextInElement(selectors.clientsIndex.searchResult, 'Bruce Wayne') .waitToClick(selectors.clientsIndex.searchResult) @@ -72,7 +72,7 @@ describe('Edit basicData path', () => { .catch(catchErrors(done)); }); - it(`should edit the name`, done => { + it('should edit the name', done => { nightmare .wait(selectors.basicData.nameInput) .clearInput(selectors.basicData.nameInput) @@ -81,13 +81,13 @@ describe('Edit basicData path', () => { .wait(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive) .then(result => { - expect(result).toEqual(`¡Datos guardados!`); + expect(result).toEqual('¡Datos guardados!'); done(); }) .catch(catchErrors(done)); }); - it(`should confirm the name have been edited`, done => { + it('should confirm the name have been edited', done => { nightmare .waitForSnackbarReset() .click(selectors.fiscalData.fiscalDataButton) @@ -96,13 +96,13 @@ describe('Edit basicData path', () => { .wait(selectors.basicData.nameInput) .getInputValue(selectors.basicData.nameInput) .then(result => { - expect(result).toEqual(`Carol Danvers Edited`); + expect(result).toEqual('Carol Danvers Edited'); done(); }) .catch(catchErrors(done)); }); - it(`should edit the tax number`, done => { + it('should edit the tax number', done => { nightmare .wait(selectors.basicData.taxNumberInput) .clearInput(selectors.basicData.taxNumberInput) @@ -111,13 +111,13 @@ describe('Edit basicData path', () => { .wait(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive) .then(result => { - expect(result).toEqual(`¡Datos guardados!`); + expect(result).toEqual('¡Datos guardados!'); done(); }) .catch(catchErrors(done)); }); - it(`should confirm the tax number have been edited`, done => { + it('should confirm the tax number have been edited', done => { nightmare .waitForSnackbarReset() .click(selectors.fiscalData.fiscalDataButton) @@ -126,13 +126,13 @@ describe('Edit basicData path', () => { .wait(selectors.basicData.taxNumberInput) .getInputValue(selectors.basicData.taxNumberInput) .then(result => { - expect(result).toEqual(`AVG tax Edited`); + expect(result).toEqual('AVG tax Edited'); done(); }) .catch(catchErrors(done)); }); - it(`should edit the social name`, done => { + it('should edit the social name', done => { nightmare .wait(selectors.basicData.socialNameInput) .clearInput(selectors.basicData.socialNameInput) @@ -141,13 +141,13 @@ describe('Edit basicData path', () => { .wait(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive) .then(result => { - expect(result).toEqual(`¡Datos guardados!`); + expect(result).toEqual('¡Datos guardados!'); done(); }) .catch(catchErrors(done)); }); - it(`should confirm the social name have been edited`, done => { + it('should confirm the social name have been edited', done => { nightmare .waitForSnackbarReset() .click(selectors.fiscalData.fiscalDataButton) @@ -156,13 +156,13 @@ describe('Edit basicData path', () => { .wait(selectors.basicData.socialNameInput) .getInputValue(selectors.basicData.socialNameInput) .then(result => { - expect(result).toEqual(`Avengers Team Edited`); + expect(result).toEqual('Avengers Team Edited'); done(); }) .catch(catchErrors(done)); }); - it(`should add the landline phone number`, done => { + it('should add the landline phone number', done => { nightmare .wait(selectors.basicData.phoneInput) .clearInput(selectors.basicData.phoneInput) @@ -171,13 +171,13 @@ describe('Edit basicData path', () => { .wait(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive) .then(result => { - expect(result).toEqual(`¡Datos guardados!`); + expect(result).toEqual('¡Datos guardados!'); done(); }) .catch(catchErrors(done)); }); - it(`should confirm the landline phone number have been added`, done => { + it('should confirm the landline phone number have been added', done => { nightmare .waitForSnackbarReset() .click(selectors.fiscalData.fiscalDataButton) @@ -192,7 +192,7 @@ describe('Edit basicData path', () => { .catch(catchErrors(done)); }); - it(`should add the mobile phone number`, done => { + it('should add the mobile phone number', done => { nightmare .wait(selectors.basicData.mobileInput) .clearInput(selectors.basicData.mobileInput) @@ -201,13 +201,13 @@ describe('Edit basicData path', () => { .wait(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive) .then(result => { - expect(result).toEqual(`¡Datos guardados!`); + expect(result).toEqual('¡Datos guardados!'); done(); }) .catch(catchErrors(done)); }); - it(`should confirm the mobile phone number have been added`, done => { + it('should confirm the mobile phone number have been added', done => { nightmare .waitForSnackbarReset() .click(selectors.fiscalData.fiscalDataButton) @@ -222,7 +222,7 @@ describe('Edit basicData path', () => { .catch(catchErrors(done)); }); - it(`should add the fax number`, done => { + it('should add the fax number', done => { nightmare .wait(selectors.basicData.faxInput) .clearInput(selectors.basicData.faxInput) @@ -231,13 +231,13 @@ describe('Edit basicData path', () => { .wait(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive) .then(result => { - expect(result).toEqual(`¡Datos guardados!`); + expect(result).toEqual('¡Datos guardados!'); done(); }) .catch(catchErrors(done)); }); - it(`should confirm the fax number have been added`, done => { + it('should confirm the fax number have been added', done => { nightmare .waitForSnackbarReset() .click(selectors.fiscalData.fiscalDataButton) @@ -252,7 +252,7 @@ describe('Edit basicData path', () => { .catch(catchErrors(done)); }); - it(`should edit the email`, done => { + it('should edit the email', done => { nightmare .wait(selectors.basicData.emailInput) .clearInput(selectors.basicData.emailInput) @@ -261,13 +261,13 @@ describe('Edit basicData path', () => { .wait(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive) .then(result => { - expect(result).toEqual(`¡Datos guardados!`); + expect(result).toEqual('¡Datos guardados!'); done(); }) .catch(catchErrors(done)); }); - it(`should confirm the email have been edited`, done => { + it('should confirm the email have been edited', done => { nightmare .waitForSnackbarReset() .click(selectors.fiscalData.fiscalDataButton) @@ -282,7 +282,7 @@ describe('Edit basicData path', () => { .catch(catchErrors(done)); }); - // it(`should select the sales person`, done => { + // it('should select the sales person', done => { // nightmare // .wait(selectors.basicData.salesPersonInput) // .select(selectors.basicData.salesPersonInput, '') // not working quite yet @@ -290,13 +290,13 @@ describe('Edit basicData path', () => { // .wait(selectors.globalItems.snackbarIsActive) // .getInnerText(selectors.globalItems.snackbarIsActive) // .then(result => { - // expect(result).toEqual(`¡Datos guardados!`); + // expect(result).toEqual('¡Datos guardados!'); // done(); // }) // .catch(catchErrors(done)); // }); - it(`should select the channel`, done => { + it('should select the channel', done => { nightmare .waitToClick(selectors.basicData.channelInput) .waitToClick(selectors.basicData.channelInput) @@ -305,13 +305,13 @@ describe('Edit basicData path', () => { .wait(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive) .then(result => { - expect(result).toEqual(`¡Datos guardados!`); + expect(result).toEqual('¡Datos guardados!'); done(); }) .catch(catchErrors(done)); }); - it(`should confirm the channel have been selected`, done => { + it('should confirm the channel have been selected', done => { nightmare .waitForSnackbarReset() .click(selectors.fiscalData.fiscalDataButton) diff --git a/e2e/paths/edit_fiscal_data.spec.js.js b/e2e/paths/edit_fiscal_data.spec.js similarity index 67% rename from e2e/paths/edit_fiscal_data.spec.js.js rename to e2e/paths/edit_fiscal_data.spec.js index 231399b54c..c835f60ff9 100644 --- a/e2e/paths/edit_fiscal_data.spec.js.js +++ b/e2e/paths/edit_fiscal_data.spec.js @@ -45,7 +45,7 @@ describe('Edit fiscalData path', () => { .catch(catchErrors(done)); }); - it(`should search for the user Bruce Banner`, done => { + it('should search for the user Bruce Banner', done => { nightmare .wait(selectors.clientsIndex.searchResult) .type(selectors.clientsIndex.searchClientInput, 'Bruce Banner') @@ -73,7 +73,7 @@ describe('Edit fiscalData path', () => { .catch(catchErrors(done)); }); - it(`should uncheck the hasToInvoice checkbox`, done => { + it('should uncheck the hasToInvoice checkbox', done => { nightmare .waitToClick(selectors.fiscalData.hasToInvoiceCheckboxLabel) .waitToClick(selectors.fiscalData.saveButton) @@ -86,7 +86,7 @@ describe('Edit fiscalData path', () => { .catch(catchErrors(done)); }); - it(`should confirm hasToInvoice checkbox is unchecked`, done => { + it('should confirm hasToInvoice checkbox is unchecked', done => { nightmare .waitForSnackbarReset() .waitToClick(selectors.basicData.basicDataButton) @@ -103,7 +103,7 @@ describe('Edit fiscalData path', () => { .catch(catchErrors(done)); }); - it(`should uncheck the invoiceByMail checkbox`, done => { + it('should uncheck the invoiceByMail checkbox', done => { nightmare .waitToClick(selectors.fiscalData.invoiceByMailCheckboxLabel) .waitToClick(selectors.fiscalData.saveButton) @@ -116,7 +116,7 @@ describe('Edit fiscalData path', () => { .catch(catchErrors(done)); }); - it(`should confirm invoiceByMail checkbox is unchecked`, done => { + it('should confirm invoiceByMail checkbox is unchecked', done => { nightmare .waitForSnackbarReset() .waitToClick(selectors.basicData.basicDataButton) @@ -133,7 +133,7 @@ describe('Edit fiscalData path', () => { .catch(catchErrors(done)); }); - it(`should edit the address`, done => { + it('should edit the address', done => { nightmare .wait(selectors.fiscalData.addressInput) .clearInput(selectors.fiscalData.addressInput) @@ -142,13 +142,13 @@ describe('Edit fiscalData path', () => { .wait(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive) .then(result => { - expect(result).toEqual(`¡Datos guardados!`); + expect(result).toEqual('¡Datos guardados!'); done(); }) .catch(catchErrors(done)); }); - it(`should confirm the address have been edited`, done => { + it('should confirm the address have been edited', done => { nightmare .waitForSnackbarReset() .click(selectors.basicData.basicDataButton) @@ -157,13 +157,13 @@ describe('Edit fiscalData path', () => { .wait(selectors.fiscalData.addressInput) .getInputValue(selectors.fiscalData.addressInput) .then(result => { - expect(result).toEqual(`Alpha Flight Low-Orbit`); + expect(result).toEqual('Alpha Flight Low-Orbit'); done(); }) .catch(catchErrors(done)); }); - it(`should edit the city`, done => { + it('should edit the city', done => { nightmare .wait(selectors.fiscalData.cityInput) .clearInput(selectors.fiscalData.cityInput) @@ -172,13 +172,13 @@ describe('Edit fiscalData path', () => { .wait(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive) .then(result => { - expect(result).toEqual(`¡Datos guardados!`); + expect(result).toEqual('¡Datos guardados!'); done(); }) .catch(catchErrors(done)); }); - it(`should confirm the city have been edited`, done => { + it('should confirm the city have been edited', done => { nightmare .waitForSnackbarReset() .click(selectors.basicData.basicDataButton) @@ -187,9 +187,69 @@ describe('Edit fiscalData path', () => { .wait(selectors.fiscalData.cityInput) .getInputValue(selectors.fiscalData.cityInput) .then(result => { - expect(result).toEqual(`N/A`); + expect(result).toEqual('N/A'); done(); }) .catch(catchErrors(done)); }); + + it('should edit the postcode', done => { + nightmare + .wait(selectors.fiscalData.postcodeInput) + .clearInput(selectors.fiscalData.postcodeInput) + .type(selectors.fiscalData.postcodeInput, '12345') + .click(selectors.fiscalData.saveButton) + .wait(selectors.globalItems.snackbarIsActive) + .getInnerText(selectors.globalItems.snackbarIsActive) + .then(result => { + expect(result).toEqual('¡Datos guardados!'); + done(); + }) + .catch(catchErrors(done)); + }); + + it('should confirm the postcode have been edited', done => { + nightmare + .waitForSnackbarReset() + .click(selectors.basicData.basicDataButton) + .wait(selectors.basicData.nameInput) + .click(selectors.fiscalData.fiscalDataButton) + .wait(selectors.fiscalData.postcodeInput) + .getInputValue(selectors.fiscalData.postcodeInput) + .then(result => { + expect(result).toEqual('12345'); + done(); + }) + .catch(catchErrors(done)); + }); + + // it(`should edit the province`, done => { + // nightmare + // .waitToClick(selectors.fiscalData.provinceInput) + // .waitToClick(selectors.fiscalData.provinceInput) + // .waitToClick(selectors.fiscalData.provinceMetropolisOption) + // .waitToClick(selectors.fiscalData.saveButton) + // .wait(selectors.globalItems.snackbarIsActive) + // .getInnerText(selectors.globalItems.snackbarIsActive) + // .then(result => { + // expect(result).toEqual(`¡Datos guardados!`); + // done(); + // }) + // .catch(catchErrors(done)); + // }); + + // it(`should confirm the province have been selected`, done => { + // nightmare + // .waitForSnackbarReset() + // .click(selectors.fiscalData.fiscalDataButton) + // .wait(selectors.fiscalData.addressInput) + // .click(selectors.fiscalData.basicDataButton) + // .wait(100) + // .getInputValue(selectors.fiscalData.provinceInput) + // .then(result => { + // expect(result).toEqual('Province two'); + // done(); + // }) + // .catch(catchErrors(done)); + // }); }); diff --git a/services/client/common/models/address.js b/services/client/common/models/address.js index 8fccf88dbd..6d74933a33 100644 --- a/services/client/common/models/address.js +++ b/services/client/common/models/address.js @@ -11,7 +11,7 @@ module.exports = function(Self) { function create(data, next) { if (data.isDefaultAddress) { - removeAllDefault(data.client, next); + removeAllDefault(data, next); } else { next(); } @@ -25,10 +25,10 @@ module.exports = function(Self) { Self.beforeRemote('findById', function(ctx, modelInstance, next) { ctx.args.filter = { - "include": { - "relation": "province", - "scope": { - "fields": ["id", "name"] + include: { + relation: "province", + scope: { + fields: ["id", "name"] } } }; @@ -44,7 +44,7 @@ module.exports = function(Self) { function callbackGetAddress(ctx, newData, oldData, next) { if (newData.isDefaultAddress) { - removeAllDefault(oldData.client, next); + removeAllDefault(oldData, next); } else if (oldData.isDefaultAddress && newData.hasOwnProperty('isDefaultAddress') && !newData.isDefaultAddress) { next(generateErrorDefaultAddress()); } else @@ -52,7 +52,10 @@ module.exports = function(Self) { } function removeAllDefault(client, next) { - Self.updateAll({clientFk: client.id, isDefaultAddress: {neq: 0}}, {isDefaultAddress: false}, next); + if (client && client.clientFk) + Self.updateAll({clientFk: client.clientFk, isDefaultAddress: {neq: 0}}, {isDefaultAddress: false}, next); + else + next(); } function generateErrorDefaultAddress() { diff --git a/services/db/localDB02Inserts.sql b/services/db/localDB02Inserts.sql index fccac9e2bf..dc859bfbfe 100644 --- a/services/db/localDB02Inserts.sql +++ b/services/db/localDB02Inserts.sql @@ -335,11 +335,11 @@ INSERT INTO `salix`.`Zone`(`id`, `name`, `printingOrder`) INSERT INTO `salix`.`Province`(`id`, `name`, `countryFk`, `warehouseFk`, `zoneFk`) VALUES - (1, 'Provicen one', 1, NULL, 1), - (2, 'Provicen two', 1, NULL, 2), - (3, 'Provicen three', 1, NULL, 3), - (4, 'Provicen four', 1, NULL, 2), - (5, 'Provicen five', 1, NULL, 1); + (1, 'Province one', 1, NULL, 1), + (2, 'Province two', 1, NULL, 2), + (3, 'Province three', 1, NULL, 3), + (4, 'Province four', 1, NULL, 2), + (5, 'Province five', 1, NULL, 1); INSERT INTO `salix`.`ClientType`(`id`, `code`, `type`) VALUES