From b134aeb0ea40c4d964f995e8fd35efef3aa58076 Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 5 Oct 2022 16:19:07 +0200 Subject: [PATCH] Mock report pdf --- .../back/methods/invoiceOut/createPdf.js | 6 ++--- .../invoiceOut/specs/createPdf.spec.js | 22 ++++++------------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/createPdf.js b/modules/invoiceOut/back/methods/invoiceOut/createPdf.js index 3ab5f526c..e56516237 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/createPdf.js +++ b/modules/invoiceOut/back/methods/invoiceOut/createPdf.js @@ -1,5 +1,5 @@ const UserError = require('vn-loopback/util/user-error'); -const {Report, storage} = require('vn-print'); +const print = require('vn-print'); module.exports = Self => { Self.remoteMethodCtx('createPdf', { @@ -52,7 +52,7 @@ module.exports = Self => { hasPdf: true }, myOptions); - const invoiceReport = new Report('invoice', { + const invoiceReport = new print.Report('invoice', { reference: invoiceOut.ref, recipientId: invoiceOut.clientFk }); @@ -66,7 +66,7 @@ module.exports = Self => { const fileName = `${year}${invoiceOut.ref}.pdf`; // Store invoice - storage.write(stream, { + print.storage.write(stream, { type: 'invoice', path: `${year}/${month}/${day}`, fileName: fileName diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/createPdf.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/createPdf.spec.js index 7600f065f..803338ef3 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/createPdf.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/createPdf.spec.js @@ -1,7 +1,6 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); -const fs = require('fs-extra'); -const axios = require('axios'); +const print = require('vn-print'); describe('InvoiceOut createPdf()', () => { const userId = 1; @@ -16,22 +15,15 @@ describe('InvoiceOut createPdf()', () => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ active: activeCtx }); - const response = { - data: { - pipe: () => {}, - on: () => {}, + + spyOn(print, 'Report').and.returnValue({ + toPdfStream: () => { + return ''; } - }; - spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(response))); - spyOn(models.InvoiceContainer, 'container').and.returnValue({ - client: {root: '/path'} - }); - spyOn(fs, 'mkdir').and.returnValue(true); - spyOn(fs, 'createWriteStream').and.returnValue({ - on: (event, cb) => cb(), - end: () => {} }); + spyOn(print.storage, 'write').and.returnValue(true); + const tx = await models.InvoiceOut.beginTransaction({}); const options = {transaction: tx};