#5926 - Worker/PDA docuware #2482

Open
jsegarra wants to merge 40 commits from 5926_pda_worker_docuware into dev
2 changed files with 35 additions and 29 deletions
Showing only changes of commit 23553a3694 - Show all commits

View File

@ -114,6 +114,9 @@ module.exports = Self => {
* @return {number} - The fileCabinet id * @return {number} - The fileCabinet id
*/ */
Self.getDialog = async(code, action, fileCabinetId) => { Self.getDialog = async(code, action, fileCabinetId) => {
if (!env && !Self.hasDeviceReady())
return Math.floor(Math.random() + 100);
const docuwareInfo = await Self.getDocuware({ const docuwareInfo = await Self.getDocuware({
where: { where: {
code, code,
@ -138,8 +141,8 @@ module.exports = Self => {
* @return {number} - The fileCabinet id * @return {number} - The fileCabinet id
*/ */
Self.getFileCabinet = async code => { Self.getFileCabinet = async code => {
// if (!process.env.NODE_ENV) if (!env && !Self.hasDeviceReady())
// return Math.floor(Math.random() + 100); return Math.floor(Math.random() + 100);
const options = await Self.getOptions(); const options = await Self.getOptions();
const docuwareInfo = await Self.app.models.Docuware.findOne({ const docuwareInfo = await Self.app.models.Docuware.findOne({
@ -164,6 +167,8 @@ module.exports = Self => {
* @return {object} - The data * @return {object} - The data
*/ */
Self.get = async(code, filter, parse) => { Self.get = async(code, filter, parse) => {
if (!env && !Self.hasDeviceReady()) return;
const options = await Self.getOptions(); const options = await Self.getOptions();
const fileCabinetId = await Self.getFileCabinet(code); const fileCabinetId = await Self.getFileCabinet(code);
const dialogId = await Self.getDialog(code, 'find', fileCabinetId); const dialogId = await Self.getDialog(code, 'find', fileCabinetId);
@ -185,7 +190,7 @@ module.exports = Self => {
* @return {object} - The data * @return {object} - The data
*/ */
Self.getById = async(code, id, parse) => { Self.getById = async(code, id, parse) => {
if (!process.env.NODE_ENV) return; if (!env && !Self.hasDeviceReady()) return;
const docuwareInfo = await Self.app.models.Docuware.findOne({ const docuwareInfo = await Self.app.models.Docuware.findOne({
fields: ['findById'], fields: ['findById'],

View File

@ -1,9 +1,10 @@
const axios = require('axios'); const axios = require('axios');
const models = require('vn-loopback/server/server').models; const {Docuware} = require('vn-loopback/server/server').models;
fdescribe('Docuware core', () => { fdescribe('Docuware core', () => {
beforeAll(() => { beforeAll(() => {
process.env.NODE_ENV = 'testing'; process.env.NODE_ENV = 'testing';
spyOn(Docuware, 'hasDeviceReady').and.returnValue(true);
}); });
afterAll(() => { afterAll(() => {
@ -12,19 +13,19 @@ fdescribe('Docuware core', () => {
describe('hasDeviceReady()', () => { describe('hasDeviceReady()', () => {
it('should return true', async() => { it('should return true', async() => {
const result = await models.Docuware.hasDeviceReady({device: 'Tablet 1'}); const result = await Docuware.hasDeviceReady({device: 'Tablet 1'});
expect(result).toBeTrue(); expect(result).toBeTrue();
}); });
it('should return false', async() => { it('should return false', async() => {
const result = await models.Docuware.hasDeviceReady({device: null}); const result = await Docuware.hasDeviceReady({device: null});
expect(result).toBeFalse(); expect(result).toBeFalse();
}); });
it('should not exists return false ', async() => { it('should not exists return false ', async() => {
const result = await models.Docuware.hasDeviceReady(); const result = await Docuware.hasDeviceReady();
expect(result).toBeFalse(); expect(result).toBeFalse();
}); });
@ -32,14 +33,14 @@ fdescribe('Docuware core', () => {
describe('getOptions()', () => { describe('getOptions()', () => {
it('should return url and headers', async() => { it('should return url and headers', async() => {
const result = await models.Docuware.getOptions(); const result = await Docuware.getOptions();
expect(result.url).toBeDefined(); expect(result.url).toBeDefined();
expect(result.headers).toBeDefined(); expect(result.headers).toBeDefined();
}); });
}); });
describe('getDialog()', () => { fdescribe('getDialog()', () => {
it('should return dialogId', async() => { it('should return dialogId', async() => {
const dialogs = { const dialogs = {
data: { data: {
@ -52,7 +53,7 @@ fdescribe('Docuware core', () => {
} }
}; };
spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs))); spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs)));
const result = await models.Docuware.getDialog('deliveryNote', 'find', 'randomFileCabinetId'); const result = await Docuware.getDialog('deliveryNote', 'find', 'randomFileCabinetId');
expect(result).toEqual('getDialogTest'); expect(result).toEqual('getDialogTest');
}); });
@ -78,7 +79,7 @@ fdescribe('Docuware core', () => {
value: 'Tablet123' value: 'Tablet123'
} }
}; };
const result = await models.Docuware.buildTemplateJSON(config); const result = await Docuware.buildTemplateJSON(config);
expect(result).toEqual({ expect(result).toEqual({
'Fields': [ 'Fields': [
@ -109,7 +110,7 @@ fdescribe('Docuware core', () => {
describe('uploadOptions()', () => { describe('uploadOptions()', () => {
it('should return uploadOptions', async() => { it('should return uploadOptions', async() => {
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random())))); spyOn(Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
// const dialogs = { // const dialogs = {
jsegarra marked this conversation as resolved
Review

Quitar?

Quitar?
// data: { // data: {
@ -122,7 +123,7 @@ fdescribe('Docuware core', () => {
// } // }
// }; // };
// spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs))); // spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs)));
const {uploadOptions: result} = await models.Docuware.uploadOptions(1, { const {uploadOptions: result} = await Docuware.uploadOptions(1, {
'N__DOCUMENTO': { 'N__DOCUMENTO': {
type: 'string', type: 'string',
value: '12345' value: '12345'
@ -136,7 +137,7 @@ fdescribe('Docuware core', () => {
describe('deleteOld()', () => { describe('deleteOld()', () => {
it('should return deleteOld', async() => { it('should return deleteOld', async() => {
await models.Docuware.deleteOld(1, 'deliveryNote', { await Docuware.deleteOld(1, 'deliveryNote', {
'N__DOCUMENTO': { 'N__DOCUMENTO': {
type: 'string', type: 'string',
value: '12345' value: '12345'
@ -144,10 +145,10 @@ fdescribe('Docuware core', () => {
}); });
}); });
describe('getFileCabinet()', () => { fdescribe('getFileCabinet()', () => {
it('should return fileCabinetId', async() => { it('should return fileCabinetId', async() => {
const code = 'deliveryNote'; const code = 'deliveryNote';
const docuwareInfo = await models.Docuware.findOne({ const docuwareInfo = await Docuware.findOne({
where: { where: {
code code
} }
@ -163,30 +164,30 @@ fdescribe('Docuware core', () => {
} }
}; };
spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs))); spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs)));
const result = await models.Docuware.getFileCabinet(code); const result = await Docuware.getFileCabinet(code);
expect(result).toEqual('getFileCabinetTest'); expect(result).toEqual('getFileCabinetTest');
}); });
}); });
describe('get()', () => { fdescribe('get()', () => {
it('should return data without parse', async() => { it('should return data without parse', async() => {
spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random())))); spyOn(Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random())))); spyOn(Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
const data = { const data = {
data: { data: {
id: 1 id: 1
} }
}; };
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data))); spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data)));
const result = await models.Docuware.get('deliveryNote'); const result = await Docuware.get('deliveryNote');
expect(result.id).toEqual(1); expect(result.id).toEqual(1);
}); });
it('should return data with parse', async() => { fit('should return data with parse', async() => {
spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random())))); spyOn(Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random())))); spyOn(Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
const data = { const data = {
data: { data: {
Items: [{ Items: [{
@ -215,7 +216,7 @@ fdescribe('Docuware core', () => {
'secondRequiredField': 'name', 'secondRequiredField': 'name',
}; };
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data))); spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data)));
const [result] = await models.Docuware.get('deliveryNote', null, parse); const [result] = await Docuware.get('deliveryNote', null, parse);
expect(result.id).toEqual(1); expect(result.id).toEqual(1);
expect(result.name).toEqual('myName'); expect(result.name).toEqual('myName');
@ -223,17 +224,17 @@ fdescribe('Docuware core', () => {
}); });
}); });
describe('getById()', () => { fdescribe('getById()', () => {
it('should return data', async() => { it('should return data', async() => {
spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random())))); spyOn(Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random())))); spyOn(Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
const data = { const data = {
data: { data: {
id: 1 id: 1
} }
}; };
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data))); spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data)));
const result = await models.Docuware.getById('deliveryNote', 1); const result = await Docuware.getById('deliveryNote', 1);
expect(result.id).toEqual(1); expect(result.id).toEqual(1);
}); });