2022-02-21 07:48:53 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
|
|
|
const got = require('got');
|
|
|
|
|
|
|
|
describe('docuware download()', () => {
|
|
|
|
const ticketId = 1;
|
|
|
|
const userId = 9;
|
|
|
|
const ctx = {
|
|
|
|
req: {
|
|
|
|
|
|
|
|
accessToken: {userId: userId},
|
|
|
|
headers: {origin: 'http://localhost:5000'},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-05-06 07:08:34 +00:00
|
|
|
const fileCabinetName = 'deliveryClient';
|
2022-02-21 07:48:53 +00:00
|
|
|
const dialogDisplayName = 'find';
|
2022-05-06 07:08:34 +00:00
|
|
|
const dialogName = 'findTicket';
|
2022-02-21 07:48:53 +00:00
|
|
|
|
|
|
|
const gotGetResponse = {
|
|
|
|
body: JSON.stringify(
|
|
|
|
{
|
|
|
|
FileCabinet: [
|
|
|
|
{Id: 12, Name: fileCabinetName}
|
|
|
|
],
|
|
|
|
Dialog: [
|
|
|
|
{Id: 34, DisplayName: dialogDisplayName}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
it('should return exist file in docuware', async() => {
|
|
|
|
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)));
|
|
|
|
|
|
|
|
const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, dialogName);
|
|
|
|
|
|
|
|
expect(result).toEqual(true);
|
2022-02-16 13:57:47 +00:00
|
|
|
});
|
|
|
|
|
2022-02-21 07:48:53 +00:00
|
|
|
it('should return not exist file in docuware', async() => {
|
|
|
|
const gotPostResponse = {
|
|
|
|
body: JSON.stringify(
|
|
|
|
{
|
|
|
|
Items: [],
|
|
|
|
})
|
|
|
|
};
|
2022-02-16 13:57:47 +00:00
|
|
|
|
2022-02-21 07:48:53 +00:00
|
|
|
spyOn(got, 'get').and.returnValue(new Promise(resolve => resolve(gotGetResponse)));
|
|
|
|
spyOn(got, 'post').and.returnValue(new Promise(resolve => resolve(gotPostResponse)));
|
2022-02-16 13:57:47 +00:00
|
|
|
|
2022-02-21 07:48:53 +00:00
|
|
|
const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, dialogName);
|
2022-02-16 13:57:47 +00:00
|
|
|
|
2022-02-21 07:48:53 +00:00
|
|
|
expect(result).toEqual(false);
|
2022-02-16 13:57:47 +00:00
|
|
|
});
|
|
|
|
});
|