2019-05-29 05:21:06 -04:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
2020-12-15 05:23:54 -05:00
|
|
|
node/handle-callback-err,
|
2019-05-29 05:21:06 -04:00
|
|
|
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'
|
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('ProjectUpdateHandler', function () {
|
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.fakeTime = new Date()
|
2019-11-18 09:37:05 -05:00
|
|
|
this.clock = sinon.useFakeTimers(this.fakeTime.getTime())
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
let Project
|
|
|
|
this.ProjectModel = Project = class Project {}
|
2020-11-03 04:19:05 -05:00
|
|
|
this.ProjectModel.updateOne = sinon.stub().callsArg(3)
|
2019-05-29 05:21:06 -04:00
|
|
|
return (this.handler = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
2021-03-31 08:20:55 -04:00
|
|
|
'../../models/Project': { Project: this.ProjectModel }
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('marking a project as recently updated', function () {
|
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.project_id = 'project_id'
|
|
|
|
this.lastUpdatedAt = 987654321
|
|
|
|
return (this.lastUpdatedBy = 'fake-last-updater-id')
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should send an update to mongo', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.handler.markAsUpdated(
|
|
|
|
this.project_id,
|
|
|
|
this.lastUpdatedAt,
|
|
|
|
this.lastUpdatedBy,
|
|
|
|
err => {
|
|
|
|
sinon.assert.calledWith(
|
2020-11-03 04:19:05 -05:00
|
|
|
this.ProjectModel.updateOne,
|
2019-05-29 05:21:06 -04:00
|
|
|
{
|
|
|
|
_id: this.project_id,
|
|
|
|
lastUpdated: { $lt: this.lastUpdatedAt }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
lastUpdated: this.lastUpdatedAt,
|
|
|
|
lastUpdatedBy: this.lastUpdatedBy
|
|
|
|
}
|
|
|
|
)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should set smart fallbacks', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.handler.markAsUpdated(this.project_id, null, null, err => {
|
|
|
|
sinon.assert.calledWithMatch(
|
2020-11-03 04:19:05 -05:00
|
|
|
this.ProjectModel.updateOne,
|
2019-05-29 05:21:06 -04:00
|
|
|
{
|
|
|
|
_id: this.project_id,
|
|
|
|
lastUpdated: { $lt: this.fakeTime }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
lastUpdated: this.fakeTime,
|
|
|
|
lastUpdatedBy: null
|
|
|
|
}
|
|
|
|
)
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('markAsOpened', function () {
|
|
|
|
it('should send an update to mongo', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
const project_id = 'project_id'
|
|
|
|
return this.handler.markAsOpened(project_id, err => {
|
2020-11-03 04:19:05 -05:00
|
|
|
const args = this.ProjectModel.updateOne.args[0]
|
2019-05-29 05:21:06 -04:00
|
|
|
args[0]._id.should.equal(project_id)
|
|
|
|
const date = args[1].lastOpened + ''
|
|
|
|
const now = Date.now() + ''
|
|
|
|
date.substring(0, 5).should.equal(now.substring(0, 5))
|
|
|
|
return done()
|
|
|
|
})
|
2019-08-07 10:04:04 -04:00
|
|
|
})
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('markAsInactive', function () {
|
|
|
|
it('should send an update to mongo', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
const project_id = 'project_id'
|
|
|
|
return this.handler.markAsInactive(project_id, err => {
|
2020-11-03 04:19:05 -05:00
|
|
|
const args = this.ProjectModel.updateOne.args[0]
|
2019-05-29 05:21:06 -04:00
|
|
|
args[0]._id.should.equal(project_id)
|
|
|
|
args[1].active.should.equal(false)
|
|
|
|
return done()
|
|
|
|
})
|
2019-08-07 10:04:04 -04:00
|
|
|
})
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('markAsActive', function () {
|
|
|
|
it('should send an update to mongo', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
const project_id = 'project_id'
|
|
|
|
return this.handler.markAsActive(project_id, err => {
|
2020-11-03 04:19:05 -05:00
|
|
|
const args = this.ProjectModel.updateOne.args[0]
|
2019-05-29 05:21:06 -04:00
|
|
|
args[0]._id.should.equal(project_id)
|
|
|
|
args[1].active.should.equal(true)
|
|
|
|
return done()
|
|
|
|
})
|
2019-08-07 10:04:04 -04:00
|
|
|
})
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|