salix/back/methods/docuware/specs/download.spec.js

51 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-02-16 13:57:47 +00:00
const models = require('vn-loopback/server/server').models;
const got = require('got');
const stream = require('stream');
2022-02-16 13:57:47 +00:00
describe('docuware download()', () => {
2022-02-16 13:57:47 +00:00
const userId = 9;
const ticketId = 1;
2022-02-16 13:57:47 +00:00
const ctx = {
req: {
accessToken: {userId: userId},
headers: {origin: 'http://localhost:5000'},
}
};
it('should return the downloaded file name', async() => {
const fileCabinetName = 'deliveryClientTest';
const dialogDisplayName = 'find';
const dialogName = 'findTest';
const gotGetResponse = {
body: JSON.stringify(
{
FileCabinet: [
{Id: 12, Name: fileCabinetName}
],
Dialog: [
{Id: 34, DisplayName: dialogDisplayName}
]
})
};
2022-02-16 13:57:47 +00:00
const gotPostResponse = {
body: JSON.stringify(
{
Items: [
{Id: 56}
],
})
};
spyOn(got, 'get').and.returnValue(new Promise(resolve => resolve(gotGetResponse)));
spyOn(got, 'post').and.returnValue(new Promise(resolve => resolve(gotPostResponse)));
spyOn(got, 'stream').and.returnValue(new stream.PassThrough({objectMode: true}));
const result = await models.Docuware.download(ctx, ticketId, fileCabinetName, dialogName);
2022-02-16 13:57:47 +00:00
expect(result[1]).toEqual('application/pdf');
expect(result[2]).toEqual(`filename="${ticketId}.pdf"`);
2022-02-16 13:57:47 +00:00
});
});