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

110 lines
3.8 KiB
JavaScript
Raw Normal View History

2021-03-03 06:44:09 +00:00
import './index';
describe('vnInvoiceOutDescriptor', () => {
let controller;
let $httpBackend;
2021-10-07 11:36:23 +00:00
let $httpParamSerializer;
const invoiceOut = {
id: 1,
client: {id: 1101}
};
2021-03-03 06:44:09 +00:00
beforeEach(ngModule('invoiceOut'));
2021-10-07 11:36:23 +00:00
beforeEach(inject(($componentController, _$httpParamSerializer_, _$httpBackend_) => {
2021-03-03 06:44:09 +00:00
$httpBackend = _$httpBackend_;
2021-10-07 11:36:23 +00:00
$httpParamSerializer = _$httpParamSerializer_;
2021-03-03 06:44:09 +00:00
controller = $componentController('vnInvoiceOutDescriptor', {$element: null});
}));
2021-10-07 11:36:23 +00:00
describe('loadData()', () => {
it(`should perform a get query to store the invoice in data into the controller`, () => {
const id = 1;
const response = {id: 1};
$httpBackend.expectGET(`InvoiceOuts/${id}`).respond(response);
controller.id = id;
$httpBackend.flush();
expect(controller.invoiceOut).toEqual(response);
});
});
describe('createPdfInvoice()', () => {
it('should make a query to the createPdf() endpoint and show a success snackbar', () => {
2021-03-15 15:35:55 +00:00
jest.spyOn(controller.vnApp, 'showSuccess');
controller.invoiceOut = invoiceOut;
$httpBackend.whenGET(`InvoiceOuts/${invoiceOut.id}`).respond();
2021-03-15 15:35:55 +00:00
$httpBackend.expectPOST(`InvoiceOuts/${invoiceOut.id}/createPdf`).respond();
2021-10-07 11:36:23 +00:00
controller.createPdfInvoice();
2021-03-15 15:35:55 +00:00
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
2021-10-07 11:36:23 +00:00
describe('showCsvInvoice()', () => {
it('should make a query to the csv invoice download endpoint and show a message snackbar', () => {
jest.spyOn(window, 'open').mockReturnThis();
2021-03-03 06:44:09 +00:00
2021-10-07 11:36:23 +00:00
controller.invoiceOut = invoiceOut;
const expectedParams = {
invoiceId: invoiceOut.id,
recipientId: invoiceOut.client.id
};
const serializedParams = $httpParamSerializer(expectedParams);
const expectedPath = `api/csv/invoice/download?${serializedParams}`;
controller.showCsvInvoice();
expect(window.open).toHaveBeenCalledWith(expectedPath);
});
});
describe('sendPdfInvoice()', () => {
it('should make a query to the email invoice endpoint and show a message snackbar', () => {
jest.spyOn(controller.vnApp, 'showMessage');
controller.invoiceOut = invoiceOut;
const $data = {email: 'brucebanner@gothamcity.com'};
const expectedParams = {
invoiceId: invoiceOut.id,
recipient: $data.email,
recipientId: invoiceOut.client.id
};
const serializedParams = $httpParamSerializer(expectedParams);
$httpBackend.expectGET(`email/invoice?${serializedParams}`).respond();
controller.sendPdfInvoice($data);
2021-03-03 06:44:09 +00:00
$httpBackend.flush();
2021-10-07 11:36:23 +00:00
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');
controller.invoiceOut = invoiceOut;
const $data = {email: 'brucebanner@gothamcity.com'};
const expectedParams = {
invoiceId: invoiceOut.id,
recipient: $data.email,
recipientId: invoiceOut.client.id
};
const serializedParams = $httpParamSerializer(expectedParams);
$httpBackend.expectGET(`csv/invoice/send?${serializedParams}`).respond();
controller.sendCsvInvoice($data);
$httpBackend.flush();
expect(controller.vnApp.showMessage).toHaveBeenCalled();
2021-03-03 06:44:09 +00:00
});
});
});