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'},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const fileCabinetName = 'deliveryClientTest';
|
|
|
|
const dialogDisplayName = 'find';
|
|
|
|
const dialogName = 'findTest';
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|