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); }); it('should return not exist file in docuware', async() => { const gotPostResponse = { body: JSON.stringify( { Items: [], }) }; 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(false); }); });