salix/modules/invoiceOut/front/global-invoicing/index.spec.js

83 lines
3.1 KiB
JavaScript
Raw Normal View History

2022-12-29 10:47:12 +00:00
import './index';
2023-02-23 08:25:23 +00:00
const UserError = require('vn-loopback/util/user-error');
2022-12-29 10:47:12 +00:00
describe('InvoiceOut', () => {
describe('Component vnInvoiceOutGlobalInvoicing', () => {
let controller;
let $httpBackend;
let $httpParamSerializer;
beforeEach(ngModule('invoiceOut'));
beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
$httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_;
let $scope = $rootScope.$new();
const $element = angular.element('<vn-invoice-out-global-invoicing></vn-invoice-out-global-invoicing>');
const $transclude = {
$$boundTransclude: {
$$slots: []
}
};
controller = $componentController('vnInvoiceOutGlobalInvoicing', {$element, $scope, $transclude});
controller.$.invoiceButton = {disabled: false};
}));
2022-12-27 11:21:04 +00:00
2022-12-29 10:47:12 +00:00
describe('makeInvoice()', () => {
it('should throw an error when invoiceDate or maxShipped properties are not filled in', () => {
jest.spyOn(controller.vnApp, 'showError');
2023-02-23 08:25:23 +00:00
controller.clientsToInvoice = 'all';
2022-12-29 10:47:12 +00:00
2023-02-23 08:25:23 +00:00
let error;
try {
controller.makeInvoice();
} catch (e) {
error = e.message;
}
2022-12-29 10:47:12 +00:00
const expectedError = 'Invoice date and the max date should be filled';
2023-02-23 08:25:23 +00:00
expect(error).toBe(expectedError);
2022-12-29 10:47:12 +00:00
});
2023-02-23 08:25:23 +00:00
it('should throw an error when select one client and clientId is not filled in', () => {
2022-12-29 10:47:12 +00:00
jest.spyOn(controller.vnApp, 'showError');
2023-02-23 08:25:23 +00:00
controller.clientsToInvoice = 'one';
2022-12-29 10:47:12 +00:00
2023-02-23 08:25:23 +00:00
let error;
try {
controller.makeInvoice();
} catch (e) {
error = e.message;
}
2022-12-29 10:47:12 +00:00
2023-02-23 08:25:23 +00:00
const expectedError = 'Choose a valid client';
2022-12-29 10:47:12 +00:00
2023-02-23 08:25:23 +00:00
expect(error).toBe(expectedError);
2022-12-29 10:47:12 +00:00
});
it('should make an http POST query and then call to the showSuccess() method', () => {
jest.spyOn(controller.vnApp, 'showSuccess');
2023-02-23 08:25:23 +00:00
const date = Date.vnNew();
date.setDate(date.getDate() + 1);
controller.invoiceDate = date;
controller.maxShipped = date;
controller.minInvoicingDate = Date.vnNew();
controller.clientsToInvoice = 'one';
controller.clientId = 1101;
controller.companyFk = 442;
controller.printerFk = 1;
const response = [{
clientId: 1101,
id: 121
}];
2022-12-29 10:47:12 +00:00
$httpBackend.expect('POST', `InvoiceOuts/clientsToInvoice`).respond(response);
2023-02-23 08:25:23 +00:00
$httpBackend.expect('POST', `InvoiceOuts/invoiceClient`).respond(1);
2022-12-29 10:47:12 +00:00
controller.makeInvoice();
$httpBackend.flush();
2023-02-23 08:25:23 +00:00
expect(controller.status).toEqual('done');
2022-12-29 10:47:12 +00:00
});
2022-12-27 11:21:04 +00:00
});
});
});