From 565162740ab66aaf98d857680e01bdca9d733ed8 Mon Sep 17 00:00:00 2001 From: joan Date: Mon, 15 Mar 2021 16:35:55 +0100 Subject: [PATCH] Updated unit tests --- .../02-client/04_edit_billing_data.spec.js | 2 +- .../invoiceOut/specs/createPdf.spec.js | 26 +++++++++++++++++++ .../invoiceOut/front/descriptor/index.spec.js | 15 +++++++++++ .../methods/ticket/specs/makeInvoice.spec.js | 4 +++ .../front/descriptor-menu/index.spec.js | 6 ++--- 5 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 modules/invoiceOut/back/methods/invoiceOut/specs/createPdf.spec.js diff --git a/e2e/paths/02-client/04_edit_billing_data.spec.js b/e2e/paths/02-client/04_edit_billing_data.spec.js index da5e6232e..24ee3c29a 100644 --- a/e2e/paths/02-client/04_edit_billing_data.spec.js +++ b/e2e/paths/02-client/04_edit_billing_data.spec.js @@ -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() => { diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/createPdf.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/createPdf.spec.js new file mode 100644 index 000000000..3372411c1 --- /dev/null +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/createPdf.spec.js @@ -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); + }); +}); diff --git a/modules/invoiceOut/front/descriptor/index.spec.js b/modules/invoiceOut/front/descriptor/index.spec.js index 987763b0a..c16900a0a 100644 --- a/modules/invoiceOut/front/descriptor/index.spec.js +++ b/modules/invoiceOut/front/descriptor/index.spec.js @@ -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; diff --git a/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js b/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js index 79bd59848..e20d9d8a2 100644 --- a/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js +++ b/modules/ticket/back/methods/ticket/specs/makeInvoice.spec.js @@ -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(); diff --git a/modules/ticket/front/descriptor-menu/index.spec.js b/modules/ticket/front/descriptor-menu/index.spec.js index 3cd08fc38..6a3009daf 100644 --- a/modules/ticket/front/descriptor-menu/index.spec.js +++ b/modules/ticket/front/descriptor-menu/index.spec.js @@ -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();