2014-02-12 05:23:40 -05:00
|
|
|
sinon = require('sinon')
|
|
|
|
chai = require('chai').should()
|
|
|
|
modulePath = "../../../../app/js/Features/Project/ProjectUpdateHandler.js"
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
|
2015-08-13 17:40:28 -04:00
|
|
|
describe 'ProjectUpdateHandler', ->
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
|
2019-05-02 10:03:48 -04:00
|
|
|
before ->
|
|
|
|
@fakeTime = new Date()
|
|
|
|
@clock = sinon.useFakeTimers(@fakeTime.getTime())
|
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
beforeEach ->
|
|
|
|
@ProjectModel = class Project
|
|
|
|
@ProjectModel.update = sinon.stub().callsArg(3)
|
|
|
|
@handler = SandboxedModule.require modulePath, requires:
|
|
|
|
'../../models/Project':{Project:@ProjectModel}
|
2017-05-22 10:33:52 -04:00
|
|
|
'logger-sharelatex' : { log: sinon.stub() }
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2019-05-02 10:03:48 -04:00
|
|
|
after ->
|
|
|
|
@clock.restore()
|
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
describe 'marking a project as recently updated', ->
|
2019-05-02 10:03:48 -04:00
|
|
|
beforeEach ->
|
|
|
|
@project_id = "project_id"
|
|
|
|
@lastUpdatedAt = 987654321
|
|
|
|
@lastUpdatedBy = 'fake-last-updater-id'
|
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
it 'should send an update to mongo', (done)->
|
2019-05-02 10:03:48 -04:00
|
|
|
@handler.markAsUpdated @project_id, @lastUpdatedAt, @lastUpdatedBy, (err) =>
|
|
|
|
sinon.assert.calledWith(
|
|
|
|
@ProjectModel.update,
|
|
|
|
{
|
|
|
|
_id: @project_id,
|
|
|
|
lastUpdated: { $lt: @lastUpdatedAt }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
lastUpdated: @lastUpdatedAt,
|
|
|
|
lastUpdatedBy: @lastUpdatedBy
|
|
|
|
}
|
|
|
|
)
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should set smart fallbacks', (done)->
|
|
|
|
@handler.markAsUpdated @project_id, null, null, (err) =>
|
|
|
|
sinon.assert.calledWithMatch(
|
|
|
|
@ProjectModel.update,
|
|
|
|
{
|
|
|
|
_id: @project_id,
|
|
|
|
lastUpdated: { $lt: @fakeTime }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
lastUpdated: @fakeTime
|
|
|
|
lastUpdatedBy: null
|
|
|
|
}
|
|
|
|
)
|
2014-02-12 05:23:40 -05:00
|
|
|
done()
|
2015-08-13 17:40:28 -04:00
|
|
|
|
|
|
|
describe "markAsOpened", ->
|
|
|
|
|
|
|
|
it 'should send an update to mongo', (done)->
|
|
|
|
project_id = "project_id"
|
|
|
|
@handler.markAsOpened project_id, (err)=>
|
|
|
|
args = @ProjectModel.update.args[0]
|
|
|
|
args[0]._id.should.equal project_id
|
|
|
|
date = args[1].lastOpened+""
|
|
|
|
now = Date.now()+""
|
|
|
|
date.substring(0,5).should.equal now.substring(0,5)
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "markAsInactive", ->
|
|
|
|
|
|
|
|
it 'should send an update to mongo', (done)->
|
|
|
|
project_id = "project_id"
|
|
|
|
@handler.markAsInactive project_id, (err)=>
|
|
|
|
args = @ProjectModel.update.args[0]
|
|
|
|
args[0]._id.should.equal project_id
|
2015-08-19 06:54:30 -04:00
|
|
|
args[1].active.should.equal false
|
2015-08-13 17:40:28 -04:00
|
|
|
done()
|
|
|
|
|
|
|
|
describe "markAsActive", ->
|
|
|
|
it 'should send an update to mongo', (done)->
|
|
|
|
project_id = "project_id"
|
|
|
|
@handler.markAsActive project_id, (err)=>
|
|
|
|
args = @ProjectModel.update.args[0]
|
|
|
|
args[0]._id.should.equal project_id
|
2015-08-19 06:54:30 -04:00
|
|
|
args[1].active.should.equal true
|
2015-08-13 17:40:28 -04:00
|
|
|
done()
|
|
|
|
|
|
|
|
|