diff --git a/services/history-v1/api/swagger/projects.js b/services/history-v1/api/swagger/projects.js index f4b8ed7352..600e864f19 100644 --- a/services/history-v1/api/swagger/projects.js +++ b/services/history-v1/api/swagger/projects.js @@ -9,6 +9,7 @@ exports.paths = { operationId: 'initializeProject', tags: ['Project'], description: 'Initialize project.', + consumes: ['application/json'], parameters: [ { name: 'body', diff --git a/services/history-v1/test/acceptance/js/api/project_updates.test.js b/services/history-v1/test/acceptance/js/api/project_updates.test.js index a248930cba..d67000245a 100644 --- a/services/history-v1/test/acceptance/js/api/project_updates.test.js +++ b/services/history-v1/test/acceptance/js/api/project_updates.test.js @@ -11,6 +11,7 @@ const expectResponse = require('./support/expect_response') const testServer = require('./support/test_server') const core = require('overleaf-editor-core') +const testProjects = require('./support/test_projects') const Change = core.Change const ChunkResponse = core.ChunkResponse const File = core.File @@ -637,10 +638,10 @@ describe('history import', function () { let testProjectId - return BPromise.resolve(basicAuthClient.apis.Project.initializeProject()) - .then(response => { - expect(response.status).to.equal(HTTPStatus.OK) - testProjectId = response.obj.projectId + return testProjects + .createEmptyProject() + .then(projectId => { + testProjectId = projectId expect(testProjectId).to.be.a('string') }) .then(() => { @@ -705,10 +706,10 @@ describe('history import', function () { let testProjectId - return basicAuthClient.apis.Project.initializeProject() - .then(response => { - expect(response.status).to.equal(HTTPStatus.OK) - testProjectId = response.obj.projectId + return testProjects + .createEmptyProject() + .then(projectId => { + testProjectId = projectId expect(testProjectId).to.be.a('string') }) .then(() => { @@ -756,10 +757,10 @@ describe('history import', function () { let testProjectId - return basicAuthClient.apis.Project.initializeProject() - .then(response => { - expect(response.status).to.equal(HTTPStatus.OK) - testProjectId = response.obj.projectId + return testProjects + .createEmptyProject() + .then(projectId => { + testProjectId = projectId expect(testProjectId).to.be.a('string') }) .then(() => { @@ -802,10 +803,9 @@ describe('history import', function () { }) it("returns unprocessable if end_version isn't provided", function () { - return basicAuthClient.apis.Project.initializeProject() - .then(response => { - expect(response.status).to.equal(HTTPStatus.OK) - const projectId = response.obj.projectId + return testProjects + .createEmptyProject() + .then(projectId => { expect(projectId).to.be.a('string') return projectId }) @@ -828,11 +828,8 @@ describe('history import', function () { }) it('returns unprocessable if return_snapshot is invalid', function () { - return basicAuthClient.apis.Project.initializeProject() - .then(response => { - expect(response.status).to.equal(HTTPStatus.OK) - return response.obj.projectId - }) + return testProjects + .createEmptyProject() .then(projectId => { // Import changes return basicAuthClient.apis.ProjectImport.importChanges1({ diff --git a/services/history-v1/test/acceptance/js/api/projects.test.js b/services/history-v1/test/acceptance/js/api/projects.test.js index ade51e418c..6358f8505d 100644 --- a/services/history-v1/test/acceptance/js/api/projects.test.js +++ b/services/history-v1/test/acceptance/js/api/projects.test.js @@ -22,23 +22,16 @@ const { Change, AddFileOperation, } = require('overleaf-editor-core') +const testProjects = require('./support/test_projects') describe('project controller', function () { beforeEach(cleanup.everything) beforeEach(fixtures.create) describe('initializeProject', function () { - let initializeProject - - before(function () { - initializeProject = - testServer.basicAuthClient.apis.Project.initializeProject - }) - it('can initialize a new project', async function () { - const response = await initializeProject() - expect(response.status).to.equal(HTTPStatus.OK) - expect(response.obj.projectId).to.be.a('string') + const projectId = await testProjects.createEmptyProject() + expect(projectId).to.be.a('string') }) }) diff --git a/services/history-v1/test/acceptance/js/api/support/test_projects.js b/services/history-v1/test/acceptance/js/api/support/test_projects.js index 9e97d8c77d..df4d83e537 100644 --- a/services/history-v1/test/acceptance/js/api/support/test_projects.js +++ b/services/history-v1/test/acceptance/js/api/support/test_projects.js @@ -5,9 +5,18 @@ const assert = require('../../../../../storage/lib/assert') const testServer = require('./test_server') -exports.createEmptyProject = function () { +/** + * Without a provided history id, a new one will get generated. + * The history id could either be a mongo id, or a postgres id. + * + * @param {string} [existingHistoryId] + * @return {Promise} + */ +exports.createEmptyProject = function (existingHistoryId) { return BPromise.resolve( - testServer.basicAuthClient.apis.Project.initializeProject() + testServer.basicAuthClient.apis.Project.initializeProject({ + body: { projectId: existingHistoryId }, + }) ).then(response => { expect(response.status).to.equal(HTTPStatus.OK) const { projectId } = response.obj