Compare commits

...

1 Commits

Author SHA1 Message Date
Javier Segarra 35f0997020 test
gitea/salix/pipeline/head There was a failure building this commit Details
2024-01-04 14:34:43 +01:00
6 changed files with 88 additions and 17 deletions

View File

@ -1,17 +1,84 @@
const {models} = require('vn-loopback/server/server'); 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() => { it(`should return an error for a user without enough privileges`, async() => {
let clientId = 1101; let clientId = 1101;
let ticketDmsTypeId = 14; let ticketDmsTypeId = 14;
let ctx = {req: {accessToken: {userId: clientId}}, args: {dmsTypeId: ticketDmsTypeId}}; let ctx = {
req: {accessToken: {userId: clientId}},
args: {dmsTypeId: ticketDmsTypeId},
};
let error; let error;
await models.Dms.uploadFile(ctx).catch(e => { await models.Dms.uploadFile(ctx)
error = e; .catch(e => {
}).finally(() => { error = e;
expect(error.message).toEqual(`You don't have enough privileges`); })
.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(); expect(error).toBeDefined();
}); });

View File

@ -66,9 +66,9 @@ module.exports = Self => {
let srcFile; let srcFile;
try { try {
const hasWriteRole = await models.DmsType.hasWriteRole(ctx, args.dmsTypeId, myOptions); // const hasWriteRole = await models.DmsType.hasWriteRole(ctx, args.dmsTypeId, myOptions);
if (!hasWriteRole) // if (!hasWriteRole)
throw new UserError(`You don't have enough privileges`); // throw new UserError(`You don't have enough privileges`);
// Upload file to temporary path // Upload file to temporary path
const tempContainer = await TempContainer.container('dms'); const tempContainer = await TempContainer.container('dms');

View File

@ -1,6 +1,6 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
describe('docuware upload()', () => { fdescribe('docuware upload()', () => {
const userId = 9; const userId = 9;
const ticketIds = [10]; const ticketIds = [10];
const ctx = { const ctx = {

View File

@ -121,18 +121,18 @@ module.exports = Self => {
if (process.env.NODE_ENV != 'production') if (process.env.NODE_ENV != 'production')
throw new UserError('Action not allowed on the test environment'); throw new UserError('Action not allowed on the test environment');
const BASE_URL = `${options.url}/FileCabinets/${fileCabinetId}/Documents`;
// delete old // delete old
const docuwareFile = await models.Docuware.checkFile(id, fileCabinet, false); const docuwareFile = await models.Docuware.checkFile(id, fileCabinet, false);
if (docuwareFile) { if (docuwareFile) {
const deleteJson = { const deleteJson = {
'Field': [{'FieldName': 'ESTADO', 'Item': 'Pendiente eliminar', 'ItemElementName': 'String'}] 'Field': [{'FieldName': 'ESTADO', 'Item': 'Pendiente eliminar', 'ItemElementName': 'String'}]
}; };
const deleteUri = `${docuwareOptions.url}/FileCabinets/${fileCabinetId}/Documents/${docuwareFile.id}/Fields`; const deleteUri = `${BASE_URL}/${docuwareFile.id}/Fields`;
await axios.put(deleteUri, deleteJson, docuwareOptions.headers); 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 FormData = require('form-data');
const data = new FormData(); const data = new FormData();

View File

@ -48,7 +48,8 @@ async function test() {
jasmine.addReporter(new SpecReporter({ jasmine.addReporter(new SpecReporter({
spec: { spec: {
displaySuccessful: isCI, displaySuccessful: isCI,
displayPending: isCI displayPending: isCI,
displayFailed: isCI
}, },
summary: { summary: {
displayPending: false, displayPending: false,
@ -59,9 +60,9 @@ async function test() {
const JunitReporter = require('jasmine-reporters'); const JunitReporter = require('jasmine-reporters');
jasmine.addReporter(new JunitReporter.JUnitXmlReporter()); jasmine.addReporter(new JunitReporter.JUnitXmlReporter());
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;
jasmine.exitOnCompletion = true; jasmine.exitOnCompletion = true;
} }
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;
const backSpecs = [ const backSpecs = [
'./back/**/*[sS]pec.js', './back/**/*[sS]pec.js',

View File

@ -1,7 +1,9 @@
// For a detailed explanation regarding each configuration property, visit: // For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html // https://jestjs.io/docs/en/configuration.html
/* eslint max-len: ["error", { "code": 150 }]*/ /* eslint max-len: ["error", { "code": 150 }]*/
/** @type {import('jest').Config} */
const cpus = require('os').cpus().length;
const maxCpus = Math.floor(cpus / 5);
module.exports = { module.exports = {
name: 'front end', name: 'front end',
displayName: { displayName: {
@ -35,6 +37,7 @@ module.exports = {
moduleFileExtensions: [ moduleFileExtensions: [
'js', 'js',
], ],
maxWorkers: maxCpus,
moduleNameMapper: { moduleNameMapper: {
'\\.(css|scss)$': 'identity-obj-proxy', '\\.(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', '\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/fileMock.js',