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

75 lines
2.6 KiB
JavaScript

import './index';
describe('InvoiceOut', () => {
describe('Component vnInvoiceOutGlobalInvoicing', () => {
let controller;
let $httpBackend;
beforeEach(ngModule('invoiceOut'));
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
const $scope = $rootScope.$new();
const $element = angular.element('<vn-invoice-out-global-invoicing></vn-invoice-out-global-invoicing>');
controller = $componentController('vnInvoiceOutGlobalInvoicing', {$element, $scope});
}));
describe('makeInvoice()', () => {
it('should throw an error when invoiceDate or maxShipped properties are not filled in', () => {
jest.spyOn(controller.vnApp, 'showError');
controller.clientsToInvoice = 'all';
let error;
try {
controller.makeInvoice();
} catch (e) {
error = e.message;
}
const expectedError = 'Invoice date and the max date should be filled';
expect(error).toBe(expectedError);
});
it('should throw an error when select one client and clientId is not filled in', () => {
jest.spyOn(controller.vnApp, 'showError');
controller.clientsToInvoice = 'one';
let error;
try {
controller.makeInvoice();
} catch (e) {
error = e.message;
}
const expectedError = 'Choose a valid client';
expect(error).toBe(expectedError);
});
it('should make an http POST query and then call to the showSuccess() method', () => {
const date = Date.vnNew();
Object.assign(controller, {
invoiceDate: date,
maxShipped: date,
minInvoicingDate: date,
clientsToInvoice: 'one',
clientId: 1101,
companyFk: 442,
printerFk: 1
});
$httpBackend.expectPOST(`InvoiceOuts/clientsToInvoice`).respond([{
clientId: 1101,
id: 121
}]);
$httpBackend.expectPOST(`InvoiceOuts/invoiceClient`).respond();
controller.makeInvoice();
$httpBackend.flush();
expect(controller.status).toEqual('done');
});
});
});
});