salix/modules/invoiceOut/front/descriptor-menu/index.spec.js

135 lines
5.0 KiB
JavaScript
Raw Normal View History

2021-11-09 14:10:43 +00:00
import './index';
describe('vnInvoiceOutDescriptorMenu', () => {
2021-11-09 14:10:43 +00:00
let controller;
let $httpBackend;
let $httpParamSerializer;
const invoiceOut = {
id: 1,
2022-07-21 08:11:31 +00:00
client: {id: 1101},
ref: 'T1111111'
2021-11-09 14:10:43 +00:00
};
beforeEach(ngModule('invoiceOut'));
beforeEach(inject(($componentController, _$httpParamSerializer_, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_;
controller = $componentController('vnInvoiceOutDescriptorMenu', {$element: null});
controller.invoiceOut = {
id: 1,
ref: 'T1111111',
client: {id: 1101}
};
2021-11-09 14:10:43 +00:00
}));
describe('createPdfInvoice()', () => {
it('should make a query to the createPdf() endpoint and show a success snackbar', () => {
jest.spyOn(controller.vnApp, 'showSuccess');
$httpBackend.whenGET(`InvoiceOuts/${invoiceOut.id}`).respond();
$httpBackend.expectPOST(`InvoiceOuts/${invoiceOut.id}/createPdf`).respond();
controller.createPdfInvoice();
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
describe('showCsvInvoice()', () => {
it('should make a query to the csv invoice download endpoint and show a message snackbar', () => {
jest.spyOn(window, 'open').mockReturnThis();
const expectedParams = {
2022-07-21 08:11:31 +00:00
recipientId: invoiceOut.client.id,
refFk: invoiceOut.ref
2021-11-09 14:10:43 +00:00
};
const serializedParams = $httpParamSerializer(expectedParams);
const expectedPath = `api/csv/invoice/download?${serializedParams}`;
controller.showCsvInvoice();
expect(window.open).toHaveBeenCalledWith(expectedPath);
});
});
describe('deleteInvoiceOut()', () => {
it(`should make a query and call showSuccess()`, () => {
controller.$state.reload = jest.fn();
jest.spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expectPOST(`InvoiceOuts/${invoiceOut.id}/delete`).respond();
controller.deleteInvoiceOut();
$httpBackend.flush();
expect(controller.$state.reload).toHaveBeenCalled();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
it(`should make a query and call showSuccess() after state.go if the state wasn't in invoiceOut module`, () => {
jest.spyOn(controller.$state, 'go').mockReturnValue('ok');
jest.spyOn(controller.vnApp, 'showSuccess');
controller.$state.current.name = 'invoiceOut.card.something';
$httpBackend.expectPOST(`InvoiceOuts/${invoiceOut.id}/delete`).respond();
controller.deleteInvoiceOut();
$httpBackend.flush();
expect(controller.$state.go).toHaveBeenCalledWith('invoiceOut.index');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
2021-11-09 14:10:43 +00:00
describe('sendPdfInvoice()', () => {
it('should make a query to the email invoice endpoint and show a message snackbar', () => {
jest.spyOn(controller.vnApp, 'showMessage');
const $data = {email: 'brucebanner@gothamcity.com'};
const expectedParams = {
recipient: $data.email,
2022-07-21 08:11:31 +00:00
recipientId: invoiceOut.client.id,
refFk: invoiceOut.ref
2021-11-09 14:10:43 +00:00
};
const serializedParams = $httpParamSerializer(expectedParams);
$httpBackend.expectGET(`email/invoice?${serializedParams}`).respond();
controller.sendPdfInvoice($data);
$httpBackend.flush();
expect(controller.vnApp.showMessage).toHaveBeenCalled();
});
});
describe('sendCsvInvoice()', () => {
it('should make a query to the csv invoice send endpoint and show a message snackbar', () => {
jest.spyOn(controller.vnApp, 'showMessage');
const $data = {email: 'brucebanner@gothamcity.com'};
const expectedParams = {
recipient: $data.email,
2022-07-21 08:11:31 +00:00
recipientId: invoiceOut.client.id,
refFk: invoiceOut.ref
2021-11-09 14:10:43 +00:00
};
const serializedParams = $httpParamSerializer(expectedParams);
$httpBackend.expectGET(`csv/invoice/send?${serializedParams}`).respond();
controller.sendCsvInvoice($data);
$httpBackend.flush();
expect(controller.vnApp.showMessage).toHaveBeenCalled();
});
});
2022-04-26 11:08:06 +00:00
describe('refundInvoiceOut()', () => {
it('should make a query and show a success message', () => {
jest.spyOn(controller.vnApp, 'showSuccess');
const params = {ref: controller.invoiceOut.ref};
2022-04-26 11:08:06 +00:00
$httpBackend.expectPOST(`InvoiceOuts/refund`, params).respond([{id: 1}, {id: 2}]);
2022-04-26 11:08:06 +00:00
controller.refundInvoiceOut();
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
2022-04-26 11:08:06 +00:00
});
});
2021-11-09 14:10:43 +00:00
});