diff --git a/loopback/locale/es.json b/loopback/locale/es.json
index b54c0cc675..d493f99e31 100644
--- a/loopback/locale/es.json
+++ b/loopback/locale/es.json
@@ -166,5 +166,7 @@
"The selected ticket is not suitable for this route": "El ticket seleccionado no es apto para esta ruta",
"Sorts whole route": "Reordena ruta entera",
"New ticket request has been created with price": "Se ha creado una nueva petición de compra '{{description}}' para el día {{shipped}}, con una cantidad de {{quantity}} y un precio de {{price}} €",
- "New ticket request has been created": "Se ha creado una nueva petición de compra '{{description}}' para el día {{shipped}}, con una cantidad de {{quantity}}"
+ "New ticket request has been created": "Se ha creado una nueva petición de compra '{{description}}' para el día {{shipped}}, con una cantidad de {{quantity}}",
+ "Swift / BIC cannot be empty": "Swift / BIC no puede estar vacío",
+ "This BIC already exist.": "Este BIC ya existe."
}
\ No newline at end of file
diff --git a/modules/client/back/models/bank-entity.js b/modules/client/back/models/bank-entity.js
index 4cfa7fc918..565c27752c 100644
--- a/modules/client/back/models/bank-entity.js
+++ b/modules/client/back/models/bank-entity.js
@@ -1,8 +1,11 @@
module.exports = Self => {
Self.validatesPresenceOf('name', {
- message: `Name cannot be blank`
+ message: 'Name cannot be blank'
});
Self.validatesPresenceOf('bic', {
- message: `Swift / BIC can't be empty`
+ message: 'Swift / BIC cannot be empty'
+ });
+ Self.validatesUniquenessOf('bic', {
+ message: 'This BIC already exist.'
});
};
diff --git a/modules/supplier/front/account/index.html b/modules/supplier/front/account/index.html
index ce908b0040..5a9addeea4 100644
--- a/modules/supplier/front/account/index.html
+++ b/modules/supplier/front/account/index.html
@@ -63,7 +63,7 @@
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/modules/supplier/front/account/index.spec.js b/modules/supplier/front/account/index.spec.js
index 34a9ce143d..448db07779 100644
--- a/modules/supplier/front/account/index.spec.js
+++ b/modules/supplier/front/account/index.spec.js
@@ -1,34 +1,68 @@
import './index.js';
-import crudModel from 'core/mocks/crud-model';
-describe('Item', () => {
- describe('Component vnItemTags', () => {
- let $scope;
- let controller;
+describe('Supplier Component vnSupplierAccount', () => {
+ let $scope;
+ let $element;
+ let controller;
+ let $httpBackend;
+ beforeEach(ngModule('supplier'));
- beforeEach(ngModule('item'));
+ beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
+ $httpBackend = _$httpBackend_;
+ $scope = $rootScope.$new();
+ $scope.bankEntity = {
+ show: () => {}
+ };
+ $element = angular.element('');
+ controller = $componentController('vnSupplierAccount', {$element, $scope});
+ controller.supplierAccount = {
+ supplierFk: 442,
+ name: 'Verdnatura'
+ };
+ }));
- beforeEach(inject(($componentController, $rootScope) => {
- $scope = $rootScope.$new();
- $scope.model = crudModel;
- $scope.model.data = [{priority: 1}, {priority: 2}, {priority: 1}];
- const $element = angular.element('');
- controller = $componentController('vnItemTags', {$element, $scope});
- }));
+ describe('showBankEntity()', () => {
+ it('should do nothing if it default is prevented', () => {
+ const event = {
+ defaultPrevented: true,
+ preventDefault: () => {}
+ };
+ jest.spyOn(event, 'preventDefault');
+ jest.spyOn(controller.$.bankEntity, 'show');
- describe('getHighestPriority', () => {
- it('should return the highest priority value + 1 from the array', () => {
- let result = controller.getHighestPriority();
+ controller.showBankEntity(event);
- expect(result).toEqual(3);
- });
+ expect(event.preventDefault).not.toHaveBeenCalledWith();
+ expect(controller.$.bankEntity.show).not.toHaveBeenCalledWith();
+ });
- it('should return 1 when there is no priority defined', () => {
- $scope.model.data = [];
- let result = controller.getHighestPriority();
+ it('should call preventDefault() and show() when the default is not prevented', () => {
+ const event = {
+ defaultPrevented: false,
+ preventDefault: () => {}
+ };
+ jest.spyOn(event, 'preventDefault');
+ jest.spyOn(controller.$.bankEntity, 'show');
- expect(result).toEqual(1);
- });
+ controller.showBankEntity(event);
+
+ expect(event.preventDefault).toHaveBeenCalledWith();
+ expect(controller.$.bankEntity.show).toHaveBeenCalledWith();
+ });
+
+ it('should request to create a new bank entity', () => {
+ controller.bankEntity = {
+ name: 'My new bank entity',
+ bic: 'ES1234',
+ countryFk: 1,
+ id: 2200
+ };
+ $httpBackend.expectPATCH(`SupplierAccounts/${controller.$.bankEntity.id}/createBankEntity`).respond({id: 2200});
+ controller.onBankEntityAccept();
+ $httpBackend.flush();
+
+ expect(controller.supplierAccount.bankEntityFk).toEqual(controller.bankEntity.id);
});
});
});
+
diff --git a/modules/supplier/front/bankentity/index.html b/modules/supplier/front/bankentity/index.html
index 55b40f4816..74a302d069 100644
--- a/modules/supplier/front/bankentity/index.html
+++ b/modules/supplier/front/bankentity/index.html
@@ -1,6 +1,6 @@
diff --git a/modules/supplier/front/bankentity/index.js b/modules/supplier/front/bankentity/index.js
index babf64c115..322afc78f6 100644
--- a/modules/supplier/front/bankentity/index.js
+++ b/modules/supplier/front/bankentity/index.js
@@ -3,11 +3,7 @@ import Component from 'core/lib/component';
import './style.scss';
class Controller extends Component {
- open() {
- this.$.bankEntityDialog.show();
- }
-
- onOpen() {
+ resetLocation() {
this.location = {};
}
@@ -20,7 +16,7 @@ class Controller extends Component {
if (!this.location.countryFk)
throw new Error(`The country can't be empty`);
- this.$http.patch(`bankentities`, this.location).then(() => {
+ this.$http.post(`Bankentities`, this.location).then(() => {
this.vnApp.showMessage(this.$t('The bank entity has been created. You can save the data now'));
this.emit('response', {$response: this.location});
});
@@ -32,7 +28,7 @@ class Controller extends Component {
}
}
-ngModule.vnComponent('vnNewBankentity', {
+ngModule.vnComponent('vnNewBankEntity', {
template: require('./index.html'),
controller: Controller,
bindings: {
diff --git a/modules/supplier/front/bankentity/index.spec.js b/modules/supplier/front/bankentity/index.spec.js
index b999ab21f2..84273ded80 100644
--- a/modules/supplier/front/bankentity/index.spec.js
+++ b/modules/supplier/front/bankentity/index.spec.js
@@ -1,34 +1,53 @@
import './index';
-describe('Supplier', () => {
- describe('Component vnNewBankentity', () => {
- let controller;
- let $httpBackend;
- let $scope;
+describe('Supplier Component vnNewBankEntity', () => {
+ let controller;
+ let $httpBackend;
+ let $scope;
+ let $element;
+ let vnApp;
- beforeEach(ngModule('supplier'));
+ beforeEach(ngModule('supplier'));
- beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
- $httpBackend = _$httpBackend_;
- $scope = $rootScope.$new();
- const $element = angular.element('');
- controller = $componentController('vnNewBankentity', {$element, $scope});
- controller.client = {id: 101};
- }));
+ beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _vnApp_) => {
+ $httpBackend = _$httpBackend_;
+ vnApp = _vnApp_;
+ jest.spyOn(vnApp, 'showError');
+ $scope = $rootScope.$new();
+ $element = angular.element('');
+ controller = $componentController('vnNewBankEntity', {$element, $scope});
+ }));
- describe('onAccept()', () => {
- it('should perform a POST query and show a success snackbar', () => {
- let params = {countryFk: 1};
- controller.location = {countryFk: 1};
+ describe('resetLocation()', () => {
+ it('should reset the location in the controller', () => {
+ expect(controller.location).toBeUndefined();
- jest.spyOn(controller.vnApp, 'showMessage');
- $httpBackend.expect('PATCH', `bankentity`, params).respond(200, params);
+ controller.resetLocation();
- controller.onAccept();
- $httpBackend.flush();
+ expect(controller.location).toEqual({});
+ });
+ });
- expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The bank entity has been created. You can save the data now');
- });
+ describe('onAccept()', () => {
+ it('should throw an error if there is no country id in the location', () => {
+ jest.spyOn(controller.vnApp, 'showMessage');
+
+ controller.location = {};
+
+ controller.onAccept();
+
+ expect(controller.vnApp.showError).toHaveBeenCalledWith(`The country can't be empty`);
+ });
+
+ it('should do add the new bank entity', () => {
+ controller.location = {
+ countryFk: 1
+ };
+
+ $httpBackend.expectPOST('Bankentities', controller.location).respond(200, controller.location);
+
+ controller.onAccept();
+ $httpBackend.flush();
});
});
});
diff --git a/modules/supplier/front/bankentity/style.scss b/modules/supplier/front/bankentity/style.scss
index adad7ab019..1171366da2 100644
--- a/modules/supplier/front/bankentity/style.scss
+++ b/modules/supplier/front/bankentity/style.scss
@@ -1,6 +1,6 @@
@import "variables";
-vn-new-bankentity {
+vn-new-bank-entity {
vn-dialog {
p {
color: $color-alert