|
|
@@ -27,17 +27,6 @@ describe('HistoryStoreManager', function () {
|
|
|
},
|
|
|
},
|
|
|
}
|
|
|
- this.latestChunkRequestArgs = sinon.match({
|
|
|
- method: 'GET',
|
|
|
- url: `${this.settings.overleaf.history.host}/projects/${this.historyId}/latest/history`,
|
|
|
- json: true,
|
|
|
- auth: {
|
|
|
- user: this.settings.overleaf.history.user,
|
|
|
- pass: this.settings.overleaf.history.pass,
|
|
|
- sendImmediately: true,
|
|
|
- },
|
|
|
- })
|
|
|
-
|
|
|
this.callback = sinon.stub()
|
|
|
|
|
|
this.LocalFileWriter = {
|
|
|
@@ -53,12 +42,11 @@ describe('HistoryStoreManager', function () {
|
|
|
|
|
|
this.FetchUtils = {
|
|
|
fetchStream: sinon.stub(),
|
|
|
+ fetchString: sinon.stub(),
|
|
|
fetchNothing: sinon.stub().resolves(),
|
|
|
RequestFailedError,
|
|
|
}
|
|
|
|
|
|
- this.request = sinon.stub()
|
|
|
-
|
|
|
this.logger = {
|
|
|
debug: sinon.stub(),
|
|
|
warn: sinon.stub(),
|
|
|
@@ -66,7 +54,6 @@ describe('HistoryStoreManager', function () {
|
|
|
|
|
|
this.HistoryStoreManager = await esmock(MODULE_PATH, {
|
|
|
'@overleaf/fetch-utils': this.FetchUtils,
|
|
|
- request: this.request,
|
|
|
'@overleaf/settings': this.settings,
|
|
|
'../../../../app/js/LocalFileWriter.js': this.LocalFileWriter,
|
|
|
'../../../../app/js/WebApiManager.js': this.WebApiManager,
|
|
|
@@ -77,7 +64,7 @@ describe('HistoryStoreManager', function () {
|
|
|
|
|
|
describe('getMostRecentChunk', function () {
|
|
|
describe('successfully', function () {
|
|
|
- beforeEach(function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
this.chunk = {
|
|
|
chunk: {
|
|
|
startVersion: 0,
|
|
|
@@ -89,13 +76,27 @@ describe('HistoryStoreManager', function () {
|
|
|
},
|
|
|
},
|
|
|
}
|
|
|
- this.request
|
|
|
- .withArgs(this.latestChunkRequestArgs)
|
|
|
- .yields(null, { statusCode: 200 }, this.chunk)
|
|
|
+ this.FetchUtils.fetchString.resolves(JSON.stringify(this.chunk))
|
|
|
this.HistoryStoreManager.getMostRecentChunk(
|
|
|
this.projectId,
|
|
|
this.historyId,
|
|
|
- this.callback
|
|
|
+ (...args) => {
|
|
|
+ this.callback(...args)
|
|
|
+ done()
|
|
|
+ }
|
|
|
+ )
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should request latest history from the overleaf history service', function () {
|
|
|
+ expect(this.FetchUtils.fetchString).to.have.been.calledWithMatch(
|
|
|
+ `${this.settings.overleaf.history.host}/projects/${this.historyId}/latest/history`,
|
|
|
+ {
|
|
|
+ method: 'GET',
|
|
|
+ basicAuth: {
|
|
|
+ user: this.settings.overleaf.history.user,
|
|
|
+ password: this.settings.overleaf.history.pass,
|
|
|
+ },
|
|
|
+ }
|
|
|
)
|
|
|
})
|
|
|
|
|
|
@@ -107,7 +108,7 @@ describe('HistoryStoreManager', function () {
|
|
|
|
|
|
describe('getMostRecentVersion', function () {
|
|
|
describe('successfully', function () {
|
|
|
- beforeEach(function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
this.chunk = {
|
|
|
chunk: {
|
|
|
startVersion: 5,
|
|
|
@@ -123,13 +124,14 @@ describe('HistoryStoreManager', function () {
|
|
|
},
|
|
|
}
|
|
|
|
|
|
- this.request
|
|
|
- .withArgs(this.latestChunkRequestArgs)
|
|
|
- .yields(null, { statusCode: 200 }, this.chunk)
|
|
|
+ this.FetchUtils.fetchString.resolves(JSON.stringify(this.chunk))
|
|
|
this.HistoryStoreManager.getMostRecentVersion(
|
|
|
this.projectId,
|
|
|
this.historyId,
|
|
|
- this.callback
|
|
|
+ (...args) => {
|
|
|
+ this.callback(...args)
|
|
|
+ done()
|
|
|
+ }
|
|
|
)
|
|
|
})
|
|
|
|
|
|
@@ -141,10 +143,23 @@ describe('HistoryStoreManager', function () {
|
|
|
{ v2Authors: ['5678'], timestamp: '2017-10-17T10:44:40.227Z' }
|
|
|
)
|
|
|
})
|
|
|
+
|
|
|
+ it('should request latest history from the overleaf history service', function () {
|
|
|
+ expect(this.FetchUtils.fetchString).to.have.been.calledWithMatch(
|
|
|
+ `${this.settings.overleaf.history.host}/projects/${this.historyId}/latest/history`,
|
|
|
+ {
|
|
|
+ method: 'GET',
|
|
|
+ basicAuth: {
|
|
|
+ user: this.settings.overleaf.history.user,
|
|
|
+ password: this.settings.overleaf.history.pass,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ )
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
describe('out of order doc ops', function () {
|
|
|
- beforeEach(function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
this.chunk = {
|
|
|
chunk: {
|
|
|
startVersion: 5,
|
|
|
@@ -172,13 +187,14 @@ describe('HistoryStoreManager', function () {
|
|
|
},
|
|
|
}
|
|
|
|
|
|
- this.request
|
|
|
- .withArgs(this.latestChunkRequestArgs)
|
|
|
- .yields(null, { statusCode: 200 }, this.chunk)
|
|
|
+ this.FetchUtils.fetchString.resolves(JSON.stringify(this.chunk))
|
|
|
this.HistoryStoreManager.getMostRecentVersion(
|
|
|
this.projectId,
|
|
|
this.historyId,
|
|
|
- this.callback
|
|
|
+ (...args) => {
|
|
|
+ this.callback(...args)
|
|
|
+ done()
|
|
|
+ }
|
|
|
)
|
|
|
})
|
|
|
|
|
|
@@ -204,7 +220,7 @@ describe('HistoryStoreManager', function () {
|
|
|
})
|
|
|
|
|
|
describe('out of order project structure versions', function () {
|
|
|
- beforeEach(function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
this.chunk = {
|
|
|
chunk: {
|
|
|
startVersion: 5,
|
|
|
@@ -222,13 +238,14 @@ describe('HistoryStoreManager', function () {
|
|
|
},
|
|
|
}
|
|
|
|
|
|
- this.request
|
|
|
- .withArgs(this.latestChunkRequestArgs)
|
|
|
- .yields(null, { statusCode: 200 }, this.chunk)
|
|
|
+ this.FetchUtils.fetchString.resolves(JSON.stringify(this.chunk))
|
|
|
this.HistoryStoreManager.getMostRecentVersion(
|
|
|
this.projectId,
|
|
|
this.historyId,
|
|
|
- this.callback
|
|
|
+ (...args) => {
|
|
|
+ this.callback(...args)
|
|
|
+ done()
|
|
|
+ }
|
|
|
)
|
|
|
})
|
|
|
|
|
|
@@ -256,7 +273,7 @@ describe('HistoryStoreManager', function () {
|
|
|
})
|
|
|
|
|
|
describe('out of order project structure and doc versions', function () {
|
|
|
- beforeEach(function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
this.chunk = {
|
|
|
chunk: {
|
|
|
startVersion: 5,
|
|
|
@@ -313,13 +330,14 @@ describe('HistoryStoreManager', function () {
|
|
|
},
|
|
|
}
|
|
|
|
|
|
- this.request
|
|
|
- .withArgs(this.latestChunkRequestArgs)
|
|
|
- .yields(null, { statusCode: 200 }, this.chunk)
|
|
|
+ this.FetchUtils.fetchString.resolves(JSON.stringify(this.chunk))
|
|
|
this.HistoryStoreManager.getMostRecentVersion(
|
|
|
this.projectId,
|
|
|
this.historyId,
|
|
|
- this.callback
|
|
|
+ (...args) => {
|
|
|
+ this.callback(...args)
|
|
|
+ done()
|
|
|
+ }
|
|
|
)
|
|
|
})
|
|
|
|
|
|
@@ -350,20 +368,21 @@ describe('HistoryStoreManager', function () {
|
|
|
})
|
|
|
|
|
|
describe('with an unexpected response', function () {
|
|
|
- beforeEach(function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
this.badChunk = {
|
|
|
chunk: {
|
|
|
foo: 123, // valid chunk should have startVersion property
|
|
|
bar: 456,
|
|
|
},
|
|
|
}
|
|
|
- this.request
|
|
|
- .withArgs(this.latestChunkRequestArgs)
|
|
|
- .yields(null, { statusCode: 200 }, this.badChunk)
|
|
|
+ this.FetchUtils.fetchString.resolves(JSON.stringify(this.badChunk))
|
|
|
this.HistoryStoreManager.getMostRecentVersion(
|
|
|
this.projectId,
|
|
|
this.historyId,
|
|
|
- this.callback
|
|
|
+ (...args) => {
|
|
|
+ this.callback(...args)
|
|
|
+ done()
|
|
|
+ }
|
|
|
)
|
|
|
})
|
|
|
|
|
|
@@ -613,28 +632,25 @@ describe('HistoryStoreManager', function () {
|
|
|
|
|
|
describe('getProjectBlob', function () {
|
|
|
describe('successfully', function () {
|
|
|
- beforeEach(function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
this.blobContent = 'test content'
|
|
|
- this.blobHash = 'test hash'
|
|
|
+ this.blobHash = 'testhash'
|
|
|
|
|
|
- this.request.yields(null, { statusCode: 200 }, this.blobContent)
|
|
|
+ this.FetchUtils.fetchString.resolves(this.blobContent)
|
|
|
this.HistoryStoreManager.getProjectBlob(
|
|
|
this.historyId,
|
|
|
this.blobHash,
|
|
|
- this.callback
|
|
|
+ (...args) => {
|
|
|
+ this.callback(...args)
|
|
|
+ done()
|
|
|
+ }
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('should get the blob from the overleaf history service', function () {
|
|
|
- expect(this.request).to.have.been.calledWithMatch({
|
|
|
- method: 'GET',
|
|
|
- url: `${this.settings.overleaf.history.host}/projects/${this.historyId}/blobs/${this.blobHash}`,
|
|
|
- auth: {
|
|
|
- user: this.settings.overleaf.history.user,
|
|
|
- pass: this.settings.overleaf.history.pass,
|
|
|
- sendImmediately: true,
|
|
|
- },
|
|
|
- })
|
|
|
+ expect(this.FetchUtils.fetchString).to.have.been.calledWithMatch(
|
|
|
+ `${this.settings.overleaf.history.host}/projects/${this.historyId}/blobs/${this.blobHash}`
|
|
|
+ )
|
|
|
})
|
|
|
|
|
|
it('should call the callback with the blob', function () {
|
|
|
@@ -677,32 +693,27 @@ describe('HistoryStoreManager', function () {
|
|
|
|
|
|
describe('initializeProject', function () {
|
|
|
describe('successfully', function () {
|
|
|
- beforeEach(function () {
|
|
|
+ beforeEach(function (done) {
|
|
|
this.response_body = { projectId: this.historyId }
|
|
|
- this.request.callsArgWith(
|
|
|
- 1,
|
|
|
- null,
|
|
|
- { statusCode: 200 },
|
|
|
- this.response_body
|
|
|
- )
|
|
|
+ this.FetchUtils.fetchString.resolves(JSON.stringify(this.response_body))
|
|
|
|
|
|
this.HistoryStoreManager.initializeProject(
|
|
|
this.historyId,
|
|
|
- this.callback
|
|
|
+ (...args) => {
|
|
|
+ this.callback(...args)
|
|
|
+ done()
|
|
|
+ }
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('should send the change to the history store', function () {
|
|
|
- expect(this.request).to.have.been.calledWithMatch({
|
|
|
- method: 'POST',
|
|
|
- url: `${this.settings.overleaf.history.host}/projects`,
|
|
|
- auth: {
|
|
|
- user: this.settings.overleaf.history.user,
|
|
|
- pass: this.settings.overleaf.history.pass,
|
|
|
- sendImmediately: true,
|
|
|
- },
|
|
|
- json: { projectId: this.historyId },
|
|
|
- })
|
|
|
+ expect(this.FetchUtils.fetchString).to.have.been.calledWithMatch(
|
|
|
+ `${this.settings.overleaf.history.host}/projects`,
|
|
|
+ {
|
|
|
+ method: 'POST',
|
|
|
+ json: { projectId: this.historyId },
|
|
|
+ }
|
|
|
+ )
|
|
|
})
|
|
|
|
|
|
it('should call the callback with the new overleaf id', function () {
|
|
|
@@ -713,15 +724,15 @@ describe('HistoryStoreManager', function () {
|
|
|
|
|
|
describe('deleteProject', function () {
|
|
|
beforeEach(function (done) {
|
|
|
- this.request.yields(null, { statusCode: 204 }, '')
|
|
|
+ this.FetchUtils.fetchString.resolves('')
|
|
|
this.HistoryStoreManager.deleteProject(this.historyId, done)
|
|
|
})
|
|
|
|
|
|
it('should ask the history store to delete the project', function () {
|
|
|
- expect(this.request).to.have.been.calledWithMatch({
|
|
|
- method: 'DELETE',
|
|
|
- url: `${this.settings.overleaf.history.host}/projects/${this.historyId}`,
|
|
|
- })
|
|
|
+ expect(this.FetchUtils.fetchString).to.have.been.calledWithMatch(
|
|
|
+ `${this.settings.overleaf.history.host}/projects/${this.historyId}`,
|
|
|
+ { method: 'DELETE' }
|
|
|
+ )
|
|
|
})
|
|
|
})
|
|
|
})
|