overleaf/services/track-changes/test/unit/js/RestoreManager/RestoreManagerTests.js

65 lines
2 KiB
JavaScript
Raw Normal View History

/* eslint-disable
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 { expect } = require('chai')
const modulePath = '../../../../app/js/RestoreManager.js'
const SandboxedModule = require('sandboxed-module')
2014-03-10 16:58:26 +00:00
2020-06-04 08:24:21 +00:00
describe('RestoreManager', function () {
beforeEach(function () {
this.RestoreManager = SandboxedModule.require(modulePath, {
requires: {
'./DocumentUpdaterManager': (this.DocumentUpdaterManager = {}),
2021-07-13 11:04:43 +00:00
'./DiffManager': (this.DiffManager = {}),
},
})
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 16:58:26 +00:00
2020-06-04 08:24:21 +00:00
return describe('restoreToBeforeVersion', function () {
beforeEach(function () {
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 16:58:26 +00:00
2020-06-04 08:24:21 +00:00
it('should get the content before the requested version', function () {
return this.DiffManager.getDocumentBeforeVersion
.calledWith(this.project_id, this.doc_id, this.version)
.should.equal(true)
})
2014-03-10 16:58:26 +00:00
2020-06-04 08:24:21 +00:00
it('should set the document in the document updater', function () {
return this.DocumentUpdaterManager.setDocument
.calledWith(this.project_id, this.doc_id, this.content, this.user_id)
.should.equal(true)
})
2014-03-10 16:58:26 +00:00
2020-06-04 08:24:21 +00:00
return it('should call the callback', function () {
return this.callback.called.should.equal(true)
})
})
})