overleaf/services/document-updater/test/acceptance/js/GettingProjectDocsTests.js

172 lines
5.1 KiB
JavaScript
Raw Normal View History

/* eslint-disable
handle-callback-err,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const sinon = require('sinon')
const { expect } = require('chai')
2017-08-11 15:55:31 +00:00
const MockWebApi = require('./helpers/MockWebApi')
const DocUpdaterClient = require('./helpers/DocUpdaterClient')
const DocUpdaterApp = require('./helpers/DocUpdaterApp')
2017-08-11 15:55:31 +00:00
describe('Getting documents for project', function () {
before(function (done) {
this.lines = ['one', 'two', 'three']
this.version = 42
return DocUpdaterApp.ensureRunning(done)
})
2017-08-11 15:55:31 +00:00
describe('when project state hash does not match', function () {
before(function (done) {
this.projectStateHash = DocUpdaterClient.randomId()
;[this.project_id, this.doc_id] = Array.from([
DocUpdaterClient.randomId(),
2021-07-13 11:04:42 +00:00
DocUpdaterClient.randomId(),
])
2017-08-11 15:55:31 +00:00
MockWebApi.insertDoc(this.project_id, this.doc_id, {
lines: this.lines,
2021-07-13 11:04:42 +00:00
version: this.version,
})
return DocUpdaterClient.preloadDoc(
this.project_id,
this.doc_id,
2021-07-13 11:04:42 +00:00
error => {
if (error != null) {
throw error
}
return DocUpdaterClient.getProjectDocs(
this.project_id,
this.projectStateHash,
(error, res, returnedDocs) => {
this.res = res
this.returnedDocs = returnedDocs
return done()
}
)
}
)
})
2017-08-11 15:55:31 +00:00
return it('should return a 409 Conflict response', function () {
return this.res.statusCode.should.equal(409)
})
})
2017-08-11 15:55:31 +00:00
describe('when project state hash matches', function () {
before(function (done) {
this.projectStateHash = DocUpdaterClient.randomId()
;[this.project_id, this.doc_id] = Array.from([
DocUpdaterClient.randomId(),
2021-07-13 11:04:42 +00:00
DocUpdaterClient.randomId(),
])
2017-08-11 15:55:31 +00:00
MockWebApi.insertDoc(this.project_id, this.doc_id, {
lines: this.lines,
2021-07-13 11:04:42 +00:00
version: this.version,
})
return DocUpdaterClient.preloadDoc(
this.project_id,
this.doc_id,
2021-07-13 11:04:42 +00:00
error => {
if (error != null) {
throw error
}
return DocUpdaterClient.getProjectDocs(
this.project_id,
this.projectStateHash,
(error, res0, returnedDocs0) => {
// set the hash
this.res0 = res0
this.returnedDocs0 = returnedDocs0
return DocUpdaterClient.getProjectDocs(
this.project_id,
this.projectStateHash,
(error, res, returnedDocs) => {
// the hash should now match
this.res = res
this.returnedDocs = returnedDocs
return done()
}
)
}
)
}
)
})
2017-08-11 15:55:31 +00:00
it('should return a 200 response', function () {
return this.res.statusCode.should.equal(200)
})
2017-08-11 15:55:31 +00:00
return it('should return the documents', function () {
return this.returnedDocs.should.deep.equal([
2021-07-13 11:04:42 +00:00
{ _id: this.doc_id, lines: this.lines, v: this.version },
])
})
})
2017-08-11 15:55:31 +00:00
return describe('when the doc has been removed', function () {
before(function (done) {
this.projectStateHash = DocUpdaterClient.randomId()
;[this.project_id, this.doc_id] = Array.from([
DocUpdaterClient.randomId(),
2021-07-13 11:04:42 +00:00
DocUpdaterClient.randomId(),
])
2017-08-11 15:55:31 +00:00
MockWebApi.insertDoc(this.project_id, this.doc_id, {
lines: this.lines,
2021-07-13 11:04:42 +00:00
version: this.version,
})
return DocUpdaterClient.preloadDoc(
this.project_id,
this.doc_id,
2021-07-13 11:04:42 +00:00
error => {
if (error != null) {
throw error
}
return DocUpdaterClient.getProjectDocs(
this.project_id,
this.projectStateHash,
(error, res0, returnedDocs0) => {
// set the hash
this.res0 = res0
this.returnedDocs0 = returnedDocs0
return DocUpdaterClient.deleteDoc(
this.project_id,
this.doc_id,
(error, res, body) => {
// delete the doc
return DocUpdaterClient.getProjectDocs(
this.project_id,
this.projectStateHash,
(error, res1, returnedDocs) => {
// the hash would match, but the doc has been deleted
this.res = res1
this.returnedDocs = returnedDocs
return done()
}
)
}
)
}
)
}
)
})
2017-08-11 15:55:31 +00:00
return it('should return a 409 Conflict response', function () {
return this.res.statusCode.should.equal(409)
})
})
})