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/RestoreManager.js'
|
|
|
|
const SandboxedModule = require('sandboxed-module')
|
2014-03-10 12:58:26 -04:00
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
describe('RestoreManager', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
this.RestoreManager = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
|
|
|
'./DocumentUpdaterManager': (this.DocumentUpdaterManager = {}),
|
2021-07-13 07:04:43 -04:00
|
|
|
'./DiffManager': (this.DiffManager = {}),
|
|
|
|
},
|
2020-02-17 12:35:16 -05:00
|
|
|
})
|
|
|
|
this.callback = sinon.stub()
|
|
|
|
this.project_id = 'mock-project-id'
|
|
|
|
this.doc_id = 'mock-doc-id'
|
|
|
|
this.user_id = 'mock-user-id'
|
|
|
|
return (this.version = 42)
|
|
|
|
})
|
2014-03-10 12:58:26 -04:00
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
return describe('restoreToBeforeVersion', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
this.content = 'mock content'
|
|
|
|
this.DocumentUpdaterManager.setDocument = sinon.stub().callsArg(4)
|
|
|
|
this.DiffManager.getDocumentBeforeVersion = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(3, null, this.content)
|
|
|
|
return this.RestoreManager.restoreToBeforeVersion(
|
|
|
|
this.project_id,
|
|
|
|
this.doc_id,
|
|
|
|
this.version,
|
|
|
|
this.user_id,
|
|
|
|
this.callback
|
|
|
|
)
|
|
|
|
})
|
2014-03-10 12:58:26 -04:00
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
it('should get the content before the requested version', function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
return this.DiffManager.getDocumentBeforeVersion
|
|
|
|
.calledWith(this.project_id, this.doc_id, this.version)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
2014-03-10 12:58:26 -04:00
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
it('should set the document in the document updater', function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
return this.DocumentUpdaterManager.setDocument
|
|
|
|
.calledWith(this.project_id, this.doc_id, this.content, this.user_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
2014-03-10 12:58:26 -04:00
|
|
|
|
2020-06-04 04:24:21 -04:00
|
|
|
return it('should call the callback', function () {
|
2020-02-17 12:35:16 -05:00
|
|
|
return this.callback.called.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|