mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-31 04:41:32 +02:00
Merge pull request #16657 from overleaf/dp-mongoose-callback-project-update-handler
Promisify ProjectUpdateHandler and ProjectUpdateHandlerTests GitOrigin-RevId: 312cbe71d431cf50932ab7d5501529d87f7827f2
This commit is contained in:
@@ -1,16 +1,3 @@
|
||||
/* eslint-disable
|
||||
n/handle-callback-err,
|
||||
max-len,
|
||||
no-return-assign,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const sinon = require('sinon')
|
||||
const modulePath =
|
||||
'../../../../app/src/Features/Project/ProjectUpdateHandler.js'
|
||||
@@ -27,98 +14,89 @@ describe('ProjectUpdateHandler', function () {
|
||||
})
|
||||
|
||||
beforeEach(function () {
|
||||
let Project
|
||||
this.ProjectModel = Project = class Project {}
|
||||
this.ProjectModel.updateOne = sinon.stub().callsArg(3)
|
||||
return (this.handler = SandboxedModule.require(modulePath, {
|
||||
this.ProjectModel = class Project {}
|
||||
this.ProjectModel.updateOne = sinon.stub().returns({
|
||||
exec: sinon.stub(),
|
||||
})
|
||||
this.handler = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'../../models/Project': { Project: this.ProjectModel },
|
||||
},
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
||||
describe('marking a project as recently updated', function () {
|
||||
beforeEach(function () {
|
||||
this.project_id = 'project_id'
|
||||
this.lastUpdatedAt = 987654321
|
||||
return (this.lastUpdatedBy = 'fake-last-updater-id')
|
||||
this.lastUpdatedBy = 'fake-last-updater-id'
|
||||
})
|
||||
|
||||
it('should send an update to mongo', function (done) {
|
||||
return this.handler.markAsUpdated(
|
||||
it('should send an update to mongo', async function () {
|
||||
await this.handler.promises.markAsUpdated(
|
||||
this.project_id,
|
||||
this.lastUpdatedAt,
|
||||
this.lastUpdatedBy,
|
||||
err => {
|
||||
sinon.assert.calledWith(
|
||||
this.ProjectModel.updateOne,
|
||||
{
|
||||
_id: this.project_id,
|
||||
lastUpdated: { $lt: this.lastUpdatedAt },
|
||||
},
|
||||
{
|
||||
lastUpdated: this.lastUpdatedAt,
|
||||
lastUpdatedBy: this.lastUpdatedBy,
|
||||
}
|
||||
)
|
||||
return done()
|
||||
this.lastUpdatedBy
|
||||
)
|
||||
|
||||
sinon.assert.calledWith(
|
||||
this.ProjectModel.updateOne,
|
||||
{
|
||||
_id: this.project_id,
|
||||
lastUpdated: { $lt: this.lastUpdatedAt },
|
||||
},
|
||||
{
|
||||
lastUpdated: this.lastUpdatedAt,
|
||||
lastUpdatedBy: this.lastUpdatedBy,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should set smart fallbacks', function (done) {
|
||||
return this.handler.markAsUpdated(this.project_id, null, null, err => {
|
||||
sinon.assert.calledWithMatch(
|
||||
this.ProjectModel.updateOne,
|
||||
{
|
||||
_id: this.project_id,
|
||||
lastUpdated: { $lt: this.fakeTime },
|
||||
},
|
||||
{
|
||||
lastUpdated: this.fakeTime,
|
||||
lastUpdatedBy: null,
|
||||
}
|
||||
)
|
||||
return done()
|
||||
})
|
||||
it('should set smart fallbacks', async function () {
|
||||
await this.handler.promises.markAsUpdated(this.project_id, null, null)
|
||||
sinon.assert.calledWithMatch(
|
||||
this.ProjectModel.updateOne,
|
||||
{
|
||||
_id: this.project_id,
|
||||
lastUpdated: { $lt: this.fakeTime },
|
||||
},
|
||||
{
|
||||
lastUpdated: this.fakeTime,
|
||||
lastUpdatedBy: null,
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('markAsOpened', function () {
|
||||
it('should send an update to mongo', function (done) {
|
||||
it('should send an update to mongo', async function () {
|
||||
const projectId = 'project_id'
|
||||
return this.handler.markAsOpened(projectId, err => {
|
||||
const args = this.ProjectModel.updateOne.args[0]
|
||||
args[0]._id.should.equal(projectId)
|
||||
const date = args[1].lastOpened + ''
|
||||
const now = Date.now() + ''
|
||||
date.substring(0, 5).should.equal(now.substring(0, 5))
|
||||
return done()
|
||||
})
|
||||
await this.handler.promises.markAsOpened(projectId)
|
||||
const args = this.ProjectModel.updateOne.args[0]
|
||||
args[0]._id.should.equal(projectId)
|
||||
const date = args[1].lastOpened + ''
|
||||
const now = Date.now() + ''
|
||||
date.substring(0, 5).should.equal(now.substring(0, 5))
|
||||
})
|
||||
})
|
||||
|
||||
describe('markAsInactive', function () {
|
||||
it('should send an update to mongo', function (done) {
|
||||
it('should send an update to mongo', async function () {
|
||||
const projectId = 'project_id'
|
||||
return this.handler.markAsInactive(projectId, err => {
|
||||
const args = this.ProjectModel.updateOne.args[0]
|
||||
args[0]._id.should.equal(projectId)
|
||||
args[1].active.should.equal(false)
|
||||
return done()
|
||||
})
|
||||
await this.handler.promises.markAsInactive(projectId)
|
||||
const args = this.ProjectModel.updateOne.args[0]
|
||||
args[0]._id.should.equal(projectId)
|
||||
args[1].active.should.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('markAsActive', function () {
|
||||
it('should send an update to mongo', function (done) {
|
||||
it('should send an update to mongo', async function () {
|
||||
const projectId = 'project_id'
|
||||
return this.handler.markAsActive(projectId, err => {
|
||||
const args = this.ProjectModel.updateOne.args[0]
|
||||
args[0]._id.should.equal(projectId)
|
||||
args[1].active.should.equal(true)
|
||||
return done()
|
||||
})
|
||||
await this.handler.promises.markAsActive(projectId)
|
||||
const args = this.ProjectModel.updateOne.args[0]
|
||||
args[0]._id.should.equal(projectId)
|
||||
args[1].active.should.equal(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user