Updated unit tests
This commit is contained in:
parent
0ec6d273e6
commit
565162740a
|
@ -1,7 +1,7 @@
|
||||||
import selectors from '../../helpers/selectors';
|
import selectors from '../../helpers/selectors';
|
||||||
import getBrowser from '../../helpers/puppeteer';
|
import getBrowser from '../../helpers/puppeteer';
|
||||||
|
|
||||||
fdescribe('Client Edit billing data path', () => {
|
describe('Client Edit billing data path', () => {
|
||||||
let browser;
|
let browser;
|
||||||
let page;
|
let page;
|
||||||
beforeAll(async() => {
|
beforeAll(async() => {
|
||||||
|
|
|
@ -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);
|
||||||
|
});
|
||||||
|
});
|
|
@ -3,6 +3,7 @@ import './index';
|
||||||
describe('vnInvoiceOutDescriptor', () => {
|
describe('vnInvoiceOutDescriptor', () => {
|
||||||
let controller;
|
let controller;
|
||||||
let $httpBackend;
|
let $httpBackend;
|
||||||
|
const invoiceOut = {id: 1};
|
||||||
|
|
||||||
beforeEach(ngModule('invoiceOut'));
|
beforeEach(ngModule('invoiceOut'));
|
||||||
|
|
||||||
|
@ -11,6 +12,20 @@ describe('vnInvoiceOutDescriptor', () => {
|
||||||
controller = $componentController('vnInvoiceOutDescriptor', {$element: null});
|
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()', () => {
|
describe('loadData()', () => {
|
||||||
it(`should perform a get query to store the invoice in data into the controller`, () => {
|
it(`should perform a get query to store the invoice in data into the controller`, () => {
|
||||||
const id = 1;
|
const id = 1;
|
||||||
|
|
|
@ -5,6 +5,7 @@ describe('ticket makeInvoice()', () => {
|
||||||
const userId = 19;
|
const userId = 19;
|
||||||
const activeCtx = {
|
const activeCtx = {
|
||||||
accessToken: {userId: userId},
|
accessToken: {userId: userId},
|
||||||
|
headers: {origin: 'http://localhost:5000'},
|
||||||
};
|
};
|
||||||
const ctx = {req: activeCtx};
|
const ctx = {req: activeCtx};
|
||||||
|
|
||||||
|
@ -43,6 +44,9 @@ describe('ticket makeInvoice()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should invoice a ticket, then try again to fail', async() => {
|
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);
|
invoice = await app.models.Ticket.makeInvoice(ctx, ticketId);
|
||||||
|
|
||||||
expect(invoice.invoiceFk).toBeDefined();
|
expect(invoice.invoiceFk).toBeDefined();
|
||||||
|
|
|
@ -148,12 +148,12 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('regenerateInvoice()', () => {
|
describe('createInvoicePdf()', () => {
|
||||||
it('should make a query and show a success snackbar', () => {
|
it('should make a query and show a success snackbar', () => {
|
||||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||||
|
|
||||||
$httpBackend.expectPOST(`InvoiceOuts/${ticket.invoiceOut.id}/regenerate`).respond();
|
$httpBackend.expectPOST(`InvoiceOuts/${ticket.invoiceOut.id}/createPdf`).respond();
|
||||||
controller.regenerateInvoice();
|
controller.createInvoicePdf();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
||||||
|
|
Loading…
Reference in New Issue