2020-02-17 12:35:01 -05:00
|
|
|
/* eslint-disable
|
|
|
|
no-return-assign,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-17 12:34:50 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-02-17 12:35:16 -05:00
|
|
|
const sinon = require('sinon')
|
2021-03-23 15:08:32 -04:00
|
|
|
const { expect } = require('chai')
|
2020-02-17 12:35:16 -05:00
|
|
|
const modulePath = '../../../../app/js/UpdateTrimmer.js'
|
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const tk = require('timekeeper')
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
describe('UpdateTrimmer', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
this.now = new Date()
|
|
|
|
tk.freeze(this.now)
|
|
|
|
|
|
|
|
this.UpdateTrimmer = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
|
|
|
'./WebApiManager': (this.WebApiManager = {}),
|
2021-07-13 07:04:43 -04:00
|
|
|
'./MongoManager': (this.MongoManager = {}),
|
|
|
|
},
|
2020-02-17 12:35:16 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
this.callback = sinon.stub()
|
|
|
|
return (this.project_id = 'mock-project-id')
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
afterEach(function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
return tk.reset()
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
return describe('shouldTrimUpdates', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
this.metadata = {}
|
|
|
|
this.details = { features: {} }
|
|
|
|
this.MongoManager.getProjectMetaData = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(1, null, this.metadata)
|
|
|
|
this.MongoManager.setProjectMetaData = sinon.stub().callsArgWith(2)
|
|
|
|
this.MongoManager.upgradeHistory = sinon.stub().callsArgWith(1)
|
|
|
|
return (this.WebApiManager.getProjectDetails = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(1, null, this.details))
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
describe('with preserveHistory set in the project meta data', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
this.metadata.preserveHistory = true
|
|
|
|
return this.UpdateTrimmer.shouldTrimUpdates(
|
|
|
|
this.project_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
it('should look up the meta data', function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
return this.MongoManager.getProjectMetaData
|
|
|
|
.calledWith(this.project_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
it('should not look up the project details', function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
return this.WebApiManager.getProjectDetails.called.should.equal(false)
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
return it('should return false', function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
return this.callback.calledWith(null, false).should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
describe('without preserveHistory set in the project meta data', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
return (this.metadata.preserveHistory = false)
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
describe('when the project has the versioning feature', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
this.details.features.versioning = true
|
|
|
|
return this.UpdateTrimmer.shouldTrimUpdates(
|
|
|
|
this.project_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
it('should look up the meta data', function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
return this.MongoManager.getProjectMetaData
|
|
|
|
.calledWith(this.project_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
it('should look up the project details', function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
return this.WebApiManager.getProjectDetails
|
|
|
|
.calledWith(this.project_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
it('should insert preserveHistory into the metadata', function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
return this.MongoManager.setProjectMetaData
|
|
|
|
.calledWith(this.project_id, { preserveHistory: true })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
it('should upgrade any existing history', function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
return this.MongoManager.upgradeHistory
|
|
|
|
.calledWith(this.project_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
return it('should return false', function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
return this.callback.calledWith(null, false).should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
return describe('when the project does not have the versioning feature', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
this.details.features.versioning = false
|
|
|
|
return this.UpdateTrimmer.shouldTrimUpdates(
|
|
|
|
this.project_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
return it('should return true', function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
return this.callback.calledWith(null, true).should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
return describe('without any meta data', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
return (this.MongoManager.getProjectMetaData = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(1, null, null))
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
describe('when the project has the versioning feature', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
this.details.features.versioning = true
|
|
|
|
return this.UpdateTrimmer.shouldTrimUpdates(
|
|
|
|
this.project_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
it('should insert preserveHistory into the metadata', function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
return this.MongoManager.setProjectMetaData
|
|
|
|
.calledWith(this.project_id, { preserveHistory: true })
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
it('should upgrade any existing history', function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
return this.MongoManager.upgradeHistory
|
|
|
|
.calledWith(this.project_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
return it('should return false', function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
return this.callback.calledWith(null, false).should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
return describe('when the project does not have the versioning feature', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
this.details.features.versioning = false
|
|
|
|
return this.UpdateTrimmer.shouldTrimUpdates(
|
|
|
|
this.project_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
return it('should return true', function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
return this.callback.calledWith(null, true).should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|