fix(supplier_account): fix setWireTransfer and add test
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-03-01 10:44:46 +01:00
parent 2137a34b36
commit a27a48f251
2 changed files with 38 additions and 0 deletions

View File

@ -45,6 +45,16 @@ class Controller extends Section {
this.$.payMethodToTransfer.show();
});
}
setWireTransfer() {
const params = {
id: this.$params.id,
payMethodFk: this.wireTransferFk
};
const query = `Suppliers/${this.$params.id}`;
return this.$http.patch(query, params)
.then(() => this.$.watcher.notifySaved());
}
}
ngModule.vnComponent('vnSupplierAccount', {

View File

@ -5,9 +5,12 @@ import crudModel from 'core/mocks/crud-model';
describe('Supplier Component vnSupplierAccount', () => {
let $scope;
let controller;
let $httpBackend;
beforeEach(ngModule('supplier'));
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
$scope.model = crudModel;
$scope.watcher = watcher;
@ -66,5 +69,30 @@ describe('Supplier Component vnSupplierAccount', () => {
}).catch(done.fail);
});
});
describe('setWireTransfer()', () => {
it(`should make HTTP PATCH request to set wire transfer and call notifySaved`, () => {
const supplierId = 1;
const params = {
id: supplierId,
payMethodFk: 2
};
const response = {
data: {id: 2}
};
const uri = 'payMethods/findOne?filter=%7B%22where%22:%7B%22code%22:%22wireTransfer%22%7D%7D';
jest.spyOn($scope.watcher, 'notifySaved');
controller.$params.id = supplierId;
controller.wireTransferFk = 2;
controller.supplier = {payMethodFk: 1};
$httpBackend.expectGET(uri).respond(response);
$httpBackend.expectPATCH(`Suppliers/${supplierId}`, params).respond();
controller.setWireTransfer();
$httpBackend.flush();
expect($scope.watcher.notifySaved).toHaveBeenCalledWith();
});
});
});