Updated unit tests

This commit is contained in:
Joan Sanchez 2021-03-15 16:35:55 +01:00
parent 0ec6d273e6
commit 565162740a
5 changed files with 49 additions and 4 deletions

View File

@ -1,7 +1,7 @@
import selectors from '../../helpers/selectors';
import getBrowser from '../../helpers/puppeteer';
fdescribe('Client Edit billing data path', () => {
describe('Client Edit billing data path', () => {
let browser;
let page;
beforeAll(async() => {

View File

@ -0,0 +1,26 @@
const app = require('vn-loopback/server/server');
const got = require('got');
describe('InvoiceOut createPdf()', () => {
const userId = 1;
const ctx = {
req: {
accessToken: {userId: userId},
headers: {origin: 'http://localhost:5000'},
}
};
it('should create a new PDF file and set true the hasPdf property', async() => {
const invoiceId = 1;
const response = {
pipe: () => {},
on: () => {},
};
spyOn(got, 'stream').and.returnValue(response);
let result = await app.models.InvoiceOut.createPdf(ctx, invoiceId);
expect(result.hasPdf).toBe(true);
});
});

View File

@ -3,6 +3,7 @@ import './index';
describe('vnInvoiceOutDescriptor', () => {
let controller;
let $httpBackend;
const invoiceOut = {id: 1};
beforeEach(ngModule('invoiceOut'));
@ -11,6 +12,20 @@ describe('vnInvoiceOutDescriptor', () => {
controller = $componentController('vnInvoiceOutDescriptor', {$element: null});
}));
describe('createInvoicePdf()', () => {
it('should make a query and show a success snackbar', () => {
jest.spyOn(controller.vnApp, 'showSuccess');
controller.invoiceOut = invoiceOut;
$httpBackend.expectPOST(`InvoiceOuts/${invoiceOut.id}/createPdf`).respond();
controller.createInvoicePdf();
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
describe('loadData()', () => {
it(`should perform a get query to store the invoice in data into the controller`, () => {
const id = 1;

View File

@ -5,6 +5,7 @@ describe('ticket makeInvoice()', () => {
const userId = 19;
const activeCtx = {
accessToken: {userId: userId},
headers: {origin: 'http://localhost:5000'},
};
const ctx = {req: activeCtx};
@ -43,6 +44,9 @@ describe('ticket makeInvoice()', () => {
});
it('should invoice a ticket, then try again to fail', async() => {
const invoiceOutModel = app.models.InvoiceOut;
spyOn(invoiceOutModel, 'createPdf');
invoice = await app.models.Ticket.makeInvoice(ctx, ticketId);
expect(invoice.invoiceFk).toBeDefined();

View File

@ -148,12 +148,12 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
});
});
describe('regenerateInvoice()', () => {
describe('createInvoicePdf()', () => {
it('should make a query and show a success snackbar', () => {
jest.spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expectPOST(`InvoiceOuts/${ticket.invoiceOut.id}/regenerate`).respond();
controller.regenerateInvoice();
$httpBackend.expectPOST(`InvoiceOuts/${ticket.invoiceOut.id}/createPdf`).respond();
controller.createInvoicePdf();
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();