110 lines
3.8 KiB
JavaScript
110 lines
3.8 KiB
JavaScript
|
import './index';
|
||
|
|
||
|
describe('vnInvoiceOutDescriptor', () => {
|
||
|
let controller;
|
||
|
let $httpBackend;
|
||
|
let $httpParamSerializer;
|
||
|
const invoiceOut = {
|
||
|
id: 1,
|
||
|
client: {id: 1101}
|
||
|
};
|
||
|
|
||
|
beforeEach(ngModule('invoiceOut'));
|
||
|
|
||
|
beforeEach(inject(($componentController, _$httpParamSerializer_, _$httpBackend_) => {
|
||
|
$httpBackend = _$httpBackend_;
|
||
|
$httpParamSerializer = _$httpParamSerializer_;
|
||
|
controller = $componentController('vnInvoiceOutDescriptor', {$element: null});
|
||
|
}));
|
||
|
|
||
|
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', () => {
|
||
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
||
|
|
||
|
controller.invoiceOut = invoiceOut;
|
||
|
|
||
|
$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();
|
||
|
|
||
|
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);
|
||
|
$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');
|
||
|
|
||
|
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();
|
||
|
});
|
||
|
});
|
||
|
});
|