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

71 lines
2.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 chai = require('chai')
const should = chai.should()
const { expect } = chai
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 () {
this.RestoreManager = SandboxedModule.require(modulePath, {
requires: {
'logger-sharelatex': (this.logger = {
log: sinon.stub(),
error: sinon.stub()
}),
'./DocumentUpdaterManager': (this.DocumentUpdaterManager = {}),
'./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 12:58:26 -04:00
2020-06-04 04:24:21 -04: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 12:58:26 -04:00
2020-06-04 04:24:21 -04: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 12:58:26 -04:00
2020-06-04 04:24:21 -04: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 12:58:26 -04:00
2020-06-04 04:24:21 -04:00
return it('should call the callback', function () {
return this.callback.called.should.equal(true)
})
})
})