diff --git a/services/web/test/acceptance/src/ProjectStructureTests.js b/services/web/test/acceptance/src/ProjectStructureTests.js index fff37acc9a..4087efcb8b 100644 --- a/services/web/test/acceptance/src/ProjectStructureTests.js +++ b/services/web/test/acceptance/src/ProjectStructureTests.js @@ -97,47 +97,21 @@ describe('ProjectStructureChanges', function() { contentType, callback ) { - const imageFile = fs.createReadStream( - Path.resolve(Path.join(__dirname, '..', 'files', file)) - ) - - owner.request.post( - { - uri: `project/${projectId}/upload`, - qs: { - folder_id: folderId - }, - formData: { - qqfile: { - value: imageFile, - options: { - filename: name, - contentType: contentType - } - } - } - }, - (error, res, body) => { - if (error) { - return callback(error) - } - if (res.statusCode < 200 || res.statusCode >= 300) { - return callback(new Error(`failed to upload file ${res.statusCode}`)) - } - - callback(null, JSON.parse(body).entity_id) - } + owner.uploadFileInProject( + projectId, + folderId, + file, + name, + contentType, + callback ) } function uploadExampleFile(owner, projectId, folderId, callback) { - uploadFile( - owner, + owner.uploadExampleFileInProject( projectId, folderId, '1pixel.png', - '1pixel.png', - 'image/png', callback ) } @@ -175,66 +149,15 @@ describe('ProjectStructureChanges', function() { } function moveItem(owner, projectId, type, itemId, folderId, callback) { - owner.request.post( - { - uri: `project/${projectId}/${type}/${itemId}/move`, - json: { - folder_id: folderId - } - }, - (error, res) => { - if (error) { - return callback(error) - } - if (res.statusCode < 200 || res.statusCode >= 300) { - return callback(new Error(`failed to move ${type} ${res.statusCode}`)) - } - - callback() - } - ) + owner.moveItemInProject(projectId, type, itemId, folderId, callback) } function renameItem(owner, projectId, type, itemId, name, callback) { - owner.request.post( - { - uri: `project/${projectId}/${type}/${itemId}/rename`, - json: { - name: name - } - }, - (error, res) => { - if (error) { - return callback(error) - } - if (res.statusCode < 200 || res.statusCode >= 300) { - return callback( - new Error(`failed to rename ${type} ${res.statusCode}`) - ) - } - - callback() - } - ) + owner.renameItemInProject(projectId, type, itemId, name, callback) } function deleteItem(owner, projectId, type, itemId, callback) { - owner.request.delete( - { - uri: `project/${projectId}/${type}/${itemId}` - }, - (error, res) => { - if (error) { - return callback(error) - } - if (res.statusCode < 200 || res.statusCode >= 300) { - return callback( - new Error(`failed to delete folder ${res.statusCode}`) - ) - } - callback() - } - ) + owner.deleteItemInProject(projectId, type, itemId, callback) } function verifyVersionIncremented( diff --git a/services/web/test/acceptance/src/helpers/User.js b/services/web/test/acceptance/src/helpers/User.js index 0401486e75..e1f7fa64ce 100644 --- a/services/web/test/acceptance/src/helpers/User.js +++ b/services/web/test/acceptance/src/helpers/User.js @@ -5,6 +5,8 @@ const UserModel = require('../../../../app/src/models/User').User const UserUpdater = require('../../../../app/src/Features/User/UserUpdater') const AuthenticationManager = require('../../../../app/src/Features/Authentication/AuthenticationManager') const { promisify } = require('util') +const fs = require('fs') +const Path = require('path') let count = 0 @@ -401,6 +403,112 @@ class User { }) } + uploadFileInProject(projectId, folderId, file, name, contentType, callback) { + const imageFile = fs.createReadStream( + Path.resolve(Path.join(__dirname, '..', '..', 'files', file)) + ) + + this.request.post( + { + uri: `project/${projectId}/upload`, + qs: { + folder_id: String(folderId) + }, + formData: { + qqfile: { + value: imageFile, + options: { + filename: name, + contentType: contentType + } + } + } + }, + (error, res, body) => { + if (error) { + return callback(error) + } + if (res.statusCode < 200 || res.statusCode >= 300) { + return callback(new Error(`failed to upload file ${res.statusCode}`)) + } + + callback(null, JSON.parse(body).entity_id) + } + ) + } + + uploadExampleFileInProject(projectId, folderId, name, callback) { + this.uploadFileInProject( + projectId, + folderId, + '1pixel.png', + name, + 'image/png', + callback + ) + } + + moveItemInProject(projectId, type, itemId, folderId, callback) { + this.request.post( + { + uri: `project/${projectId}/${type}/${itemId}/move`, + json: { + folder_id: folderId + } + }, + (error, res) => { + if (error) { + return callback(error) + } + if (res.statusCode < 200 || res.statusCode >= 300) { + return callback(new Error(`failed to move ${type} ${res.statusCode}`)) + } + + callback() + } + ) + } + + renameItemInProject(projectId, type, itemId, name, callback) { + this.request.post( + { + uri: `project/${projectId}/${type}/${itemId}/rename`, + json: { + name: name + } + }, + (error, res) => { + if (error) { + return callback(error) + } + if (res.statusCode < 200 || res.statusCode >= 300) { + return callback( + new Error(`failed to rename ${type} ${res.statusCode}`) + ) + } + + callback() + } + ) + } + + deleteItemInProject(projectId, type, itemId, callback) { + this.request.delete( + `project/${projectId}/${type}/${itemId}`, + (error, res) => { + if (error) { + return callback(error) + } + if (res.statusCode < 200 || res.statusCode >= 300) { + return callback( + new Error(`failed to delete ${type} ${res.statusCode}`) + ) + } + callback() + } + ) + } + addUserToProject(projectId, user, privileges, callback) { let updateOp if (privileges === 'readAndWrite') {