2021-03-03 06:44:09 +00:00
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('vnInvoiceInDescriptor', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
|
|
|
|
beforeEach(ngModule('invoiceIn'));
|
|
|
|
|
|
|
|
beforeEach(inject(($componentController, _$httpBackend_) => {
|
|
|
|
$httpBackend = _$httpBackend_;
|
2021-12-14 07:33:29 +00:00
|
|
|
const $element = angular.element('<vn-invoice-in-descriptor></vn-invoice-in-descriptor>');
|
|
|
|
|
|
|
|
controller = $componentController('vnInvoiceInDescriptor', {$element});
|
2021-10-05 09:19:48 +00:00
|
|
|
controller.invoiceIn = {id: 1};
|
|
|
|
$httpBackend.when('GET', `InvoiceIns/${controller.invoiceIn.id}`).respond({id: 1});
|
2021-03-03 06:44:09 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('loadData()', () => {
|
|
|
|
it(`should perform a get query to store the invoice in data into the controller`, () => {
|
2021-10-05 09:19:48 +00:00
|
|
|
expect(controller.invoiceIn).toEqual({id: 1});
|
2021-03-03 06:44:09 +00:00
|
|
|
});
|
|
|
|
});
|
2021-09-24 06:24:34 +00:00
|
|
|
|
2021-10-05 09:19:48 +00:00
|
|
|
describe('onAcceptToBook()', () => {
|
|
|
|
it(`should perform a post query to book the invoice`, () => {
|
2021-12-14 07:33:29 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
controller.$state.reload = jest.fn();
|
|
|
|
|
2021-09-24 06:24:34 +00:00
|
|
|
const id = 1;
|
|
|
|
|
2021-10-05 09:19:48 +00:00
|
|
|
$httpBackend.expectPOST(`InvoiceIns/${id}/toBook`).respond();
|
|
|
|
controller.onAcceptToBook();
|
2021-09-24 06:24:34 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
2021-10-05 09:19:48 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('InvoiceIn booked');
|
2021-09-24 06:24:34 +00:00
|
|
|
});
|
|
|
|
});
|
2022-01-19 13:21:19 +00:00
|
|
|
|
2022-01-20 09:05:24 +00:00
|
|
|
describe('checkToBook()', () => {
|
2022-01-24 14:35:32 +00:00
|
|
|
it(`should show a warning before book`, () => {
|
2022-01-19 13:21:19 +00:00
|
|
|
controller.$.confirmToBookAnyway = {show: () => {}};
|
|
|
|
jest.spyOn(controller.$.confirmToBookAnyway, 'show');
|
|
|
|
|
|
|
|
const invoceInId = 1;
|
|
|
|
const data = {
|
|
|
|
totalDueDay: 'an amount',
|
|
|
|
totalTaxableBase: 'distinct amount'
|
|
|
|
};
|
|
|
|
|
|
|
|
$httpBackend.expectGET(`InvoiceIns/${invoceInId}/getTotals`).respond(data);
|
|
|
|
$httpBackend.expectGET(`InvoiceInDueDays/count`).respond();
|
|
|
|
|
2022-01-20 09:05:24 +00:00
|
|
|
controller.checkToBook();
|
2022-01-19 13:21:19 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.$.confirmToBookAnyway.show).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should call onAcceptToBook`, () => {
|
|
|
|
controller.onAcceptToBook = jest.fn();
|
|
|
|
|
|
|
|
const invoceInId = 1;
|
|
|
|
const data = {
|
|
|
|
totalDueDay: 'same amount',
|
|
|
|
totalTaxableBase: 'same amount'
|
|
|
|
};
|
|
|
|
|
|
|
|
$httpBackend.expectGET(`InvoiceIns/${invoceInId}/getTotals`).respond(data);
|
|
|
|
$httpBackend.expectGET(`InvoiceInDueDays/count`).respond();
|
|
|
|
|
2022-01-20 09:05:24 +00:00
|
|
|
controller.checkToBook();
|
2022-01-19 13:21:19 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.onAcceptToBook).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
2021-03-03 06:44:09 +00:00
|
|
|
});
|