2022-02-16 13:57:47 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
2023-01-12 14:16:38 +00:00
|
|
|
const axios = require('axios');
|
2022-02-21 07:48:53 +00:00
|
|
|
const stream = require('stream');
|
2022-02-16 13:57:47 +00:00
|
|
|
|
2023-01-13 12:33:59 +00:00
|
|
|
describe('docuware download()', () => {
|
2022-02-16 13:57:47 +00:00
|
|
|
const userId = 9;
|
2022-02-21 07:48:53 +00:00
|
|
|
const ticketId = 1;
|
2022-02-16 13:57:47 +00:00
|
|
|
const ctx = {
|
|
|
|
req: {
|
|
|
|
|
|
|
|
accessToken: {userId: userId},
|
|
|
|
headers: {origin: 'http://localhost:5000'},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-01-12 14:16:38 +00:00
|
|
|
const docuwareModel = models.Docuware;
|
|
|
|
const fileCabinetName = 'deliveryNote';
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
spyOn(docuwareModel, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
|
|
|
spyOn(docuwareModel, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return error if file not exist', async() => {
|
|
|
|
spyOn(docuwareModel, 'checkFile').and.returnValue(false);
|
|
|
|
spyOn(axios, 'get').and.returnValue(new stream.PassThrough({objectMode: true}));
|
|
|
|
|
|
|
|
let error;
|
|
|
|
try {
|
|
|
|
await models.Docuware.download(ctx, ticketId, fileCabinetName);
|
|
|
|
} catch (e) {
|
|
|
|
error = e.message;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(error).toEqual('The DOCUWARE PDF document does not exists');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return the downloaded file if exist file ', async() => {
|
|
|
|
spyOn(docuwareModel, 'checkFile').and.returnValue({});
|
|
|
|
spyOn(axios, 'get').and.returnValue(new stream.PassThrough({objectMode: true}));
|
|
|
|
|
|
|
|
const result = await models.Docuware.download(ctx, ticketId, fileCabinetName);
|
2022-02-16 13:57:47 +00:00
|
|
|
|
|
|
|
expect(result[1]).toEqual('application/pdf');
|
2022-02-21 07:48:53 +00:00
|
|
|
expect(result[2]).toEqual(`filename="${ticketId}.pdf"`);
|
2022-02-16 13:57:47 +00:00
|
|
|
});
|
|
|
|
});
|