2021-08-02 11:35:38 +00:00
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('InvoiceOut', () => {
|
2021-08-10 11:57:03 +00:00
|
|
|
describe('Component vnInvoiceOutGlobalInvoicing', () => {
|
2021-08-02 11:35:38 +00:00
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
2021-08-10 11:57:03 +00:00
|
|
|
let $httpParamSerializer;
|
2021-08-02 11:35:38 +00:00
|
|
|
|
|
|
|
beforeEach(ngModule('invoiceOut'));
|
|
|
|
|
2021-08-10 11:57:03 +00:00
|
|
|
beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
|
2021-08-02 11:35:38 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
2021-08-10 11:57:03 +00:00
|
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
2021-08-02 11:35:38 +00:00
|
|
|
let $scope = $rootScope.$new();
|
2021-08-10 11:57:03 +00:00
|
|
|
const $element = angular.element('<vn-invoice-out-global-invoicing></vn-invoice-out-global-invoicing>');
|
2021-08-02 11:35:38 +00:00
|
|
|
const $transclude = {
|
|
|
|
$$boundTransclude: {
|
|
|
|
$$slots: []
|
|
|
|
}
|
|
|
|
};
|
2021-08-10 11:57:03 +00:00
|
|
|
controller = $componentController('vnInvoiceOutGlobalInvoicing', {$element, $scope, $transclude});
|
2021-08-02 11:35:38 +00:00
|
|
|
}));
|
|
|
|
|
2021-08-10 11:57:03 +00:00
|
|
|
describe('getMinClientId()', () => {
|
|
|
|
it('should set the invoice fromClientId property', () => {
|
|
|
|
const filter = {
|
|
|
|
order: 'id ASC',
|
|
|
|
limit: 1
|
|
|
|
};
|
|
|
|
|
|
|
|
const serializedParams = $httpParamSerializer({filter});
|
|
|
|
$httpBackend.expectGET(`Clients/findOne?${serializedParams}`).respond(200, {id: 1101});
|
|
|
|
|
|
|
|
controller.getMinClientId();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.invoice.fromClientId).toEqual(1101);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getMaxClientId()', () => {
|
|
|
|
it('should set the invoice toClientId property', () => {
|
|
|
|
const filter = {
|
|
|
|
order: 'id DESC',
|
|
|
|
limit: 1
|
|
|
|
};
|
|
|
|
|
|
|
|
const serializedParams = $httpParamSerializer({filter});
|
|
|
|
$httpBackend.expectGET(`Clients/findOne?${serializedParams}`).respond(200, {id: 1112});
|
|
|
|
|
|
|
|
controller.getMaxClientId();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.invoice.toClientId).toEqual(1112);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-08-02 11:35:38 +00:00
|
|
|
describe('responseHandler()', () => {
|
2021-08-10 11:57:03 +00:00
|
|
|
it('should throw an error when invoiceDate or maxShipped properties are not filled in', () => {
|
2021-08-02 11:35:38 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showError');
|
|
|
|
|
|
|
|
controller.invoice = {
|
2021-08-10 11:57:03 +00:00
|
|
|
fromClientId: 1101,
|
|
|
|
toClientId: 1101
|
2021-08-02 11:35:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
controller.responseHandler('accept');
|
|
|
|
|
2021-08-10 11:57:03 +00:00
|
|
|
expect(controller.vnApp.showError).toHaveBeenCalledWith(`Invoice date and the max date should be filled`);
|
2021-08-02 11:35:38 +00:00
|
|
|
});
|
|
|
|
|
2021-08-10 11:57:03 +00:00
|
|
|
it('should throw an error when fromClientId or toClientId properties are not filled in', () => {
|
2021-08-02 11:35:38 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showError');
|
|
|
|
|
|
|
|
controller.invoice = {
|
2021-08-10 11:57:03 +00:00
|
|
|
invoiceDate: new Date(),
|
|
|
|
maxShipped: new Date()
|
2021-08-02 11:35:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
controller.responseHandler('accept');
|
|
|
|
|
2021-08-10 11:57:03 +00:00
|
|
|
expect(controller.vnApp.showError).toHaveBeenCalledWith(`Choose a valid clients range`);
|
2021-08-02 11:35:38 +00:00
|
|
|
});
|
|
|
|
|
2021-08-10 11:57:03 +00:00
|
|
|
it('should make an http POST query and then call to the showSuccess() method', () => {
|
2021-08-02 11:35:38 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
|
|
|
|
controller.invoice = {
|
2021-08-10 11:57:03 +00:00
|
|
|
invoiceDate: new Date(),
|
|
|
|
maxShipped: new Date(),
|
|
|
|
fromClientId: 1101,
|
|
|
|
toClientId: 1101
|
2021-08-02 11:35:38 +00:00
|
|
|
};
|
|
|
|
|
2021-08-10 11:57:03 +00:00
|
|
|
$httpBackend.expect('POST', `InvoiceOuts/globalInvoicing`).respond({id: 1});
|
2021-08-02 11:35:38 +00:00
|
|
|
controller.responseHandler('accept');
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|