2020-08-27 09:16:36 +00:00
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('Client', () => {
|
|
|
|
describe('Component vnClientBalancCreate', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
let $httpParamSerializer;
|
|
|
|
|
|
|
|
beforeEach(ngModule('client'));
|
|
|
|
|
|
|
|
beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
|
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
|
|
|
let $scope = $rootScope.$new();
|
|
|
|
const $element = angular.element('<vn-client-balance-create></vn-client-balance-create>');
|
|
|
|
const $transclude = {
|
|
|
|
$$boundTransclude: {
|
|
|
|
$$slots: []
|
|
|
|
}
|
|
|
|
};
|
|
|
|
controller = $componentController('vnClientBalanceCreate', {$element, $scope, $transclude});
|
|
|
|
controller.receipt = {
|
2021-06-23 11:24:23 +00:00
|
|
|
clientFk: 1101,
|
2020-08-27 09:16:36 +00:00
|
|
|
companyFk: 442
|
|
|
|
};
|
2021-11-08 12:02:42 +00:00
|
|
|
controller.bankSelection = {accountingType: {code: 'myCode'}};
|
2020-08-27 09:16:36 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('bankSelection() setter', () => {
|
|
|
|
it('should set the receipt description property', () => {
|
2021-10-27 07:55:35 +00:00
|
|
|
controller.originalDescription = 'Albaran: 1, 2';
|
2020-08-27 09:16:36 +00:00
|
|
|
controller.bankSelection = {
|
|
|
|
id: 1,
|
|
|
|
bank: 'Cash',
|
|
|
|
accountingType: {
|
|
|
|
id: 2,
|
|
|
|
receiptDescription: 'Cash'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-23 14:52:47 +00:00
|
|
|
expect(controller.receipt.description).toEqual('Cash, Albaran: 1, 2');
|
2020-08-27 09:16:36 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-06-22 11:57:32 +00:00
|
|
|
describe('amountToReturn() setter', () => {
|
|
|
|
it('should set the amount to return with a maximum of two decimals', () => {
|
|
|
|
controller.amountToReturn = 200.1451789;
|
|
|
|
|
|
|
|
expect(controller.amountToReturn).toEqual(200.15);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-27 09:16:36 +00:00
|
|
|
describe('getAmountPaid()', () => {
|
|
|
|
it('should make an http GET query and then set the receipt amountPaid property', () => {
|
2021-06-23 11:24:23 +00:00
|
|
|
controller.$params = {id: 1101};
|
2020-08-27 09:16:36 +00:00
|
|
|
const receipt = controller.receipt;
|
|
|
|
const filter = {
|
|
|
|
where: {
|
2021-06-23 11:24:23 +00:00
|
|
|
clientFk: 1101,
|
2020-08-27 09:16:36 +00:00
|
|
|
companyFk: 442
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const serializedParams = $httpParamSerializer({filter});
|
2020-10-26 07:38:43 +00:00
|
|
|
$httpBackend.expect('GET', `ClientRisks?${serializedParams}`).respond([{amount: 20}]);
|
2020-08-27 09:16:36 +00:00
|
|
|
controller.getAmountPaid();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(receipt.amountPaid).toEqual(20);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('responseHandler()', () => {
|
|
|
|
it('should make an http POST query and then call to the parent responseHandler() method', () => {
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
2021-06-22 11:57:32 +00:00
|
|
|
jest.spyOn(controller.vnReport, 'show');
|
|
|
|
|
2021-06-23 12:21:48 +00:00
|
|
|
controller.$params = {id: 1101};
|
2021-06-22 11:57:32 +00:00
|
|
|
|
2021-06-23 12:21:48 +00:00
|
|
|
$httpBackend.expect('POST', `Clients/1101/createReceipt`).respond({id: 1});
|
2021-06-22 11:57:32 +00:00
|
|
|
controller.responseHandler('accept');
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
|
|
expect(controller.vnReport.show).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should make an http POST query and then call to the report show() method', () => {
|
2022-10-24 07:49:51 +00:00
|
|
|
const receiptId = 1;
|
|
|
|
|
2021-06-22 11:57:32 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
jest.spyOn(controller.vnReport, 'show');
|
|
|
|
window.open = jest.fn();
|
2020-08-27 09:16:36 +00:00
|
|
|
|
2021-06-23 11:24:23 +00:00
|
|
|
controller.$params = {id: 1101};
|
2021-06-22 11:57:32 +00:00
|
|
|
controller.viewReceipt = true;
|
2020-08-27 09:16:36 +00:00
|
|
|
|
2022-10-24 07:49:51 +00:00
|
|
|
$httpBackend.expect('POST', `Clients/1101/createReceipt`).respond({id: receiptId});
|
2020-08-27 09:16:36 +00:00
|
|
|
controller.responseHandler('accept');
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
2022-10-24 07:49:51 +00:00
|
|
|
expect(controller.vnReport.show).toHaveBeenCalledWith(`Receipts/${receiptId}/receipt-pdf`);
|
2020-08-27 09:16:36 +00:00
|
|
|
});
|
|
|
|
});
|
2020-12-16 15:25:19 +00:00
|
|
|
|
|
|
|
describe('deliveredAmount() setter', () => {
|
|
|
|
it('should set the deliveredAmount property', () => {
|
|
|
|
controller.amountPaid = 999;
|
|
|
|
controller.deliveredAmount = 1000;
|
|
|
|
|
|
|
|
expect(controller.amountToReturn).toEqual(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('accountShortToStandard()', () => {
|
|
|
|
it('should get de account in stardard format', () => {
|
|
|
|
const shortAccount = '4.3';
|
|
|
|
controller.accountShortToStandard(shortAccount);
|
|
|
|
|
|
|
|
expect(controller.receipt.compensationAccount).toEqual('4000000003');
|
|
|
|
});
|
|
|
|
});
|
2021-09-03 12:00:47 +00:00
|
|
|
|
|
|
|
describe('bankSearchFunc()', () => {
|
|
|
|
it('should return the filter by id property for an input of a number', () => {
|
|
|
|
const bankId = 1;
|
|
|
|
const result = controller.bankSearchFunc(bankId);
|
|
|
|
|
|
|
|
expect(result).toEqual({id: bankId});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return the filter by bank property for an input of an string', () => {
|
|
|
|
const bankName = 'Bank of America';
|
|
|
|
const result = controller.bankSearchFunc(bankName);
|
|
|
|
|
|
|
|
expect(result).toEqual({bank: {like: '%' + bankName + '%'}});
|
|
|
|
});
|
|
|
|
});
|
2020-08-27 09:16:36 +00:00
|
|
|
});
|
|
|
|
});
|