2019-05-29 05:21:06 -04:00
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const sinon = require('sinon')
|
|
|
|
const { expect } = require('chai')
|
2021-02-17 08:00:48 -05:00
|
|
|
const { ObjectId } = require('mongodb')
|
|
|
|
const Errors = require('../../../../app/src/Features/Errors/Errors')
|
|
|
|
|
|
|
|
const MODULE_PATH =
|
2019-05-29 05:21:06 -04:00
|
|
|
'../../../../app/src/Features/ThirdPartyDataStore/TpdsUpdateHandler.js'
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('TpdsUpdateHandler', function () {
|
|
|
|
beforeEach(function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
this.clock = sinon.useFakeTimers()
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
afterEach(function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
this.clock.restore()
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
beforeEach(function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
this.projectName = 'My recipes'
|
|
|
|
this.projects = {
|
|
|
|
active1: { _id: new ObjectId(), name: this.projectName },
|
|
|
|
active2: { _id: new ObjectId(), name: this.projectName },
|
|
|
|
archived1: {
|
|
|
|
_id: new ObjectId(),
|
|
|
|
name: this.projectName,
|
2021-04-27 03:52:58 -04:00
|
|
|
archived: [this.userId],
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
2021-02-17 08:00:48 -05:00
|
|
|
archived2: {
|
|
|
|
_id: new ObjectId(),
|
|
|
|
name: this.projectName,
|
2021-04-27 03:52:58 -04:00
|
|
|
archived: [this.userId],
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2021-02-17 08:00:48 -05:00
|
|
|
this.userId = new ObjectId()
|
|
|
|
this.source = 'dropbox'
|
|
|
|
this.path = `/some/file`
|
|
|
|
this.update = {}
|
2022-09-21 08:01:56 -04:00
|
|
|
this.folderPath = '/some/folder'
|
|
|
|
this.folder = {
|
2023-12-18 05:54:01 -05:00
|
|
|
_id: new ObjectId(),
|
|
|
|
parentFolder_id: new ObjectId(),
|
2022-09-21 08:01:56 -04:00
|
|
|
}
|
2021-02-17 08:00:48 -05:00
|
|
|
|
|
|
|
this.CooldownManager = {
|
2022-09-07 06:28:26 -04:00
|
|
|
promises: {
|
|
|
|
isProjectOnCooldown: sinon.stub().resolves(false),
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2021-02-17 08:00:48 -05:00
|
|
|
this.FileTypeManager = {
|
2022-09-07 06:28:26 -04:00
|
|
|
promises: {
|
|
|
|
shouldIgnore: sinon.stub().resolves(false),
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2021-02-17 08:00:48 -05:00
|
|
|
this.Modules = {
|
2022-09-07 06:28:26 -04:00
|
|
|
promises: {
|
|
|
|
hooks: { fire: sinon.stub().resolves() },
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2021-02-17 08:00:48 -05:00
|
|
|
this.notification = {
|
2022-09-07 06:28:26 -04:00
|
|
|
create: sinon.stub().resolves(),
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2021-02-17 08:00:48 -05:00
|
|
|
this.NotificationsBuilder = {
|
2022-09-07 06:28:26 -04:00
|
|
|
promises: {
|
|
|
|
dropboxDuplicateProjectNames: sinon.stub().returns(this.notification),
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2021-02-17 08:00:48 -05:00
|
|
|
this.ProjectCreationHandler = {
|
2022-09-07 06:28:26 -04:00
|
|
|
promises: {
|
|
|
|
createBlankProject: sinon.stub().resolves(this.projects.active1),
|
|
|
|
},
|
2021-02-17 08:00:48 -05:00
|
|
|
}
|
|
|
|
this.ProjectDeleter = {
|
2022-09-07 06:28:26 -04:00
|
|
|
promises: {
|
|
|
|
markAsDeletedByExternalSource: sinon.stub().resolves(),
|
|
|
|
},
|
2021-02-17 08:00:48 -05:00
|
|
|
}
|
|
|
|
this.ProjectGetter = {
|
2022-09-07 06:28:26 -04:00
|
|
|
promises: {
|
|
|
|
findUsersProjectsByName: sinon.stub(),
|
2022-10-05 05:26:52 -04:00
|
|
|
findAllUsersProjects: sinon
|
|
|
|
.stub()
|
|
|
|
.resolves({ owned: [this.projects.active1], readAndWrite: [] }),
|
2022-09-07 06:28:26 -04:00
|
|
|
},
|
2021-02-17 08:00:48 -05:00
|
|
|
}
|
|
|
|
this.ProjectHelper = {
|
2021-04-27 03:52:58 -04:00
|
|
|
isArchivedOrTrashed: sinon.stub().returns(false),
|
2021-02-17 08:00:48 -05:00
|
|
|
}
|
|
|
|
this.ProjectHelper.isArchivedOrTrashed
|
|
|
|
.withArgs(this.projects.archived1, this.userId)
|
|
|
|
.returns(true)
|
|
|
|
this.ProjectHelper.isArchivedOrTrashed
|
|
|
|
.withArgs(this.projects.archived2, this.userId)
|
|
|
|
.returns(true)
|
2022-09-07 06:28:26 -04:00
|
|
|
this.RootDocManager = {
|
|
|
|
promises: {
|
|
|
|
setRootDocAutomatically: sinon.stub().resolves(),
|
|
|
|
},
|
|
|
|
}
|
2021-02-17 08:00:48 -05:00
|
|
|
this.UpdateMerger = {
|
2022-09-07 06:28:26 -04:00
|
|
|
promises: {
|
|
|
|
deleteUpdate: sinon.stub().resolves(),
|
|
|
|
mergeUpdate: sinon.stub().resolves(),
|
2022-09-21 08:01:56 -04:00
|
|
|
createFolder: sinon.stub().resolves(this.folder),
|
2022-09-07 06:28:26 -04:00
|
|
|
},
|
2021-02-17 08:00:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
this.TpdsUpdateHandler = SandboxedModule.require(MODULE_PATH, {
|
2019-05-29 05:21:06 -04:00
|
|
|
requires: {
|
|
|
|
'../Cooldown/CooldownManager': this.CooldownManager,
|
2021-02-17 08:00:48 -05:00
|
|
|
'../Uploads/FileTypeManager': this.FileTypeManager,
|
|
|
|
'../../infrastructure/Modules': this.Modules,
|
|
|
|
'../Notifications/NotificationsBuilder': this.NotificationsBuilder,
|
|
|
|
'../Project/ProjectCreationHandler': this.ProjectCreationHandler,
|
|
|
|
'../Project/ProjectDeleter': this.ProjectDeleter,
|
|
|
|
'../Project/ProjectGetter': this.ProjectGetter,
|
|
|
|
'../Project/ProjectHelper': this.ProjectHelper,
|
|
|
|
'../Project/ProjectRootDocManager': this.RootDocManager,
|
2021-04-27 03:52:58 -04:00
|
|
|
'./UpdateMerger': this.UpdateMerger,
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('getting an update', function () {
|
2022-10-05 05:26:52 -04:00
|
|
|
describe('byId', function () {
|
|
|
|
describe('with no matching project', function () {
|
|
|
|
beforeEach(function () {
|
2023-12-18 05:54:01 -05:00
|
|
|
this.projectId = new ObjectId().toString()
|
2022-10-05 05:26:52 -04:00
|
|
|
})
|
|
|
|
receiveUpdateById()
|
|
|
|
expectProjectNotCreated()
|
|
|
|
expectUpdateNotProcessed()
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with one matching active project', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.projectId = this.projects.active1._id.toString()
|
|
|
|
})
|
|
|
|
receiveUpdateById()
|
|
|
|
expectProjectNotCreated()
|
|
|
|
expectUpdateProcessed()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with no matching project', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
setupMatchingProjects([])
|
|
|
|
receiveUpdate()
|
|
|
|
expectProjectCreated()
|
|
|
|
expectUpdateProcessed()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with one matching active project', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
setupMatchingProjects(['active1'])
|
|
|
|
receiveUpdate()
|
|
|
|
expectProjectNotCreated()
|
|
|
|
expectUpdateProcessed()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with one matching archived project', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
setupMatchingProjects(['archived1'])
|
|
|
|
receiveUpdate()
|
|
|
|
expectProjectNotCreated()
|
|
|
|
expectUpdateNotProcessed()
|
|
|
|
expectDropboxNotUnlinked()
|
2020-08-24 08:21:14 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with two matching active projects', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
setupMatchingProjects(['active1', 'active2'])
|
|
|
|
receiveUpdate()
|
|
|
|
expectProjectNotCreated()
|
|
|
|
expectUpdateNotProcessed()
|
|
|
|
expectDropboxUnlinked()
|
2020-08-24 08:21:14 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with two matching archived projects', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
setupMatchingProjects(['archived1', 'archived2'])
|
|
|
|
receiveUpdate()
|
|
|
|
expectProjectNotCreated()
|
|
|
|
expectUpdateNotProcessed()
|
|
|
|
expectDropboxNotUnlinked()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with one matching active and one matching archived project', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
setupMatchingProjects(['active1', 'archived1'])
|
|
|
|
receiveUpdate()
|
|
|
|
expectProjectNotCreated()
|
|
|
|
expectUpdateNotProcessed()
|
|
|
|
expectDropboxUnlinked()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2022-09-07 06:28:26 -04:00
|
|
|
describe('update to a file that should be ignored', async function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
setupMatchingProjects(['active1'])
|
2021-04-14 09:17:21 -04:00
|
|
|
beforeEach(function () {
|
2022-09-07 06:28:26 -04:00
|
|
|
this.FileTypeManager.promises.shouldIgnore.resolves(true)
|
2021-02-17 08:00:48 -05:00
|
|
|
})
|
|
|
|
receiveUpdate()
|
|
|
|
expectProjectNotCreated()
|
|
|
|
expectUpdateNotProcessed()
|
|
|
|
expectDropboxNotUnlinked()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2022-09-07 06:28:26 -04:00
|
|
|
describe('update to a project on cooldown', async function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
setupMatchingProjects(['active1'])
|
|
|
|
setupProjectOnCooldown()
|
2022-09-07 06:28:26 -04:00
|
|
|
beforeEach(async function () {
|
|
|
|
await expect(
|
|
|
|
this.TpdsUpdateHandler.promises.newUpdate(
|
|
|
|
this.userId,
|
2022-10-05 05:26:52 -04:00
|
|
|
'', // projectId
|
2022-09-07 06:28:26 -04:00
|
|
|
this.projectName,
|
|
|
|
this.path,
|
|
|
|
this.update,
|
|
|
|
this.source
|
|
|
|
)
|
|
|
|
).to.be.rejectedWith(Errors.TooManyRequestsError)
|
2021-02-17 08:00:48 -05:00
|
|
|
})
|
|
|
|
expectUpdateNotProcessed()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('getting a file delete', function () {
|
2022-10-05 05:26:52 -04:00
|
|
|
describe('byId', function () {
|
|
|
|
describe('with no matching project', function () {
|
|
|
|
beforeEach(function () {
|
2023-12-18 05:54:01 -05:00
|
|
|
this.projectId = new ObjectId().toString()
|
2022-10-05 05:26:52 -04:00
|
|
|
})
|
|
|
|
receiveFileDeleteById()
|
|
|
|
expectDeleteNotProcessed()
|
|
|
|
expectProjectNotDeleted()
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with one matching active project', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.projectId = this.projects.active1._id.toString()
|
|
|
|
})
|
|
|
|
receiveFileDeleteById()
|
|
|
|
expectDeleteProcessed()
|
|
|
|
expectProjectNotDeleted()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with no matching project', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
setupMatchingProjects([])
|
|
|
|
receiveFileDelete()
|
|
|
|
expectDeleteNotProcessed()
|
|
|
|
expectProjectNotDeleted()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with one matching active project', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
setupMatchingProjects(['active1'])
|
|
|
|
receiveFileDelete()
|
|
|
|
expectDeleteProcessed()
|
|
|
|
expectProjectNotDeleted()
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with one matching archived project', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
setupMatchingProjects(['archived1'])
|
|
|
|
receiveFileDelete()
|
|
|
|
expectDeleteNotProcessed()
|
|
|
|
expectProjectNotDeleted()
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with two matching active projects', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
setupMatchingProjects(['active1', 'active2'])
|
|
|
|
receiveFileDelete()
|
|
|
|
expectDeleteNotProcessed()
|
|
|
|
expectProjectNotDeleted()
|
|
|
|
expectDropboxUnlinked()
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with two matching archived projects', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
setupMatchingProjects(['archived1', 'archived2'])
|
|
|
|
receiveFileDelete()
|
|
|
|
expectDeleteNotProcessed()
|
|
|
|
expectProjectNotDeleted()
|
|
|
|
expectDropboxNotUnlinked()
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with one matching active and one matching archived project', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
setupMatchingProjects(['active1', 'archived1'])
|
|
|
|
receiveFileDelete()
|
|
|
|
expectDeleteNotProcessed()
|
|
|
|
expectProjectNotDeleted()
|
|
|
|
expectDropboxUnlinked()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('getting a project delete', function () {
|
|
|
|
describe('with no matching project', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
setupMatchingProjects([])
|
|
|
|
receiveProjectDelete()
|
|
|
|
expectDeleteNotProcessed()
|
|
|
|
expectProjectNotDeleted()
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with one matching active project', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
setupMatchingProjects(['active1'])
|
|
|
|
receiveProjectDelete()
|
|
|
|
expectDeleteNotProcessed()
|
|
|
|
expectProjectDeleted()
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with one matching archived project', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
setupMatchingProjects(['archived1'])
|
|
|
|
receiveProjectDelete()
|
|
|
|
expectDeleteNotProcessed()
|
|
|
|
expectProjectNotDeleted()
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with two matching active projects', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
setupMatchingProjects(['active1', 'active2'])
|
|
|
|
receiveProjectDelete()
|
|
|
|
expectDeleteNotProcessed()
|
|
|
|
expectProjectNotDeleted()
|
|
|
|
expectDropboxUnlinked()
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with two matching archived projects', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
setupMatchingProjects(['archived1', 'archived2'])
|
|
|
|
receiveProjectDelete()
|
|
|
|
expectDeleteNotProcessed()
|
|
|
|
expectProjectNotDeleted()
|
|
|
|
expectDropboxNotUnlinked()
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with one matching active and one matching archived project', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
setupMatchingProjects(['active1', 'archived1'])
|
|
|
|
receiveProjectDelete()
|
|
|
|
expectDeleteNotProcessed()
|
|
|
|
expectProjectNotDeleted()
|
|
|
|
expectDropboxUnlinked()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
2022-09-21 08:01:56 -04:00
|
|
|
|
|
|
|
describe('getting a folder update', function () {
|
|
|
|
describe('with no matching project', function () {
|
|
|
|
setupMatchingProjects([])
|
|
|
|
receiveFolderUpdate()
|
|
|
|
expectProjectCreated()
|
|
|
|
expectFolderUpdateProcessed()
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with one matching active project', function () {
|
|
|
|
setupMatchingProjects(['active1'])
|
|
|
|
receiveFolderUpdate()
|
|
|
|
expectProjectNotCreated()
|
|
|
|
expectFolderUpdateProcessed()
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with one matching archived project', function () {
|
|
|
|
setupMatchingProjects(['archived1'])
|
|
|
|
receiveFolderUpdate()
|
|
|
|
expectProjectNotCreated()
|
|
|
|
expectFolderUpdateNotProcessed()
|
|
|
|
expectDropboxNotUnlinked()
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with two matching active projects', function () {
|
|
|
|
setupMatchingProjects(['active1', 'active2'])
|
|
|
|
receiveFolderUpdate()
|
|
|
|
expectProjectNotCreated()
|
|
|
|
expectFolderUpdateNotProcessed()
|
|
|
|
expectDropboxUnlinked()
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with two matching archived projects', function () {
|
|
|
|
setupMatchingProjects(['archived1', 'archived2'])
|
|
|
|
receiveFolderUpdate()
|
|
|
|
expectProjectNotCreated()
|
|
|
|
expectFolderUpdateNotProcessed()
|
|
|
|
expectDropboxNotUnlinked()
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with one matching active and one matching archived project', function () {
|
|
|
|
setupMatchingProjects(['active1', 'archived1'])
|
|
|
|
receiveFolderUpdate()
|
|
|
|
expectProjectNotCreated()
|
|
|
|
expectFolderUpdateNotProcessed()
|
|
|
|
expectDropboxUnlinked()
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('update to a project on cooldown', async function () {
|
|
|
|
setupMatchingProjects(['active1'])
|
|
|
|
setupProjectOnCooldown()
|
|
|
|
beforeEach(async function () {
|
|
|
|
await expect(
|
|
|
|
this.TpdsUpdateHandler.promises.createFolder(
|
|
|
|
this.userId,
|
2022-10-05 05:26:52 -04:00
|
|
|
this.projectId,
|
2022-09-21 08:01:56 -04:00
|
|
|
this.projectName,
|
|
|
|
this.path
|
|
|
|
)
|
|
|
|
).to.be.rejectedWith(Errors.TooManyRequestsError)
|
|
|
|
})
|
|
|
|
expectFolderUpdateNotProcessed()
|
|
|
|
})
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
2021-02-17 08:00:48 -05:00
|
|
|
|
|
|
|
/* Setup helpers */
|
|
|
|
|
|
|
|
function setupMatchingProjects(projectKeys) {
|
2021-04-14 09:17:21 -04:00
|
|
|
beforeEach(function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
const projects = projectKeys.map(key => this.projects[key])
|
2022-09-07 06:28:26 -04:00
|
|
|
this.ProjectGetter.promises.findUsersProjectsByName
|
2021-02-17 08:00:48 -05:00
|
|
|
.withArgs(this.userId, this.projectName)
|
2022-09-07 06:28:26 -04:00
|
|
|
.resolves(projects)
|
2021-02-17 08:00:48 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function setupProjectOnCooldown() {
|
2021-04-14 09:17:21 -04:00
|
|
|
beforeEach(function () {
|
2022-09-07 06:28:26 -04:00
|
|
|
this.CooldownManager.promises.isProjectOnCooldown
|
2021-02-17 08:00:48 -05:00
|
|
|
.withArgs(this.projects.active1._id)
|
2022-09-07 06:28:26 -04:00
|
|
|
.resolves(true)
|
2021-02-17 08:00:48 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test helpers */
|
|
|
|
|
|
|
|
function receiveUpdate() {
|
2022-09-07 06:28:26 -04:00
|
|
|
beforeEach(async function () {
|
|
|
|
await this.TpdsUpdateHandler.promises.newUpdate(
|
2021-02-17 08:00:48 -05:00
|
|
|
this.userId,
|
2022-10-05 05:26:52 -04:00
|
|
|
'', // projectId
|
2021-02-17 08:00:48 -05:00
|
|
|
this.projectName,
|
|
|
|
this.path,
|
|
|
|
this.update,
|
2022-09-07 06:28:26 -04:00
|
|
|
this.source
|
2021-02-17 08:00:48 -05:00
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-10-05 05:26:52 -04:00
|
|
|
function receiveUpdateById() {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
this.TpdsUpdateHandler.newUpdate(
|
|
|
|
this.userId,
|
|
|
|
this.projectId,
|
|
|
|
'', // projectName
|
|
|
|
this.path,
|
|
|
|
this.update,
|
|
|
|
this.source,
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-02-17 08:00:48 -05:00
|
|
|
function receiveFileDelete() {
|
2022-09-07 06:28:26 -04:00
|
|
|
beforeEach(async function () {
|
|
|
|
await this.TpdsUpdateHandler.promises.deleteUpdate(
|
2021-02-17 08:00:48 -05:00
|
|
|
this.userId,
|
2022-10-05 05:26:52 -04:00
|
|
|
'', // projectId
|
2021-02-17 08:00:48 -05:00
|
|
|
this.projectName,
|
|
|
|
this.path,
|
2022-09-07 06:28:26 -04:00
|
|
|
this.source
|
2021-02-17 08:00:48 -05:00
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-10-05 05:26:52 -04:00
|
|
|
function receiveFileDeleteById() {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
this.TpdsUpdateHandler.deleteUpdate(
|
|
|
|
this.userId,
|
|
|
|
this.projectId,
|
|
|
|
'', // projectName
|
|
|
|
this.path,
|
|
|
|
this.source,
|
|
|
|
done
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-02-17 08:00:48 -05:00
|
|
|
function receiveProjectDelete() {
|
2022-09-07 06:28:26 -04:00
|
|
|
beforeEach(async function () {
|
|
|
|
await this.TpdsUpdateHandler.promises.deleteUpdate(
|
2021-02-17 08:00:48 -05:00
|
|
|
this.userId,
|
2022-10-05 05:26:52 -04:00
|
|
|
'', // projectId
|
2021-02-17 08:00:48 -05:00
|
|
|
this.projectName,
|
|
|
|
'/',
|
2022-09-07 06:28:26 -04:00
|
|
|
this.source
|
2021-02-17 08:00:48 -05:00
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-09-21 08:01:56 -04:00
|
|
|
function receiveFolderUpdate() {
|
|
|
|
beforeEach(async function () {
|
|
|
|
await this.TpdsUpdateHandler.promises.createFolder(
|
|
|
|
this.userId,
|
2022-10-05 05:26:52 -04:00
|
|
|
this.projectId,
|
2022-09-21 08:01:56 -04:00
|
|
|
this.projectName,
|
|
|
|
this.folderPath
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-02-17 08:00:48 -05:00
|
|
|
/* Expectations */
|
|
|
|
|
|
|
|
function expectProjectCreated() {
|
2021-04-14 09:17:21 -04:00
|
|
|
it('creates a project', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
expect(
|
2022-09-07 06:28:26 -04:00
|
|
|
this.ProjectCreationHandler.promises.createBlankProject
|
2021-02-17 08:00:48 -05:00
|
|
|
).to.have.been.calledWith(this.userId, this.projectName)
|
|
|
|
})
|
|
|
|
|
2023-05-24 06:01:56 -04:00
|
|
|
it('sets the root doc', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
// Fire pending timers
|
2023-05-24 06:01:56 -04:00
|
|
|
this.clock.next()
|
2022-09-07 06:28:26 -04:00
|
|
|
expect(
|
|
|
|
this.RootDocManager.promises.setRootDocAutomatically
|
|
|
|
).to.have.been.calledWith(this.projects.active1._id)
|
2021-02-17 08:00:48 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function expectProjectNotCreated() {
|
2021-04-14 09:17:21 -04:00
|
|
|
it('does not create a project', function () {
|
2022-09-07 06:28:26 -04:00
|
|
|
expect(this.ProjectCreationHandler.promises.createBlankProject).not.to.have
|
|
|
|
.been.called
|
2021-02-17 08:00:48 -05:00
|
|
|
})
|
|
|
|
|
2023-05-24 06:01:56 -04:00
|
|
|
it('does not set the root doc', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
// Fire pending timers
|
2023-05-24 06:01:56 -04:00
|
|
|
this.clock.next()
|
2022-09-07 06:28:26 -04:00
|
|
|
expect(this.RootDocManager.promises.setRootDocAutomatically).not.to.have
|
|
|
|
.been.called
|
2021-02-17 08:00:48 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function expectUpdateProcessed() {
|
2021-04-14 09:17:21 -04:00
|
|
|
it('processes the update', function () {
|
2022-09-07 06:28:26 -04:00
|
|
|
expect(this.UpdateMerger.promises.mergeUpdate).to.have.been.calledWith(
|
2021-02-17 08:00:48 -05:00
|
|
|
this.userId,
|
|
|
|
this.projects.active1._id,
|
|
|
|
this.path,
|
|
|
|
this.update,
|
|
|
|
this.source
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function expectUpdateNotProcessed() {
|
2021-04-14 09:17:21 -04:00
|
|
|
it('does not process the update', function () {
|
2022-09-07 06:28:26 -04:00
|
|
|
expect(this.UpdateMerger.promises.mergeUpdate).not.to.have.been.called
|
2021-02-17 08:00:48 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-09-21 08:01:56 -04:00
|
|
|
function expectFolderUpdateProcessed() {
|
|
|
|
it('processes the folder update', function () {
|
|
|
|
expect(this.UpdateMerger.promises.createFolder).to.have.been.calledWith(
|
|
|
|
this.projects.active1._id,
|
|
|
|
this.folderPath
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function expectFolderUpdateNotProcessed() {
|
|
|
|
it("doesn't process the folder update", function () {
|
|
|
|
expect(this.UpdateMerger.promises.createFolder).not.to.have.been.called
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-02-17 08:00:48 -05:00
|
|
|
function expectDropboxUnlinked() {
|
2021-04-14 09:17:21 -04:00
|
|
|
it('unlinks Dropbox', function () {
|
2022-09-07 06:28:26 -04:00
|
|
|
expect(this.Modules.promises.hooks.fire).to.have.been.calledWith(
|
2021-02-17 08:00:48 -05:00
|
|
|
'removeDropbox',
|
2021-05-18 09:40:56 -04:00
|
|
|
this.userId,
|
|
|
|
'duplicate-projects'
|
2021-02-17 08:00:48 -05:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('creates a notification that dropbox was unlinked', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
expect(
|
2022-09-07 06:28:26 -04:00
|
|
|
this.NotificationsBuilder.promises.dropboxDuplicateProjectNames
|
2021-02-17 08:00:48 -05:00
|
|
|
).to.have.been.calledWith(this.userId)
|
|
|
|
expect(this.notification.create).to.have.been.calledWith(this.projectName)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function expectDropboxNotUnlinked() {
|
2021-04-14 09:17:21 -04:00
|
|
|
it('does not unlink Dropbox', function () {
|
2022-09-07 06:28:26 -04:00
|
|
|
expect(this.Modules.promises.hooks.fire).not.to.have.been.called
|
2021-02-17 08:00:48 -05:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('does not create a notification that dropbox was unlinked', function () {
|
2022-09-07 06:28:26 -04:00
|
|
|
expect(this.NotificationsBuilder.promises.dropboxDuplicateProjectNames).not
|
|
|
|
.to.have.been.called
|
2021-02-17 08:00:48 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function expectDeleteProcessed() {
|
2021-04-14 09:17:21 -04:00
|
|
|
it('processes the delete', function () {
|
2022-09-07 06:28:26 -04:00
|
|
|
expect(this.UpdateMerger.promises.deleteUpdate).to.have.been.calledWith(
|
2021-02-17 08:00:48 -05:00
|
|
|
this.userId,
|
|
|
|
this.projects.active1._id,
|
|
|
|
this.path,
|
|
|
|
this.source
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function expectDeleteNotProcessed() {
|
2021-04-14 09:17:21 -04:00
|
|
|
it('does not process the delete', function () {
|
2022-09-07 06:28:26 -04:00
|
|
|
expect(this.UpdateMerger.promises.deleteUpdate).not.to.have.been.called
|
2021-02-17 08:00:48 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function expectProjectDeleted() {
|
2021-04-14 09:17:21 -04:00
|
|
|
it('deletes the project', function () {
|
2021-02-17 08:00:48 -05:00
|
|
|
expect(
|
2022-09-07 06:28:26 -04:00
|
|
|
this.ProjectDeleter.promises.markAsDeletedByExternalSource
|
2021-02-17 08:00:48 -05:00
|
|
|
).to.have.been.calledWith(this.projects.active1._id)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function expectProjectNotDeleted() {
|
2021-04-14 09:17:21 -04:00
|
|
|
it('does not delete the project', function () {
|
2022-09-07 06:28:26 -04:00
|
|
|
expect(this.ProjectDeleter.promises.markAsDeletedByExternalSource).not.to
|
|
|
|
.have.been.called
|
2021-02-17 08:00:48 -05:00
|
|
|
})
|
|
|
|
}
|