This commit is contained in:
Carlos 2017-11-09 14:52:16 +01:00
commit 7c37ded182
10 changed files with 172 additions and 91 deletions

18
Jenkinsfile vendored
View File

@ -3,22 +3,24 @@
def branchName = "${env.BRANCH_NAME}"; def branchName = "${env.BRANCH_NAME}";
def branchProduction = "master" def branchProduction = "master"
def branchTest = "test"; def branchTest = "test";
def dockerHost = "${env.DOCKER_HOST}";
env.NODE_ENV = branchName;
env.BRANCH_NAME = branchName; env.BRANCH_NAME = branchName;
env.TAG = "${env.BUILD_NUMBER}"; env.TAG = "${env.BUILD_NUMBER}";
if (branchName == "test") switch (branchName){
env.NODE_ENV = "development"; case branchTest:
env.NODE_ENV = "development";
if (branchName == branchProduction) break;
dockerHost = "tcp://172.16.255.29:2375"; case branchProduction:
env.DOCKER_HOST = "tcp://172.16.255.29:2375";
env.NODE_ENV = "production"
break;
}
node node
{ {
stage ('Print environment variables'){ 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') { stage ('Checkout') {
checkout scm checkout scm

View File

@ -18,18 +18,18 @@
</vn-one> </vn-one>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-textfield vn-two label="Domicilio fiscal" field="$ctrl.client.street" vn-focus></vn-textfield> <vn-textfield vn-two label="Street" field="$ctrl.client.street" vn-focus></vn-textfield>
<vn-textfield vn-one label="Municipio" field="$ctrl.client.city"></vn-textfield> <vn-textfield vn-one label="City" field="$ctrl.client.city"></vn-textfield>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-textfield vn-one label="Código postal" field="$ctrl.client.postcode"></vn-textfield> <vn-textfield vn-one label="Postcode" field="$ctrl.client.postcode"></vn-textfield>
<vn-autocomplete vn-one <vn-autocomplete vn-one
initial-data="$ctrl.client.province" initial-data="$ctrl.client.province"
field="$ctrl.client.provinceFk" field="$ctrl.client.provinceFk"
url="/client/api/Provinces" url="/client/api/Provinces"
show-field="name" show-field="name"
value-field="id" value-field="id"
label="Provincia"> label="Province">
</vn-autocomplete> </vn-autocomplete>
<vn-autocomplete vn-one <vn-autocomplete vn-one
initial-data="$ctrl.client.country" initial-data="$ctrl.client.country"
@ -37,13 +37,13 @@
url="/client/api/Countries" url="/client/api/Countries"
show-field="name" show-field="name"
value-field="id" value-field="id"
label="CountryFk"> label="Country">
</vn-autocomplete> </vn-autocomplete>
</vn-horizontal> </vn-horizontal>
</vn-vertical> </vn-vertical>
</vn-card> </vn-card>
<vn-button-bar> <vn-button-bar>
<vn-submit label="Guardar"></vn-submit> <vn-submit label="Save"></vn-submit>
</vn-button-bar> </vn-button-bar>
</form> </form>

View File

@ -4,5 +4,10 @@
"Fiscal data": "Datos Fiscales", "Fiscal data": "Datos Fiscales",
"Has to invoice": "Factura", "Has to invoice": "Factura",
"Invoice by mail": "Factura impresa", "Invoice by mail": "Factura impresa",
"CountryFk": "País" "Country": "País",
"Street": "Domicilio fiscal",
"City": "Municipio",
"Postcode": "Código postal",
"Province": "Provincia",
"Save": "Guardar"
} }

View File

@ -11,8 +11,8 @@ function loader(moduleName, validations) {
return load; return load;
} }
config.$inject = ['$stateProvider', '$urlRouterProvider', 'aclServiceProvider']; config.$inject = ['$stateProvider', '$urlRouterProvider', 'aclServiceProvider', 'modulesFactoryProvider'];
function config($stateProvider, $urlRouterProvider, aclServiceProvider) { function config($stateProvider, $urlRouterProvider, aclServiceProvider, modulesFactory) {
splitingRegister.registerGraph(deps); splitingRegister.registerGraph(deps);
let aclService = aclServiceProvider.$get(); let aclService = aclServiceProvider.$get();
@ -41,21 +41,28 @@ function config($stateProvider, $urlRouterProvider, aclServiceProvider) {
let fileRoutes = window.routes[file].routes; let fileRoutes = window.routes[file].routes;
let moduleName = window.routes[file].module; let moduleName = window.routes[file].module;
let validations = window.routes[file].validations || false; let validations = window.routes[file].validations || false;
fileRoutes.forEach(function(route) { let mainModule = modulesFactory.$get().getMainRoute(fileRoutes);
if (aclService.routeHasPermission(route)) { if (mainModule) {
$stateProvider.state(route.state, { let count = fileRoutes.length;
url: route.url, for (let i = 0; i < count; i++) {
abstract: route.abstract || false, let route = fileRoutes[i];
template: `<${route.component} ${getParams(route)}></${route.component}>`, if (aclService.routeHasPermission(route)) {
resolve: { $stateProvider.state(route.state, {
loader: loader(moduleName, validations) url: route.url,
}, abstract: route.abstract || false,
data: { template: `<${route.component} ${getParams(route)}></${route.component}>`,
routes: fileRoutes resolve: {
} loader: loader(moduleName, validations)
}); },
data: {
routes: fileRoutes
}
});
} else if (route.state === mainModule.state) {
break;
}
} }
}); }
} }
} }
ngModule.config(config); ngModule.config(config);

View File

@ -1,7 +1,7 @@
import ngModule from './module'; import ngModule from './module';
function modulesFactory(aclService) { function modulesFactory(aclService) {
function _getMainRoute(routeCollection) { function getMainRoute(routeCollection) {
let cant = routeCollection.length; let cant = routeCollection.length;
for (let i = 0; i < cant; i++) { for (let i = 0; i < cant; i++) {
if (!routeCollection[i].abstract) { if (!routeCollection[i].abstract) {
@ -18,7 +18,7 @@ function modulesFactory(aclService) {
name: routes[file].name || routes[file].module, name: routes[file].name || routes[file].module,
icon: routes[file].icon || '' icon: routes[file].icon || ''
}; };
let mainRoute = _getMainRoute(window.routes[file].routes); let mainRoute = getMainRoute(window.routes[file].routes);
if (mainRoute && aclService.routeHasPermission(mainRoute)) { if (mainRoute && aclService.routeHasPermission(mainRoute)) {
card.route = mainRoute; card.route = mainRoute;
modules.push(card); modules.push(card);
@ -28,7 +28,8 @@ function modulesFactory(aclService) {
} }
return { return {
getModules: getModules getModules: getModules,
getMainRoute: getMainRoute
}; };
} }
modulesFactory.$inject = ['aclService']; modulesFactory.$inject = ['aclService'];

View File

@ -54,6 +54,9 @@ export default {
invoiceByMailCheckboxInput: `${components.vnCheck}[label='Invoice by mail'] > label > label > input`, invoiceByMailCheckboxInput: `${components.vnCheck}[label='Invoice by mail'] > label > label > input`,
addressInput: `${components.vnTextfield}[name="street"]`, addressInput: `${components.vnTextfield}[name="street"]`,
cityInput: `${components.vnTextfield}[name="city"]`, 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' 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'
} }
}; };

View File

@ -45,7 +45,7 @@ describe('Edit basicData path', () => {
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
it(`should search for the user Bruce Wayne`, done => { it('should search for the user Bruce Wayne', done => {
nightmare nightmare
.wait(selectors.clientsIndex.searchResult) .wait(selectors.clientsIndex.searchResult)
.type(selectors.clientsIndex.searchClientInput, 'Bruce Wayne') .type(selectors.clientsIndex.searchClientInput, 'Bruce Wayne')
@ -59,7 +59,7 @@ describe('Edit basicData path', () => {
.catch(catchErrors(done)); .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 nightmare
.waitForTextInElement(selectors.clientsIndex.searchResult, 'Bruce Wayne') .waitForTextInElement(selectors.clientsIndex.searchResult, 'Bruce Wayne')
.waitToClick(selectors.clientsIndex.searchResult) .waitToClick(selectors.clientsIndex.searchResult)
@ -72,7 +72,7 @@ describe('Edit basicData path', () => {
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
it(`should edit the name`, done => { it('should edit the name', done => {
nightmare nightmare
.wait(selectors.basicData.nameInput) .wait(selectors.basicData.nameInput)
.clearInput(selectors.basicData.nameInput) .clearInput(selectors.basicData.nameInput)
@ -81,13 +81,13 @@ describe('Edit basicData path', () => {
.wait(selectors.globalItems.snackbarIsActive) .wait(selectors.globalItems.snackbarIsActive)
.getInnerText(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive)
.then(result => { .then(result => {
expect(result).toEqual(`¡Datos guardados!`); expect(result).toEqual('¡Datos guardados!');
done(); done();
}) })
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
it(`should confirm the name have been edited`, done => { it('should confirm the name have been edited', done => {
nightmare nightmare
.waitForSnackbarReset() .waitForSnackbarReset()
.click(selectors.fiscalData.fiscalDataButton) .click(selectors.fiscalData.fiscalDataButton)
@ -96,13 +96,13 @@ describe('Edit basicData path', () => {
.wait(selectors.basicData.nameInput) .wait(selectors.basicData.nameInput)
.getInputValue(selectors.basicData.nameInput) .getInputValue(selectors.basicData.nameInput)
.then(result => { .then(result => {
expect(result).toEqual(`Carol Danvers Edited`); expect(result).toEqual('Carol Danvers Edited');
done(); done();
}) })
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
it(`should edit the tax number`, done => { it('should edit the tax number', done => {
nightmare nightmare
.wait(selectors.basicData.taxNumberInput) .wait(selectors.basicData.taxNumberInput)
.clearInput(selectors.basicData.taxNumberInput) .clearInput(selectors.basicData.taxNumberInput)
@ -111,13 +111,13 @@ describe('Edit basicData path', () => {
.wait(selectors.globalItems.snackbarIsActive) .wait(selectors.globalItems.snackbarIsActive)
.getInnerText(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive)
.then(result => { .then(result => {
expect(result).toEqual(`¡Datos guardados!`); expect(result).toEqual('¡Datos guardados!');
done(); done();
}) })
.catch(catchErrors(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 nightmare
.waitForSnackbarReset() .waitForSnackbarReset()
.click(selectors.fiscalData.fiscalDataButton) .click(selectors.fiscalData.fiscalDataButton)
@ -126,13 +126,13 @@ describe('Edit basicData path', () => {
.wait(selectors.basicData.taxNumberInput) .wait(selectors.basicData.taxNumberInput)
.getInputValue(selectors.basicData.taxNumberInput) .getInputValue(selectors.basicData.taxNumberInput)
.then(result => { .then(result => {
expect(result).toEqual(`AVG tax Edited`); expect(result).toEqual('AVG tax Edited');
done(); done();
}) })
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
it(`should edit the social name`, done => { it('should edit the social name', done => {
nightmare nightmare
.wait(selectors.basicData.socialNameInput) .wait(selectors.basicData.socialNameInput)
.clearInput(selectors.basicData.socialNameInput) .clearInput(selectors.basicData.socialNameInput)
@ -141,13 +141,13 @@ describe('Edit basicData path', () => {
.wait(selectors.globalItems.snackbarIsActive) .wait(selectors.globalItems.snackbarIsActive)
.getInnerText(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive)
.then(result => { .then(result => {
expect(result).toEqual(`¡Datos guardados!`); expect(result).toEqual('¡Datos guardados!');
done(); done();
}) })
.catch(catchErrors(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 nightmare
.waitForSnackbarReset() .waitForSnackbarReset()
.click(selectors.fiscalData.fiscalDataButton) .click(selectors.fiscalData.fiscalDataButton)
@ -156,13 +156,13 @@ describe('Edit basicData path', () => {
.wait(selectors.basicData.socialNameInput) .wait(selectors.basicData.socialNameInput)
.getInputValue(selectors.basicData.socialNameInput) .getInputValue(selectors.basicData.socialNameInput)
.then(result => { .then(result => {
expect(result).toEqual(`Avengers Team Edited`); expect(result).toEqual('Avengers Team Edited');
done(); done();
}) })
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
it(`should add the landline phone number`, done => { it('should add the landline phone number', done => {
nightmare nightmare
.wait(selectors.basicData.phoneInput) .wait(selectors.basicData.phoneInput)
.clearInput(selectors.basicData.phoneInput) .clearInput(selectors.basicData.phoneInput)
@ -171,13 +171,13 @@ describe('Edit basicData path', () => {
.wait(selectors.globalItems.snackbarIsActive) .wait(selectors.globalItems.snackbarIsActive)
.getInnerText(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive)
.then(result => { .then(result => {
expect(result).toEqual(`¡Datos guardados!`); expect(result).toEqual('¡Datos guardados!');
done(); done();
}) })
.catch(catchErrors(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 nightmare
.waitForSnackbarReset() .waitForSnackbarReset()
.click(selectors.fiscalData.fiscalDataButton) .click(selectors.fiscalData.fiscalDataButton)
@ -192,7 +192,7 @@ describe('Edit basicData path', () => {
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
it(`should add the mobile phone number`, done => { it('should add the mobile phone number', done => {
nightmare nightmare
.wait(selectors.basicData.mobileInput) .wait(selectors.basicData.mobileInput)
.clearInput(selectors.basicData.mobileInput) .clearInput(selectors.basicData.mobileInput)
@ -201,13 +201,13 @@ describe('Edit basicData path', () => {
.wait(selectors.globalItems.snackbarIsActive) .wait(selectors.globalItems.snackbarIsActive)
.getInnerText(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive)
.then(result => { .then(result => {
expect(result).toEqual(`¡Datos guardados!`); expect(result).toEqual('¡Datos guardados!');
done(); done();
}) })
.catch(catchErrors(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 nightmare
.waitForSnackbarReset() .waitForSnackbarReset()
.click(selectors.fiscalData.fiscalDataButton) .click(selectors.fiscalData.fiscalDataButton)
@ -222,7 +222,7 @@ describe('Edit basicData path', () => {
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
it(`should add the fax number`, done => { it('should add the fax number', done => {
nightmare nightmare
.wait(selectors.basicData.faxInput) .wait(selectors.basicData.faxInput)
.clearInput(selectors.basicData.faxInput) .clearInput(selectors.basicData.faxInput)
@ -231,13 +231,13 @@ describe('Edit basicData path', () => {
.wait(selectors.globalItems.snackbarIsActive) .wait(selectors.globalItems.snackbarIsActive)
.getInnerText(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive)
.then(result => { .then(result => {
expect(result).toEqual(`¡Datos guardados!`); expect(result).toEqual('¡Datos guardados!');
done(); done();
}) })
.catch(catchErrors(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 nightmare
.waitForSnackbarReset() .waitForSnackbarReset()
.click(selectors.fiscalData.fiscalDataButton) .click(selectors.fiscalData.fiscalDataButton)
@ -252,7 +252,7 @@ describe('Edit basicData path', () => {
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
it(`should edit the email`, done => { it('should edit the email', done => {
nightmare nightmare
.wait(selectors.basicData.emailInput) .wait(selectors.basicData.emailInput)
.clearInput(selectors.basicData.emailInput) .clearInput(selectors.basicData.emailInput)
@ -261,13 +261,13 @@ describe('Edit basicData path', () => {
.wait(selectors.globalItems.snackbarIsActive) .wait(selectors.globalItems.snackbarIsActive)
.getInnerText(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive)
.then(result => { .then(result => {
expect(result).toEqual(`¡Datos guardados!`); expect(result).toEqual('¡Datos guardados!');
done(); done();
}) })
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
it(`should confirm the email have been edited`, done => { it('should confirm the email have been edited', done => {
nightmare nightmare
.waitForSnackbarReset() .waitForSnackbarReset()
.click(selectors.fiscalData.fiscalDataButton) .click(selectors.fiscalData.fiscalDataButton)
@ -282,7 +282,7 @@ describe('Edit basicData path', () => {
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
// it(`should select the sales person`, done => { // it('should select the sales person', done => {
// nightmare // nightmare
// .wait(selectors.basicData.salesPersonInput) // .wait(selectors.basicData.salesPersonInput)
// .select(selectors.basicData.salesPersonInput, '') // not working quite yet // .select(selectors.basicData.salesPersonInput, '') // not working quite yet
@ -290,13 +290,13 @@ describe('Edit basicData path', () => {
// .wait(selectors.globalItems.snackbarIsActive) // .wait(selectors.globalItems.snackbarIsActive)
// .getInnerText(selectors.globalItems.snackbarIsActive) // .getInnerText(selectors.globalItems.snackbarIsActive)
// .then(result => { // .then(result => {
// expect(result).toEqual(`¡Datos guardados!`); // expect(result).toEqual('¡Datos guardados!');
// done(); // done();
// }) // })
// .catch(catchErrors(done)); // .catch(catchErrors(done));
// }); // });
it(`should select the channel`, done => { it('should select the channel', done => {
nightmare nightmare
.waitToClick(selectors.basicData.channelInput) .waitToClick(selectors.basicData.channelInput)
.waitToClick(selectors.basicData.channelInput) .waitToClick(selectors.basicData.channelInput)
@ -305,13 +305,13 @@ describe('Edit basicData path', () => {
.wait(selectors.globalItems.snackbarIsActive) .wait(selectors.globalItems.snackbarIsActive)
.getInnerText(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive)
.then(result => { .then(result => {
expect(result).toEqual(`¡Datos guardados!`); expect(result).toEqual('¡Datos guardados!');
done(); done();
}) })
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
it(`should confirm the channel have been selected`, done => { it('should confirm the channel have been selected', done => {
nightmare nightmare
.waitForSnackbarReset() .waitForSnackbarReset()
.click(selectors.fiscalData.fiscalDataButton) .click(selectors.fiscalData.fiscalDataButton)

View File

@ -45,7 +45,7 @@ describe('Edit fiscalData path', () => {
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
it(`should search for the user Bruce Banner`, done => { it('should search for the user Bruce Banner', done => {
nightmare nightmare
.wait(selectors.clientsIndex.searchResult) .wait(selectors.clientsIndex.searchResult)
.type(selectors.clientsIndex.searchClientInput, 'Bruce Banner') .type(selectors.clientsIndex.searchClientInput, 'Bruce Banner')
@ -73,7 +73,7 @@ describe('Edit fiscalData path', () => {
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
it(`should uncheck the hasToInvoice checkbox`, done => { it('should uncheck the hasToInvoice checkbox', done => {
nightmare nightmare
.waitToClick(selectors.fiscalData.hasToInvoiceCheckboxLabel) .waitToClick(selectors.fiscalData.hasToInvoiceCheckboxLabel)
.waitToClick(selectors.fiscalData.saveButton) .waitToClick(selectors.fiscalData.saveButton)
@ -86,7 +86,7 @@ describe('Edit fiscalData path', () => {
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
it(`should confirm hasToInvoice checkbox is unchecked`, done => { it('should confirm hasToInvoice checkbox is unchecked', done => {
nightmare nightmare
.waitForSnackbarReset() .waitForSnackbarReset()
.waitToClick(selectors.basicData.basicDataButton) .waitToClick(selectors.basicData.basicDataButton)
@ -103,7 +103,7 @@ describe('Edit fiscalData path', () => {
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
it(`should uncheck the invoiceByMail checkbox`, done => { it('should uncheck the invoiceByMail checkbox', done => {
nightmare nightmare
.waitToClick(selectors.fiscalData.invoiceByMailCheckboxLabel) .waitToClick(selectors.fiscalData.invoiceByMailCheckboxLabel)
.waitToClick(selectors.fiscalData.saveButton) .waitToClick(selectors.fiscalData.saveButton)
@ -116,7 +116,7 @@ describe('Edit fiscalData path', () => {
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
it(`should confirm invoiceByMail checkbox is unchecked`, done => { it('should confirm invoiceByMail checkbox is unchecked', done => {
nightmare nightmare
.waitForSnackbarReset() .waitForSnackbarReset()
.waitToClick(selectors.basicData.basicDataButton) .waitToClick(selectors.basicData.basicDataButton)
@ -133,7 +133,7 @@ describe('Edit fiscalData path', () => {
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
it(`should edit the address`, done => { it('should edit the address', done => {
nightmare nightmare
.wait(selectors.fiscalData.addressInput) .wait(selectors.fiscalData.addressInput)
.clearInput(selectors.fiscalData.addressInput) .clearInput(selectors.fiscalData.addressInput)
@ -142,13 +142,13 @@ describe('Edit fiscalData path', () => {
.wait(selectors.globalItems.snackbarIsActive) .wait(selectors.globalItems.snackbarIsActive)
.getInnerText(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive)
.then(result => { .then(result => {
expect(result).toEqual(`¡Datos guardados!`); expect(result).toEqual('¡Datos guardados!');
done(); done();
}) })
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
it(`should confirm the address have been edited`, done => { it('should confirm the address have been edited', done => {
nightmare nightmare
.waitForSnackbarReset() .waitForSnackbarReset()
.click(selectors.basicData.basicDataButton) .click(selectors.basicData.basicDataButton)
@ -157,13 +157,13 @@ describe('Edit fiscalData path', () => {
.wait(selectors.fiscalData.addressInput) .wait(selectors.fiscalData.addressInput)
.getInputValue(selectors.fiscalData.addressInput) .getInputValue(selectors.fiscalData.addressInput)
.then(result => { .then(result => {
expect(result).toEqual(`Alpha Flight Low-Orbit`); expect(result).toEqual('Alpha Flight Low-Orbit');
done(); done();
}) })
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
it(`should edit the city`, done => { it('should edit the city', done => {
nightmare nightmare
.wait(selectors.fiscalData.cityInput) .wait(selectors.fiscalData.cityInput)
.clearInput(selectors.fiscalData.cityInput) .clearInput(selectors.fiscalData.cityInput)
@ -172,13 +172,13 @@ describe('Edit fiscalData path', () => {
.wait(selectors.globalItems.snackbarIsActive) .wait(selectors.globalItems.snackbarIsActive)
.getInnerText(selectors.globalItems.snackbarIsActive) .getInnerText(selectors.globalItems.snackbarIsActive)
.then(result => { .then(result => {
expect(result).toEqual(`¡Datos guardados!`); expect(result).toEqual('¡Datos guardados!');
done(); done();
}) })
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
it(`should confirm the city have been edited`, done => { it('should confirm the city have been edited', done => {
nightmare nightmare
.waitForSnackbarReset() .waitForSnackbarReset()
.click(selectors.basicData.basicDataButton) .click(selectors.basicData.basicDataButton)
@ -187,9 +187,69 @@ describe('Edit fiscalData path', () => {
.wait(selectors.fiscalData.cityInput) .wait(selectors.fiscalData.cityInput)
.getInputValue(selectors.fiscalData.cityInput) .getInputValue(selectors.fiscalData.cityInput)
.then(result => { .then(result => {
expect(result).toEqual(`N/A`); expect(result).toEqual('N/A');
done(); done();
}) })
.catch(catchErrors(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));
// });
}); });

View File

@ -11,7 +11,7 @@ module.exports = function(Self) {
function create(data, next) { function create(data, next) {
if (data.isDefaultAddress) { if (data.isDefaultAddress) {
removeAllDefault(data.client, next); removeAllDefault(data, next);
} else { } else {
next(); next();
} }
@ -25,10 +25,10 @@ module.exports = function(Self) {
Self.beforeRemote('findById', function(ctx, modelInstance, next) { Self.beforeRemote('findById', function(ctx, modelInstance, next) {
ctx.args.filter = { ctx.args.filter = {
"include": { include: {
"relation": "province", relation: "province",
"scope": { scope: {
"fields": ["id", "name"] fields: ["id", "name"]
} }
} }
}; };
@ -44,7 +44,7 @@ module.exports = function(Self) {
function callbackGetAddress(ctx, newData, oldData, next) { function callbackGetAddress(ctx, newData, oldData, next) {
if (newData.isDefaultAddress) { if (newData.isDefaultAddress) {
removeAllDefault(oldData.client, next); removeAllDefault(oldData, next);
} else if (oldData.isDefaultAddress && newData.hasOwnProperty('isDefaultAddress') && !newData.isDefaultAddress) { } else if (oldData.isDefaultAddress && newData.hasOwnProperty('isDefaultAddress') && !newData.isDefaultAddress) {
next(generateErrorDefaultAddress()); next(generateErrorDefaultAddress());
} else } else
@ -52,7 +52,10 @@ module.exports = function(Self) {
} }
function removeAllDefault(client, next) { 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() { function generateErrorDefaultAddress() {

View File

@ -335,11 +335,11 @@ INSERT INTO `salix`.`Zone`(`id`, `name`, `printingOrder`)
INSERT INTO `salix`.`Province`(`id`, `name`, `countryFk`, `warehouseFk`, `zoneFk`) INSERT INTO `salix`.`Province`(`id`, `name`, `countryFk`, `warehouseFk`, `zoneFk`)
VALUES VALUES
(1, 'Provicen one', 1, NULL, 1), (1, 'Province one', 1, NULL, 1),
(2, 'Provicen two', 1, NULL, 2), (2, 'Province two', 1, NULL, 2),
(3, 'Provicen three', 1, NULL, 3), (3, 'Province three', 1, NULL, 3),
(4, 'Provicen four', 1, NULL, 2), (4, 'Province four', 1, NULL, 2),
(5, 'Provicen five', 1, NULL, 1); (5, 'Province five', 1, NULL, 1);
INSERT INTO `salix`.`ClientType`(`id`, `code`, `type`) INSERT INTO `salix`.`ClientType`(`id`, `code`, `type`)
VALUES VALUES