Compare commits
1 Commits
dev
...
6587_dms_u
Author | SHA1 | Date |
---|---|---|
Javier Segarra | 35f0997020 |
|
@ -1,17 +1,84 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
const fs = require('fs');
|
||||
const {request, IncomingMessage} = require('http');
|
||||
|
||||
describe('dms uploadFile()', () => {
|
||||
fdescribe('dms uploadFile()', () => {
|
||||
it(`should return an error for a user without enough privileges`, async() => {
|
||||
let clientId = 1101;
|
||||
let ticketDmsTypeId = 14;
|
||||
let ctx = {req: {accessToken: {userId: clientId}}, args: {dmsTypeId: ticketDmsTypeId}};
|
||||
let ctx = {
|
||||
req: {accessToken: {userId: clientId}},
|
||||
args: {dmsTypeId: ticketDmsTypeId},
|
||||
};
|
||||
|
||||
let error;
|
||||
await models.Dms.uploadFile(ctx).catch(e => {
|
||||
error = e;
|
||||
}).finally(() => {
|
||||
expect(error.message).toEqual(`You don't have enough privileges`);
|
||||
await models.Dms.uploadFile(ctx)
|
||||
.catch(e => {
|
||||
error = e;
|
||||
})
|
||||
.finally(() => {
|
||||
expect(error.message).toEqual(
|
||||
`You don't have enough privileges`
|
||||
);
|
||||
});
|
||||
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
fit(`should return an error for a user without enough privileges`, async() => {
|
||||
const filename = '2001A1010001.pdf';
|
||||
const path = `${__dirname}/../../../../storage/pdfs/invoice/2001/1/1/${filename}`;
|
||||
const fileContent = fs.readFileSync(path);
|
||||
const {size} = fs.statSync(path);
|
||||
let clientId = 1101;
|
||||
let ticketDmsTypeId = 14;
|
||||
const headers = {
|
||||
'content-type': 'application/octet-stream', // Especifica el tipo de contenido como octet-stream
|
||||
'content-length': size};
|
||||
const fileStream = fs.createReadStream(path); // Reemplaza 'ruta/al/archivo.txt' con la ruta a tu archivo
|
||||
|
||||
|
||||
const options = {
|
||||
'method': 'POST',
|
||||
'content-type': 'application/octet-stream', // Especifica el tipo de contenido como octet-stream
|
||||
'content-length': size
|
||||
};
|
||||
const req = new IncomingMessage();
|
||||
req.headers = {
|
||||
'content-type': 'multipart/form-data',
|
||||
};
|
||||
|
||||
// Simula la carga de archivos
|
||||
req.pipe(fileStream);
|
||||
const formidable = require('formidable')
|
||||
const form = new formidable.IncomingForm();
|
||||
form.parse(req, (err, fields, files) => {
|
||||
// Asegúrate de manejar el resultado de la carga de archivos según tu lógica de aplicación
|
||||
|
||||
});
|
||||
let ctx = {
|
||||
req: {headers, accessToken: {userId: clientId}},
|
||||
result: fileStream,
|
||||
args: {dmsTypeId: ticketDmsTypeId},
|
||||
};
|
||||
ctx.req = {...ctx.req,
|
||||
...new IncomingMessage({headers: {
|
||||
'method': 'POST',
|
||||
'content-type': 'application/octet-stream', // Especifica el tipo de contenido como octet-stream
|
||||
'content-length': size
|
||||
},
|
||||
req
|
||||
})};
|
||||
let error;
|
||||
await models.Dms.uploadFile(ctx, {'content-length': size})
|
||||
.catch(e => {
|
||||
error = e;
|
||||
})
|
||||
.finally(() => {
|
||||
expect(error.message).toEqual(
|
||||
`You don't have enough privileges`
|
||||
);
|
||||
});
|
||||
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
|
|
@ -66,9 +66,9 @@ module.exports = Self => {
|
|||
|
||||
let srcFile;
|
||||
try {
|
||||
const hasWriteRole = await models.DmsType.hasWriteRole(ctx, args.dmsTypeId, myOptions);
|
||||
if (!hasWriteRole)
|
||||
throw new UserError(`You don't have enough privileges`);
|
||||
// const hasWriteRole = await models.DmsType.hasWriteRole(ctx, args.dmsTypeId, myOptions);
|
||||
// if (!hasWriteRole)
|
||||
// throw new UserError(`You don't have enough privileges`);
|
||||
|
||||
// Upload file to temporary path
|
||||
const tempContainer = await TempContainer.container('dms');
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('docuware upload()', () => {
|
||||
fdescribe('docuware upload()', () => {
|
||||
const userId = 9;
|
||||
const ticketIds = [10];
|
||||
const ctx = {
|
||||
|
|
|
@ -121,18 +121,18 @@ module.exports = Self => {
|
|||
|
||||
if (process.env.NODE_ENV != 'production')
|
||||
throw new UserError('Action not allowed on the test environment');
|
||||
|
||||
const BASE_URL = `${options.url}/FileCabinets/${fileCabinetId}/Documents`;
|
||||
// delete old
|
||||
const docuwareFile = await models.Docuware.checkFile(id, fileCabinet, false);
|
||||
if (docuwareFile) {
|
||||
const deleteJson = {
|
||||
'Field': [{'FieldName': 'ESTADO', 'Item': 'Pendiente eliminar', 'ItemElementName': 'String'}]
|
||||
};
|
||||
const deleteUri = `${docuwareOptions.url}/FileCabinets/${fileCabinetId}/Documents/${docuwareFile.id}/Fields`;
|
||||
await axios.put(deleteUri, deleteJson, docuwareOptions.headers);
|
||||
const deleteUri = `${BASE_URL}/${docuwareFile.id}/Fields`;
|
||||
await axios.put(deleteUri, deleteJson, options.headers);
|
||||
}
|
||||
|
||||
const uploadUri = `${docuwareOptions.url}/FileCabinets/${fileCabinetId}/Documents?StoreDialogId=${dialogId}`;
|
||||
const uploadUri = `${BASE_URL}?StoreDialogId=${dialogId}`;
|
||||
const FormData = require('form-data');
|
||||
const data = new FormData();
|
||||
|
||||
|
|
|
@ -48,7 +48,8 @@ async function test() {
|
|||
jasmine.addReporter(new SpecReporter({
|
||||
spec: {
|
||||
displaySuccessful: isCI,
|
||||
displayPending: isCI
|
||||
displayPending: isCI,
|
||||
displayFailed: isCI
|
||||
},
|
||||
summary: {
|
||||
displayPending: false,
|
||||
|
@ -59,9 +60,9 @@ async function test() {
|
|||
const JunitReporter = require('jasmine-reporters');
|
||||
jasmine.addReporter(new JunitReporter.JUnitXmlReporter());
|
||||
|
||||
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;
|
||||
jasmine.exitOnCompletion = true;
|
||||
}
|
||||
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;
|
||||
|
||||
const backSpecs = [
|
||||
'./back/**/*[sS]pec.js',
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
// For a detailed explanation regarding each configuration property, visit:
|
||||
// https://jestjs.io/docs/en/configuration.html
|
||||
/* eslint max-len: ["error", { "code": 150 }]*/
|
||||
|
||||
/** @type {import('jest').Config} */
|
||||
const cpus = require('os').cpus().length;
|
||||
const maxCpus = Math.floor(cpus / 5);
|
||||
module.exports = {
|
||||
name: 'front end',
|
||||
displayName: {
|
||||
|
@ -35,6 +37,7 @@ module.exports = {
|
|||
moduleFileExtensions: [
|
||||
'js',
|
||||
],
|
||||
maxWorkers: maxCpus,
|
||||
moduleNameMapper: {
|
||||
'\\.(css|scss)$': 'identity-obj-proxy',
|
||||
'\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/fileMock.js',
|
||||
|
|
Loading…
Reference in New Issue