|
@@ -1,45 +1,45 @@
|
|
|
-/* eslint-disable
|
|
|
|
|
- max-len,
|
|
|
|
|
- no-return-assign,
|
|
|
|
|
-*/
|
|
|
|
|
-// 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 chai = require('chai')
|
|
|
|
|
-chai.should()
|
|
|
|
|
-const { expect } = chai
|
|
|
|
|
|
|
+const { expect } = require('chai')
|
|
|
const sinon = require('sinon')
|
|
const sinon = require('sinon')
|
|
|
-const modulePath = '../../../../app/src/Features/History/HistoryManager'
|
|
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
|
|
|
|
|
|
+const MODULE_PATH = '../../../../app/src/Features/History/HistoryManager'
|
|
|
|
|
+
|
|
|
describe('HistoryManager', function() {
|
|
describe('HistoryManager', function() {
|
|
|
beforeEach(function() {
|
|
beforeEach(function() {
|
|
|
- this.callback = sinon.stub()
|
|
|
|
|
this.user_id = 'user-id-123'
|
|
this.user_id = 'user-id-123'
|
|
|
this.AuthenticationController = {
|
|
this.AuthenticationController = {
|
|
|
getLoggedInUserId: sinon.stub().returns(this.user_id)
|
|
getLoggedInUserId: sinon.stub().returns(this.user_id)
|
|
|
}
|
|
}
|
|
|
- this.HistoryManager = SandboxedModule.require(modulePath, {
|
|
|
|
|
|
|
+ this.request = {
|
|
|
|
|
+ post: sinon.stub()
|
|
|
|
|
+ }
|
|
|
|
|
+ this.settings = {
|
|
|
|
|
+ apis: {
|
|
|
|
|
+ trackchanges: {
|
|
|
|
|
+ enabled: false,
|
|
|
|
|
+ url: 'http://trackchanges.example.com'
|
|
|
|
|
+ },
|
|
|
|
|
+ project_history: {
|
|
|
|
|
+ url: 'http://project_history.example.com'
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.UserGetter = {
|
|
|
|
|
+ promises: {
|
|
|
|
|
+ getUsersByV1Ids: sinon.stub(),
|
|
|
|
|
+ getUsers: sinon.stub()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.HistoryManager = SandboxedModule.require(MODULE_PATH, {
|
|
|
globals: {
|
|
globals: {
|
|
|
console: console
|
|
console: console
|
|
|
},
|
|
},
|
|
|
requires: {
|
|
requires: {
|
|
|
- request: (this.request = sinon.stub()),
|
|
|
|
|
- 'settings-sharelatex': (this.settings = {}),
|
|
|
|
|
- '../User/UserGetter': (this.UserGetter = {})
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- return (this.settings.apis = {
|
|
|
|
|
- trackchanges: {
|
|
|
|
|
- enabled: false,
|
|
|
|
|
- url: 'http://trackchanges.example.com'
|
|
|
|
|
- },
|
|
|
|
|
- project_history: {
|
|
|
|
|
- url: 'http://project_history.example.com'
|
|
|
|
|
|
|
+ 'request-promise-native': this.request,
|
|
|
|
|
+ 'settings-sharelatex': this.settings,
|
|
|
|
|
+ '../User/UserGetter': this.UserGetter
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
@@ -47,101 +47,53 @@ describe('HistoryManager', function() {
|
|
|
describe('initializeProject', function() {
|
|
describe('initializeProject', function() {
|
|
|
describe('with project history enabled', function() {
|
|
describe('with project history enabled', function() {
|
|
|
beforeEach(function() {
|
|
beforeEach(function() {
|
|
|
- return (this.settings.apis.project_history.initializeHistoryForNewProjects = true)
|
|
|
|
|
|
|
+ this.settings.apis.project_history.initializeHistoryForNewProjects = true
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('project history returns a successful response', function() {
|
|
describe('project history returns a successful response', function() {
|
|
|
- beforeEach(function() {
|
|
|
|
|
|
|
+ beforeEach(async function() {
|
|
|
this.overleaf_id = 1234
|
|
this.overleaf_id = 1234
|
|
|
- this.res = { statusCode: 200 }
|
|
|
|
|
- this.body = JSON.stringify({ project: { id: this.overleaf_id } })
|
|
|
|
|
- this.request.post = sinon
|
|
|
|
|
- .stub()
|
|
|
|
|
- .callsArgWith(1, null, this.res, this.body)
|
|
|
|
|
-
|
|
|
|
|
- return this.HistoryManager.initializeProject(this.callback)
|
|
|
|
|
|
|
+ this.request.post.resolves(
|
|
|
|
|
+ JSON.stringify({ project: { id: this.overleaf_id } })
|
|
|
|
|
+ )
|
|
|
|
|
+ this.result = await this.HistoryManager.promises.initializeProject()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should call the project history api', function() {
|
|
it('should call the project history api', function() {
|
|
|
- return this.request.post
|
|
|
|
|
|
|
+ this.request.post
|
|
|
.calledWith({
|
|
.calledWith({
|
|
|
url: `${this.settings.apis.project_history.url}/project`
|
|
url: `${this.settings.apis.project_history.url}/project`
|
|
|
})
|
|
})
|
|
|
.should.equal(true)
|
|
.should.equal(true)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should return the callback with the overleaf id', function() {
|
|
|
|
|
- return this.callback
|
|
|
|
|
- .calledWithExactly(null, { overleaf_id: this.overleaf_id })
|
|
|
|
|
- .should.equal(true)
|
|
|
|
|
|
|
+ it('should return the overleaf id', function() {
|
|
|
|
|
+ expect(this.result).to.deep.equal({ overleaf_id: this.overleaf_id })
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('project history returns a response without the project id', function() {
|
|
describe('project history returns a response without the project id', function() {
|
|
|
- beforeEach(function() {
|
|
|
|
|
- this.res = { statusCode: 200 }
|
|
|
|
|
- this.body = JSON.stringify({ project: {} })
|
|
|
|
|
- this.request.post = sinon
|
|
|
|
|
- .stub()
|
|
|
|
|
- .callsArgWith(1, null, this.res, this.body)
|
|
|
|
|
-
|
|
|
|
|
- return this.HistoryManager.initializeProject(this.callback)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- it('should return the callback with an error', function() {
|
|
|
|
|
- return this.callback
|
|
|
|
|
- .calledWith(
|
|
|
|
|
- sinon.match.has(
|
|
|
|
|
- 'message',
|
|
|
|
|
- 'project-history did not provide an id'
|
|
|
|
|
- )
|
|
|
|
|
- )
|
|
|
|
|
- .should.equal(true)
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- describe('project history returns a unsuccessful response', function() {
|
|
|
|
|
- beforeEach(function() {
|
|
|
|
|
- this.res = { statusCode: 404 }
|
|
|
|
|
- this.request.post = sinon.stub().callsArgWith(1, null, this.res)
|
|
|
|
|
-
|
|
|
|
|
- return this.HistoryManager.initializeProject(this.callback)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- it('should return the callback with an error', function() {
|
|
|
|
|
- return this.callback
|
|
|
|
|
- .calledWith(
|
|
|
|
|
- sinon.match.has(
|
|
|
|
|
- 'message',
|
|
|
|
|
- 'project-history returned a non-success status code: 404'
|
|
|
|
|
- )
|
|
|
|
|
- )
|
|
|
|
|
- .should.equal(true)
|
|
|
|
|
|
|
+ it('should throw an error', async function() {
|
|
|
|
|
+ this.request.post.resolves(JSON.stringify({ project: {} }))
|
|
|
|
|
+ await expect(this.HistoryManager.promises.initializeProject()).to.be
|
|
|
|
|
+ .rejected
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('project history errors', function() {
|
|
describe('project history errors', function() {
|
|
|
- beforeEach(function() {
|
|
|
|
|
- this.error = sinon.stub()
|
|
|
|
|
- this.request.post = sinon.stub().callsArgWith(1, this.error)
|
|
|
|
|
-
|
|
|
|
|
- return this.HistoryManager.initializeProject(this.callback)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- it('should return the callback with the error', function() {
|
|
|
|
|
- return this.callback.calledWithExactly(this.error).should.equal(true)
|
|
|
|
|
|
|
+ it('should propagate the error', async function() {
|
|
|
|
|
+ this.request.post.rejects(new Error('problem connecting'))
|
|
|
|
|
+ await expect(this.HistoryManager.promises.initializeProject()).to.be
|
|
|
|
|
+ .rejected
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('with project history disabled', function() {
|
|
describe('with project history disabled', function() {
|
|
|
- beforeEach(function() {
|
|
|
|
|
|
|
+ it('should return without errors', async function() {
|
|
|
this.settings.apis.project_history.initializeHistoryForNewProjects = false
|
|
this.settings.apis.project_history.initializeHistoryForNewProjects = false
|
|
|
- return this.HistoryManager.initializeProject(this.callback)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- it('should return the callback', function() {
|
|
|
|
|
- return this.callback.calledWithExactly().should.equal(true)
|
|
|
|
|
|
|
+ await expect(this.HistoryManager.promises.initializeProject()).to.be
|
|
|
|
|
+ .fulfilled
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
@@ -173,160 +125,120 @@ describe('HistoryManager', function() {
|
|
|
last_name: 'Doe',
|
|
last_name: 'Doe',
|
|
|
email: 'john@example.com'
|
|
email: 'john@example.com'
|
|
|
}
|
|
}
|
|
|
- this.UserGetter.getUsersByV1Ids = sinon.stub().yields(null, [this.user1])
|
|
|
|
|
- return (this.UserGetter.getUsers = sinon
|
|
|
|
|
- .stub()
|
|
|
|
|
- .yields(null, [this.user1, this.user2]))
|
|
|
|
|
|
|
+ this.UserGetter.promises.getUsersByV1Ids.resolves([this.user1])
|
|
|
|
|
+ this.UserGetter.promises.getUsers.resolves([this.user1, this.user2])
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('with a diff', function() {
|
|
describe('with a diff', function() {
|
|
|
- it('should turn user_ids into user objects', function(done) {
|
|
|
|
|
- return this.HistoryManager.injectUserDetails(
|
|
|
|
|
- {
|
|
|
|
|
- diff: [
|
|
|
|
|
- {
|
|
|
|
|
- i: 'foo',
|
|
|
|
|
- meta: {
|
|
|
|
|
- users: [this.user_id1]
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- i: 'bar',
|
|
|
|
|
- meta: {
|
|
|
|
|
- users: [this.user_id2]
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ it('should turn user_ids into user objects', async function() {
|
|
|
|
|
+ const diff = await this.HistoryManager.promises.injectUserDetails({
|
|
|
|
|
+ diff: [
|
|
|
|
|
+ {
|
|
|
|
|
+ i: 'foo',
|
|
|
|
|
+ meta: {
|
|
|
|
|
+ users: [this.user_id1]
|
|
|
}
|
|
}
|
|
|
- ]
|
|
|
|
|
- },
|
|
|
|
|
- (error, diff) => {
|
|
|
|
|
- expect(error).to.be.null
|
|
|
|
|
- expect(diff.diff[0].meta.users).to.deep.equal([this.user1_view])
|
|
|
|
|
- expect(diff.diff[1].meta.users).to.deep.equal([this.user2_view])
|
|
|
|
|
- return done()
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ i: 'bar',
|
|
|
|
|
+ meta: {
|
|
|
|
|
+ users: [this.user_id2]
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ ]
|
|
|
|
|
+ })
|
|
|
|
|
+ expect(diff.diff[0].meta.users).to.deep.equal([this.user1_view])
|
|
|
|
|
+ expect(diff.diff[1].meta.users).to.deep.equal([this.user2_view])
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should handle v1 user ids', function(done) {
|
|
|
|
|
- return this.HistoryManager.injectUserDetails(
|
|
|
|
|
- {
|
|
|
|
|
- diff: [
|
|
|
|
|
- {
|
|
|
|
|
- i: 'foo',
|
|
|
|
|
- meta: {
|
|
|
|
|
- users: [5011]
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- i: 'bar',
|
|
|
|
|
- meta: {
|
|
|
|
|
- users: [this.user_id2]
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ it('should handle v1 user ids', async function() {
|
|
|
|
|
+ const diff = await this.HistoryManager.promises.injectUserDetails({
|
|
|
|
|
+ diff: [
|
|
|
|
|
+ {
|
|
|
|
|
+ i: 'foo',
|
|
|
|
|
+ meta: {
|
|
|
|
|
+ users: [5011]
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ i: 'bar',
|
|
|
|
|
+ meta: {
|
|
|
|
|
+ users: [this.user_id2]
|
|
|
}
|
|
}
|
|
|
- ]
|
|
|
|
|
- },
|
|
|
|
|
- (error, diff) => {
|
|
|
|
|
- expect(error).to.be.null
|
|
|
|
|
- expect(diff.diff[0].meta.users).to.deep.equal([this.user1_view])
|
|
|
|
|
- expect(diff.diff[1].meta.users).to.deep.equal([this.user2_view])
|
|
|
|
|
- return done()
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ ]
|
|
|
|
|
+ })
|
|
|
|
|
+ expect(diff.diff[0].meta.users).to.deep.equal([this.user1_view])
|
|
|
|
|
+ expect(diff.diff[1].meta.users).to.deep.equal([this.user2_view])
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should leave user objects', function(done) {
|
|
|
|
|
- return this.HistoryManager.injectUserDetails(
|
|
|
|
|
- {
|
|
|
|
|
- diff: [
|
|
|
|
|
- {
|
|
|
|
|
- i: 'foo',
|
|
|
|
|
- meta: {
|
|
|
|
|
- users: [this.user1_view]
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- i: 'bar',
|
|
|
|
|
- meta: {
|
|
|
|
|
- users: [this.user_id2]
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ it('should leave user objects', async function() {
|
|
|
|
|
+ const diff = await this.HistoryManager.promises.injectUserDetails({
|
|
|
|
|
+ diff: [
|
|
|
|
|
+ {
|
|
|
|
|
+ i: 'foo',
|
|
|
|
|
+ meta: {
|
|
|
|
|
+ users: [this.user1_view]
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ i: 'bar',
|
|
|
|
|
+ meta: {
|
|
|
|
|
+ users: [this.user_id2]
|
|
|
}
|
|
}
|
|
|
- ]
|
|
|
|
|
- },
|
|
|
|
|
- (error, diff) => {
|
|
|
|
|
- expect(error).to.be.null
|
|
|
|
|
- expect(diff.diff[0].meta.users).to.deep.equal([this.user1_view])
|
|
|
|
|
- expect(diff.diff[1].meta.users).to.deep.equal([this.user2_view])
|
|
|
|
|
- return done()
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ ]
|
|
|
|
|
+ })
|
|
|
|
|
+ expect(diff.diff[0].meta.users).to.deep.equal([this.user1_view])
|
|
|
|
|
+ expect(diff.diff[1].meta.users).to.deep.equal([this.user2_view])
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('with a list of updates', function() {
|
|
describe('with a list of updates', function() {
|
|
|
- it('should turn user_ids into user objects', function(done) {
|
|
|
|
|
- return this.HistoryManager.injectUserDetails(
|
|
|
|
|
- {
|
|
|
|
|
- updates: [
|
|
|
|
|
- {
|
|
|
|
|
- fromV: 5,
|
|
|
|
|
- toV: 8,
|
|
|
|
|
- meta: {
|
|
|
|
|
- users: [this.user_id1]
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- fromV: 4,
|
|
|
|
|
- toV: 5,
|
|
|
|
|
- meta: {
|
|
|
|
|
- users: [this.user_id2]
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ it('should turn user_ids into user objects', async function() {
|
|
|
|
|
+ const updates = await this.HistoryManager.promises.injectUserDetails({
|
|
|
|
|
+ updates: [
|
|
|
|
|
+ {
|
|
|
|
|
+ fromV: 5,
|
|
|
|
|
+ toV: 8,
|
|
|
|
|
+ meta: {
|
|
|
|
|
+ users: [this.user_id1]
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ fromV: 4,
|
|
|
|
|
+ toV: 5,
|
|
|
|
|
+ meta: {
|
|
|
|
|
+ users: [this.user_id2]
|
|
|
}
|
|
}
|
|
|
- ]
|
|
|
|
|
- },
|
|
|
|
|
- (error, updates) => {
|
|
|
|
|
- expect(error).to.be.null
|
|
|
|
|
- expect(updates.updates[0].meta.users).to.deep.equal([
|
|
|
|
|
- this.user1_view
|
|
|
|
|
- ])
|
|
|
|
|
- expect(updates.updates[1].meta.users).to.deep.equal([
|
|
|
|
|
- this.user2_view
|
|
|
|
|
- ])
|
|
|
|
|
- return done()
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ ]
|
|
|
|
|
+ })
|
|
|
|
|
+ expect(updates.updates[0].meta.users).to.deep.equal([this.user1_view])
|
|
|
|
|
+ expect(updates.updates[1].meta.users).to.deep.equal([this.user2_view])
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('should leave user objects', function(done) {
|
|
|
|
|
- return this.HistoryManager.injectUserDetails(
|
|
|
|
|
- {
|
|
|
|
|
- updates: [
|
|
|
|
|
- {
|
|
|
|
|
- fromV: 5,
|
|
|
|
|
- toV: 8,
|
|
|
|
|
- meta: {
|
|
|
|
|
- users: [this.user1_view]
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- fromV: 4,
|
|
|
|
|
- toV: 5,
|
|
|
|
|
- meta: {
|
|
|
|
|
- users: [this.user_id2]
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ it('should leave user objects', async function() {
|
|
|
|
|
+ const updates = await this.HistoryManager.promises.injectUserDetails({
|
|
|
|
|
+ updates: [
|
|
|
|
|
+ {
|
|
|
|
|
+ fromV: 5,
|
|
|
|
|
+ toV: 8,
|
|
|
|
|
+ meta: {
|
|
|
|
|
+ users: [this.user1_view]
|
|
|
}
|
|
}
|
|
|
- ]
|
|
|
|
|
- },
|
|
|
|
|
- (error, updates) => {
|
|
|
|
|
- expect(error).to.be.null
|
|
|
|
|
- expect(updates.updates[0].meta.users).to.deep.equal([
|
|
|
|
|
- this.user1_view
|
|
|
|
|
- ])
|
|
|
|
|
- expect(updates.updates[1].meta.users).to.deep.equal([
|
|
|
|
|
- this.user2_view
|
|
|
|
|
- ])
|
|
|
|
|
- return done()
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ fromV: 4,
|
|
|
|
|
+ toV: 5,
|
|
|
|
|
+ meta: {
|
|
|
|
|
+ users: [this.user_id2]
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ ]
|
|
|
|
|
+ })
|
|
|
|
|
+ expect(updates.updates[0].meta.users).to.deep.equal([this.user1_view])
|
|
|
|
|
+ expect(updates.updates[1].meta.users).to.deep.equal([this.user2_view])
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|