Merge pull request #9316 from overleaf/jpa-dropbox-sync-detached-from-project-name

[misc] detach dropbox sync from project names

GitOrigin-RevId: 57b3a131aec81bc97ff4da57497950d6658eaeff
This commit is contained in:
Jakob Ackermann
2022-10-05 13:25:08 +00:00
committed by Copybot
parent 7517f4c005
commit ac91f40c08
5 changed files with 219 additions and 24 deletions
@@ -63,14 +63,18 @@ describe('TpdsController', function () {
this.projectName = 'projectName'
this.path = '/here.txt'
this.req = {
params: { 0: `${this.projectName}${this.path}`, user_id: this.user_id },
params: {
0: `${this.projectName}${this.path}`,
user_id: this.user_id,
project_id: '',
},
headers: {
'x-sl-update-source': (this.source = 'dropbox'),
},
}
})
it('should process the update with the update receiver', function (done) {
it('should process the update with the update receiver by name', function (done) {
const res = {
json: payload => {
expect(payload).to.deep.equal({
@@ -84,6 +88,7 @@ describe('TpdsController', function () {
this.TpdsUpdateHandler.promises.newUpdate
.calledWith(
this.user_id,
'', // projectId
this.projectName,
this.path,
this.req,
@@ -107,6 +112,34 @@ describe('TpdsController', function () {
this.TpdsController.mergeUpdate(this.req, res)
})
it('should process the update with the update receiver by id', function (done) {
const path = '/here.txt'
const req = {
pause() {},
params: { 0: path, user_id: this.user_id, project_id: '123' },
session: {
destroy() {},
},
headers: {
'x-sl-update-source': (this.source = 'dropbox'),
},
}
const res = {
json: () => {
this.TpdsUpdateHandler.promises.newUpdate.should.have.been.calledWith(
this.user_id,
'123',
'', // projectName
'/here.txt',
req,
this.source
)
done()
},
}
this.TpdsController.mergeUpdate(req, res)
})
it('should return a 500 error when the update receiver fails', function (done) {
this.TpdsUpdateHandler.promises.newUpdate.rejects(new Error())
const res = {
@@ -150,10 +183,10 @@ describe('TpdsController', function () {
})
describe('getting a delete update', function () {
it('should process the delete with the update receiver', function (done) {
it('should process the delete with the update receiver by name', function (done) {
const path = '/projectName/here.txt'
const req = {
params: { 0: path, user_id: this.user_id },
params: { 0: path, user_id: this.user_id, project_id: '' },
session: {
destroy() {},
},
@@ -164,13 +197,45 @@ describe('TpdsController', function () {
const res = {
sendStatus: () => {
this.TpdsUpdateHandler.promises.deleteUpdate
.calledWith(this.user_id, 'projectName', '/here.txt', this.source)
.calledWith(
this.user_id,
'',
'projectName',
'/here.txt',
this.source
)
.should.equal(true)
done()
},
}
this.TpdsController.deleteUpdate(req, res)
})
it('should process the delete with the update receiver by id', function (done) {
const path = '/here.txt'
const req = {
params: { 0: path, user_id: this.user_id, project_id: '123' },
session: {
destroy() {},
},
headers: {
'x-sl-update-source': (this.source = 'dropbox'),
},
}
const res = {
sendStatus: () => {
this.TpdsUpdateHandler.promises.deleteUpdate.should.have.been.calledWith(
this.user_id,
'123',
'', // projectName
'/here.txt',
this.source
)
done()
},
}
this.TpdsController.deleteUpdate(req, res)
})
})
describe('updateFolder', function () {
@@ -78,6 +78,9 @@ describe('TpdsUpdateHandler', function () {
this.ProjectGetter = {
promises: {
findUsersProjectsByName: sinon.stub(),
findAllUsersProjects: sinon
.stub()
.resolves({ owned: [this.projects.active1], readAndWrite: [] }),
},
}
this.ProjectHelper = {
@@ -119,6 +122,26 @@ describe('TpdsUpdateHandler', function () {
})
describe('getting an update', function () {
describe('byId', function () {
describe('with no matching project', function () {
beforeEach(function () {
this.projectId = ObjectId().toString()
})
receiveUpdateById()
expectProjectNotCreated()
expectUpdateNotProcessed()
})
describe('with one matching active project', function () {
beforeEach(function () {
this.projectId = this.projects.active1._id.toString()
})
receiveUpdateById()
expectProjectNotCreated()
expectUpdateProcessed()
})
})
describe('with no matching project', function () {
setupMatchingProjects([])
receiveUpdate()
@@ -183,6 +206,7 @@ describe('TpdsUpdateHandler', function () {
await expect(
this.TpdsUpdateHandler.promises.newUpdate(
this.userId,
'', // projectId
this.projectName,
this.path,
this.update,
@@ -195,6 +219,26 @@ describe('TpdsUpdateHandler', function () {
})
describe('getting a file delete', function () {
describe('byId', function () {
describe('with no matching project', function () {
beforeEach(function () {
this.projectId = ObjectId().toString()
})
receiveFileDeleteById()
expectDeleteNotProcessed()
expectProjectNotDeleted()
})
describe('with one matching active project', function () {
beforeEach(function () {
this.projectId = this.projects.active1._id.toString()
})
receiveFileDeleteById()
expectDeleteProcessed()
expectProjectNotDeleted()
})
})
describe('with no matching project', function () {
setupMatchingProjects([])
receiveFileDelete()
@@ -342,6 +386,7 @@ describe('TpdsUpdateHandler', function () {
await expect(
this.TpdsUpdateHandler.promises.createFolder(
this.userId,
this.projectId,
this.projectName,
this.path
)
@@ -377,6 +422,7 @@ function receiveUpdate() {
beforeEach(async function () {
await this.TpdsUpdateHandler.promises.newUpdate(
this.userId,
'', // projectId
this.projectName,
this.path,
this.update,
@@ -385,10 +431,25 @@ function receiveUpdate() {
})
}
function receiveUpdateById() {
beforeEach(function (done) {
this.TpdsUpdateHandler.newUpdate(
this.userId,
this.projectId,
'', // projectName
this.path,
this.update,
this.source,
done
)
})
}
function receiveFileDelete() {
beforeEach(async function () {
await this.TpdsUpdateHandler.promises.deleteUpdate(
this.userId,
'', // projectId
this.projectName,
this.path,
this.source
@@ -396,10 +457,24 @@ function receiveFileDelete() {
})
}
function receiveFileDeleteById() {
beforeEach(function (done) {
this.TpdsUpdateHandler.deleteUpdate(
this.userId,
this.projectId,
'', // projectName
this.path,
this.source,
done
)
})
}
function receiveProjectDelete() {
beforeEach(async function () {
await this.TpdsUpdateHandler.promises.deleteUpdate(
this.userId,
'', // projectId
this.projectName,
'/',
this.source
@@ -411,6 +486,7 @@ function receiveFolderUpdate() {
beforeEach(async function () {
await this.TpdsUpdateHandler.promises.createFolder(
this.userId,
this.projectId,
this.projectName,
this.folderPath
)