2022-12-29 10:47:12 +00:00
|
|
|
import './index';
|
2023-02-23 08:45:15 +00:00
|
|
|
|
2022-12-29 10:47:12 +00:00
|
|
|
describe('InvoiceOut', () => {
|
|
|
|
describe('Component vnInvoiceOutGlobalInvoicing', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
|
|
|
|
beforeEach(ngModule('invoiceOut'));
|
|
|
|
|
2023-02-23 08:45:15 +00:00
|
|
|
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
|
2022-12-29 10:47:12 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
2023-02-23 08:45:15 +00:00
|
|
|
const $scope = $rootScope.$new();
|
2022-12-29 10:47:12 +00:00
|
|
|
const $element = angular.element('<vn-invoice-out-global-invoicing></vn-invoice-out-global-invoicing>');
|
2023-02-23 08:45:15 +00:00
|
|
|
|
|
|
|
controller = $componentController('vnInvoiceOutGlobalInvoicing', {$element, $scope});
|
2022-12-29 10:47:12 +00:00
|
|
|
}));
|
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', () => {
|
2023-02-23 08:25:23 +00:00
|
|
|
const date = Date.vnNew();
|
2023-02-23 08:45:15 +00:00
|
|
|
Object.assign(controller, {
|
|
|
|
invoiceDate: date,
|
|
|
|
maxShipped: date,
|
|
|
|
minInvoicingDate: date,
|
|
|
|
clientsToInvoice: 'one',
|
|
|
|
clientId: 1101,
|
|
|
|
companyFk: 442,
|
|
|
|
printerFk: 1
|
|
|
|
});
|
|
|
|
$httpBackend.expectPOST(`InvoiceOuts/clientsToInvoice`).respond([{
|
2023-02-23 08:25:23 +00:00
|
|
|
clientId: 1101,
|
|
|
|
id: 121
|
2023-02-23 08:45:15 +00:00
|
|
|
}]);
|
|
|
|
$httpBackend.expectPOST(`InvoiceOuts/invoiceClient`).respond();
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|