Fix formating

This commit is contained in:
Christopher Hoskin 2020-08-12 15:29:19 +01:00
parent 2be47a6820
commit 16c9ab38b2
20 changed files with 234 additions and 234 deletions

View file

@ -24,8 +24,8 @@ module.exports = {
unArchiveAllDocs,
unarchiveDoc,
destroyAllDocs,
destroyDoc,
},
destroyDoc
}
}
async function archiveAllDocs(projectId) {
@ -61,7 +61,7 @@ async function archiveDoc(projectId, doc) {
const json = JSON.stringify({
lines: doc.lines,
ranges: doc.ranges,
schema_v: 1,
schema_v: 1
})
// this should never happen, but protects against memory-corruption errors that
@ -75,7 +75,7 @@ async function archiveDoc(projectId, doc) {
const md5 = crypto.createHash('md5').update(json).digest('hex')
const stream = Streamifier.createReadStream(json)
await PersistorManager.sendStream(settings.docstore.bucket, key, stream, {
sourceMd5: md5,
sourceMd5: md5
})
await MongoManager.markDocAsArchived(doc._id, doc.rev)
}
@ -115,7 +115,7 @@ async function unarchiveDoc(projectId, docId) {
throw new Errors.Md5MismatchError('md5 mismatch when downloading doc', {
key,
sourceMd5,
md5,
md5
})
}
@ -155,7 +155,7 @@ async function destroyDoc(projectId, docId) {
'removing doc from mongo and persistor'
)
const doc = await MongoManager.findDoc(projectId, docId, {
inS3: 1,
inS3: 1
})
if (!doc) {
throw new Errors.NotFoundError('Doc not found in Mongo')

View file

@ -103,7 +103,7 @@ module.exports = DocManager = {
deleted: true,
version: true,
ranges: true,
inS3: true,
inS3: true
},
function (err, doc) {
if (err != null) {
@ -175,7 +175,7 @@ module.exports = DocManager = {
lines: true,
version: true,
ranges: true,
inS3: true,
inS3: true
},
function (err, doc) {
let updateLines, updateRanges, updateVersion
@ -238,7 +238,7 @@ module.exports = DocManager = {
project_id,
doc_id,
oldVersion: doc != null ? doc.version : undefined,
newVersion: version,
newVersion: version
},
'updating doc version'
)
@ -288,5 +288,5 @@ module.exports = DocManager = {
}
return MongoManager.markDocAsDeleted(project_id, doc_id, callback)
})
},
}
}

View file

@ -6,5 +6,5 @@ class Md5MismatchError extends OError {}
module.exports = {
Md5MismatchError,
...Errors,
...Errors
}

View file

@ -26,11 +26,11 @@ module.exports = {
const url = `http://localhost:${port}/project/${project_id}/doc/${doc_id}`
const lines = [
'smoke test - delete me',
`${crypto.randomBytes(32).toString('hex')}`,
`${crypto.randomBytes(32).toString('hex')}`
]
const getOpts = () => ({
url,
timeout: 3000,
timeout: 3000
})
logger.log({ lines, url, doc_id, project_id }, 'running health check')
const jobs = [
@ -61,8 +61,8 @@ module.exports = {
})
},
(cb) => db.docs.remove({ _id: doc_id, project_id }, cb),
(cb) => db.docOps.remove({ doc_id }, cb),
(cb) => db.docOps.remove({ doc_id }, cb)
]
return async.series(jobs, callback)
},
}
}

View file

@ -157,7 +157,7 @@ module.exports = HttpController = {
}
return res.json({
modified,
rev,
rev
})
}
)
@ -259,5 +259,5 @@ module.exports = HttpController = {
return res.sendStatus(200)
}
})
},
}
}

View file

@ -24,7 +24,7 @@ module.exports = MongoManager = {
return db.docs.find(
{
_id: ObjectId(doc_id.toString()),
project_id: ObjectId(project_id.toString()),
project_id: ObjectId(project_id.toString())
},
filter,
function (error, docs) {
@ -50,7 +50,7 @@ module.exports = MongoManager = {
getArchivedProjectDocs(project_id, callback) {
const query = {
project_id: ObjectId(project_id.toString()),
inS3: true,
inS3: true
}
return db.docs.find(query, {}, callback)
},
@ -59,11 +59,11 @@ module.exports = MongoManager = {
const update = {
$set: updates,
$inc: {
rev: 1,
rev: 1
},
$unset: {
inS3: true,
},
inS3: true
}
}
update.$set.project_id = ObjectId(project_id)
return db.docs.update(
@ -78,10 +78,10 @@ module.exports = MongoManager = {
return db.docs.update(
{
_id: ObjectId(doc_id),
project_id: ObjectId(project_id),
project_id: ObjectId(project_id)
},
{
$set: { deleted: true },
$set: { deleted: true }
},
callback
)
@ -90,14 +90,14 @@ module.exports = MongoManager = {
markDocAsArchived(doc_id, rev, callback) {
const update = {
$set: {},
$unset: {},
$unset: {}
}
update.$set.inS3 = true
update.$unset.lines = true
update.$unset.ranges = true
const query = {
_id: doc_id,
rev,
rev
}
return db.docs.update(query, update, (err) => callback(err))
},
@ -108,10 +108,10 @@ module.exports = MongoManager = {
}
return db.docOps.find(
{
doc_id: ObjectId(doc_id),
doc_id: ObjectId(doc_id)
},
{
version: 1,
version: 1
},
function (error, docs) {
if (error != null) {
@ -132,13 +132,13 @@ module.exports = MongoManager = {
}
return db.docOps.update(
{
doc_id: ObjectId(doc_id),
doc_id: ObjectId(doc_id)
},
{
$set: { version },
$set: { version }
},
{
upsert: true,
upsert: true
},
callback
)
@ -147,7 +147,7 @@ module.exports = MongoManager = {
destroyDoc(doc_id, callback) {
return db.docs.remove(
{
_id: ObjectId(doc_id),
_id: ObjectId(doc_id)
},
function (err) {
if (err != null) {
@ -155,13 +155,13 @@ module.exports = MongoManager = {
}
return db.docOps.remove(
{
doc_id: ObjectId(doc_id),
doc_id: ObjectId(doc_id)
},
callback
)
}
)
},
}
}
const methods = Object.getOwnPropertyNames(MongoManager)

View file

@ -65,5 +65,5 @@ module.exports = RangeManager = {
} catch (error) {
return data
}
},
}
}

View file

@ -5,5 +5,5 @@ const mongojs = require('mongojs')
const db = mongojs(Settings.mongo.url, ['docs', 'docOps'])
module.exports = {
db,
ObjectId: mongojs.ObjectId,
ObjectId: mongojs.ObjectId
}

View file

@ -10,8 +10,8 @@ const Settings = {
internal: {
docstore: {
port: 3016,
host: process.env.LISTEN_ADDRESS || 'localhost',
},
host: process.env.LISTEN_ADDRESS || 'localhost'
}
},
mongo: {},
@ -19,17 +19,17 @@ const Settings = {
docstore: {
backend: process.env.BACKEND || 's3',
healthCheck: {
project_id: process.env.HEALTH_CHECK_PROJECT_ID,
project_id: process.env.HEALTH_CHECK_PROJECT_ID
},
bucket: process.env.BUCKET_NAME || process.env.AWS_BUCKET || 'bucket',
gcs: {
unlockBeforeDelete: process.env.GCS_UNLOCK_BEFORE_DELETE === 'true',
deletedBucketSuffix: process.env.GCS_DELETED_BUCKET_SUFFIX,
deleteConcurrency: parseInt(process.env.GCS_DELETE_CONCURRENCY) || 50,
},
deleteConcurrency: parseInt(process.env.GCS_DELETE_CONCURRENCY) || 50
}
},
max_doc_length: parseInt(process.env.MAX_DOC_LENGTH) || 2 * 1024 * 1024, // 2mb
max_doc_length: parseInt(process.env.MAX_DOC_LENGTH) || 2 * 1024 * 1024 // 2mb
}
if (process.env.MONGO_CONNECTION_STRING != null) {
@ -51,7 +51,7 @@ if (
bucket: process.env.AWS_BUCKET,
endpoint: process.env.AWS_S3_ENDPOINT,
pathStyle: process.env.AWS_S3_PATH_STYLE,
partSize: parseInt(process.env.AWS_S3_PARTSIZE) || 100 * 1024 * 1024,
partSize: parseInt(process.env.AWS_S3_PARTSIZE) || 100 * 1024 * 1024
}
}
@ -59,7 +59,7 @@ if (process.env.GCS_API_ENDPOINT) {
Settings.docstore.gcs.endpoint = {
apiEndpoint: process.env.GCS_API_ENDPOINT,
apiScheme: process.env.GCS_API_SCHEME,
projectId: process.env.GCS_PROJECT_ID,
projectId: process.env.GCS_PROJECT_ID
}
}
@ -69,7 +69,7 @@ if (process.env.FALLBACK_BACKEND) {
// mapping of bucket names on the fallback, to bucket names on the primary.
// e.g. { myS3UserFilesBucketName: 'myGoogleUserFilesBucketName' }
buckets: JSON.parse(process.env.FALLBACK_BUCKET_MAPPING || '{}'),
copyOnMiss: process.env.COPY_ON_MISS === 'true',
copyOnMiss: process.env.COPY_ON_MISS === 'true'
}
}

View file

@ -51,14 +51,14 @@ describe('Archiving', function () {
_id: ObjectId(),
lines: ['one', 'two', 'three'],
ranges: {},
version: 2,
version: 2
},
{
_id: ObjectId(),
lines: ['aaa', 'bbb', 'ccc'],
ranges: {},
version: 4,
},
version: 4
}
]
const jobs = Array.from(this.docs).map((doc) =>
((doc) => {
@ -173,7 +173,7 @@ describe('Archiving', function () {
_id: ObjectId(),
lines: ['one', 'two', 'three'],
ranges: {},
version: 2,
version: 2
}
return DocstoreClient.createDoc(
this.project_id,
@ -287,7 +287,7 @@ describe('Archiving', function () {
_id: ObjectId(),
lines: [big_line, big_line, big_line, big_line],
ranges: {},
version: 2,
version: 2
}
return DocstoreClient.createDoc(
this.project_id,
@ -758,10 +758,10 @@ describe('Archiving', function () {
'Roses are \u001b[0;31mred\u001b[0m, violets are \u001b[0;34mblue. Hope you enjoy terminal hue',
'But now...\u001b[20Cfor my greatest trick...\u001b[8m',
'The quic\b\b\b\b\b\bk brown fo\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007x... [Beeeep]',
'Powerلُلُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ冗',
'Powerلُلُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ冗'
],
ranges: {},
version: 2,
version: 2
}
return DocstoreClient.createDoc(
this.project_id,
@ -857,17 +857,17 @@ describe('Archiving', function () {
op: { i: 'foo', p: 24 },
metadata: {
user_id: ObjectId(),
ts: new Date('2017-01-27T16:10:44.194Z'),
},
ts: new Date('2017-01-27T16:10:44.194Z')
}
},
{
id: ObjectId(),
op: { d: 'bar', p: 50 },
metadata: {
user_id: ObjectId(),
ts: new Date('2017-01-27T18:10:44.194Z'),
},
},
ts: new Date('2017-01-27T18:10:44.194Z')
}
}
],
comments: [
{
@ -875,12 +875,12 @@ describe('Archiving', function () {
op: { c: 'comment', p: 284, t: ObjectId() },
metadata: {
user_id: ObjectId(),
ts: new Date('2017-01-26T14:22:04.869Z'),
},
},
],
ts: new Date('2017-01-26T14:22:04.869Z')
}
}
]
},
version: 2,
version: 2
}
return DocstoreClient.createDoc(
this.project_id,
@ -971,7 +971,7 @@ describe('Archiving', function () {
_id: ObjectId(),
lines: ['abc', 'def', 'ghi'],
ranges: {},
version: 2,
version: 2
}
return DocstoreClient.createDoc(
this.project_id,
@ -1067,7 +1067,7 @@ describe('Archiving', function () {
_id: ObjectId(),
lines: ['abc', 'def', 'ghi'],
ranges: {},
version: 2,
version: 2
}
uploadContent(
`${this.project_id}/${this.doc._id}`,
@ -1079,7 +1079,7 @@ describe('Archiving', function () {
project_id: this.project_id,
_id: this.doc._id,
rev: this.doc.version,
inS3: true,
inS3: true
},
(error) => {
if (error != null) {

View file

@ -28,26 +28,26 @@ describe('Getting all docs', function () {
_id: ObjectId(),
lines: ['one', 'two', 'three'],
ranges: { mock: 'one' },
rev: 2,
rev: 2
},
{
_id: ObjectId(),
lines: ['aaa', 'bbb', 'ccc'],
ranges: { mock: 'two' },
rev: 4,
rev: 4
},
{
_id: ObjectId(),
lines: ['111', '222', '333'],
ranges: { mock: 'three' },
rev: 6,
},
rev: 6
}
]
this.deleted_doc = {
_id: ObjectId(),
lines: ['deleted'],
ranges: { mock: 'four' },
rev: 8,
rev: 8
}
const version = 42
const jobs = Array.from(this.docs).map((doc) =>

View file

@ -32,10 +32,10 @@ describe('Getting a doc', function () {
op: { i: 'foo', p: 3 },
meta: {
user_id: ObjectId().toString(),
ts: new Date().toString(),
},
},
],
ts: new Date().toString()
}
}
]
}
return DocstoreApp.ensureRunning(() => {
return DocstoreClient.createDoc(

View file

@ -31,10 +31,10 @@ describe('Applying updates to a doc', function () {
op: { i: 'foo', p: 3 },
meta: {
user_id: ObjectId().toString(),
ts: new Date().toString(),
},
},
],
ts: new Date().toString()
}
}
]
}
this.newRanges = {
changes: [
@ -43,10 +43,10 @@ describe('Applying updates to a doc', function () {
op: { i: 'bar', p: 6 },
meta: {
user_id: ObjectId().toString(),
ts: new Date().toString(),
},
},
],
ts: new Date().toString()
}
}
]
}
this.version = 42
return DocstoreApp.ensureRunning(() => {

View file

@ -48,5 +48,5 @@ module.exports = {
}
)
}
},
}
}

View file

@ -54,7 +54,7 @@ module.exports = DocstoreClient = {
{
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`,
json: true,
qs,
qs
},
callback
)
@ -67,7 +67,7 @@ module.exports = DocstoreClient = {
return request.get(
{
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc`,
json: true,
json: true
},
(req, res, body) => {
callback(req, res, body)
@ -82,7 +82,7 @@ module.exports = DocstoreClient = {
return request.get(
{
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/ranges`,
json: true,
json: true
},
callback
)
@ -98,8 +98,8 @@ module.exports = DocstoreClient = {
json: {
lines,
version,
ranges,
},
ranges
}
},
callback
)
@ -111,7 +111,7 @@ module.exports = DocstoreClient = {
}
return request.del(
{
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`,
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`
},
callback
)
@ -123,7 +123,7 @@ module.exports = DocstoreClient = {
}
return request.post(
{
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/archive`,
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/archive`
},
callback
)
@ -135,7 +135,7 @@ module.exports = DocstoreClient = {
}
return request.post(
{
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/destroy`,
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/destroy`
},
callback
)
@ -151,5 +151,5 @@ module.exports = DocstoreClient = {
callback(null, JSON.parse(data))
})
.catch(callback)
},
}
}

View file

@ -32,24 +32,24 @@ describe('DocArchiveManager', function () {
md5Sum = 'decafbad'
RangeManager = {
jsonRangesToMongo: sinon.stub().returns({ mongo: 'ranges' }),
jsonRangesToMongo: sinon.stub().returns({ mongo: 'ranges' })
}
Settings = {
docstore: {
bucket: 'wombat',
},
bucket: 'wombat'
}
}
Logger = {
log: sinon.stub(),
err: sinon.stub(),
err: sinon.stub()
}
HashDigest = sinon.stub().returns(md5Sum)
HashUpdate = sinon.stub().returns({ digest: HashDigest })
Crypto = {
createHash: sinon.stub().returns({ update: HashUpdate }),
createHash: sinon.stub().returns({ update: HashUpdate })
}
Streamifier = {
createReadStream: sinon.stub().returns({ stream: 'readStream' }),
createReadStream: sinon.stub().returns({ stream: 'readStream' })
}
projectId = ObjectId()
@ -57,69 +57,69 @@ describe('DocArchiveManager', function () {
{
_id: ObjectId(),
inS3: true,
rev: 2,
rev: 2
},
{
_id: ObjectId(),
inS3: true,
rev: 4,
rev: 4
},
{
_id: ObjectId(),
inS3: true,
rev: 6,
},
rev: 6
}
]
mongoDocs = [
{
_id: ObjectId(),
lines: ['one', 'two', 'three'],
rev: 2,
rev: 2
},
{
_id: ObjectId(),
lines: ['aaa', 'bbb', 'ccc'],
rev: 4,
rev: 4
},
{
_id: ObjectId(),
inS3: true,
rev: 6,
rev: 6
},
{
_id: ObjectId(),
inS3: true,
rev: 6,
rev: 6
},
{
_id: ObjectId(),
lines: ['111', '222', '333'],
rev: 6,
},
rev: 6
}
]
docJson = JSON.stringify({
lines: mongoDocs[0].lines,
ranges: mongoDocs[0].ranges,
schema_v: 1,
schema_v: 1
})
stream = {
on: sinon.stub(),
resume: sinon.stub(),
resume: sinon.stub()
}
stream.on.withArgs('data').yields(Buffer.from(docJson, 'utf8'))
stream.on.withArgs('end').yields()
readStream = {
stream: 'readStream',
stream: 'readStream'
}
PersistorManager = {
getObjectStream: sinon.stub().resolves(stream),
sendStream: sinon.stub().resolves(),
getObjectMd5Hash: sinon.stub().resolves(md5Sum),
deleteObject: sinon.stub().resolves(),
deleteObject: sinon.stub().resolves()
}
MongoManager = {
@ -129,8 +129,8 @@ describe('DocArchiveManager', function () {
getProjectsDocs: sinon.stub().resolves(mongoDocs),
getArchivedProjectDocs: sinon.stub().resolves(archivedDocs),
findDoc: sinon.stub().resolves(),
destroyDoc: sinon.stub().resolves(),
},
destroyDoc: sinon.stub().resolves()
}
}
for (const mongoDoc of mongoDocs) {
MongoManager.promises.findDoc
@ -147,12 +147,12 @@ describe('DocArchiveManager', function () {
'./MongoManager': MongoManager,
'./RangeManager': RangeManager,
'./PersistorManager': PersistorManager,
'./Errors': Errors,
'./Errors': Errors
},
globals: {
console,
JSON,
},
JSON
}
})
})
@ -183,7 +183,7 @@ describe('DocArchiveManager', function () {
const json = JSON.stringify({
lines: mongoDocs[0].lines,
ranges: mongoDocs[0].ranges,
schema_v: 1,
schema_v: 1
})
await DocArchiveManager.promises.archiveDoc(projectId, mongoDocs[0])
@ -290,7 +290,7 @@ describe('DocArchiveManager', function () {
describe('when the doc has the old schema', function () {
beforeEach(function () {
mongoDoc = {
lines: ['doc', 'lines'],
lines: ['doc', 'lines']
}
s3Doc = ['doc', 'lines']
docJson = JSON.stringify(s3Doc)
@ -310,11 +310,11 @@ describe('DocArchiveManager', function () {
s3Doc = {
lines: ['doc', 'lines'],
ranges: { json: 'ranges' },
schema_v: 1,
schema_v: 1
}
mongoDoc = {
lines: ['doc', 'lines'],
ranges: { mongo: 'ranges' },
ranges: { mongo: 'ranges' }
}
docJson = JSON.stringify(s3Doc)
stream.on.withArgs('data').yields(Buffer.from(docJson, 'utf8'))
@ -332,10 +332,10 @@ describe('DocArchiveManager', function () {
beforeEach(function () {
s3Doc = {
lines: ['doc', 'lines'],
schema_v: 1,
schema_v: 1
}
mongoDoc = {
lines: ['doc', 'lines'],
lines: ['doc', 'lines']
}
docJson = JSON.stringify(s3Doc)
stream.on.withArgs('data').yields(Buffer.from(docJson, 'utf8'))
@ -353,7 +353,7 @@ describe('DocArchiveManager', function () {
beforeEach(function () {
s3Doc = {
lines: ['doc', 'lines'],
schema_v: 2,
schema_v: 2
}
docJson = JSON.stringify(s3Doc)
stream.on.withArgs('data').yields(Buffer.from(docJson, 'utf8'))

View file

@ -32,15 +32,15 @@ describe('DocManager', function () {
jsonRangesToMongo(r) {
return r
},
shouldUpdateRanges: sinon.stub().returns(false),
shouldUpdateRanges: sinon.stub().returns(false)
}),
'logger-sharelatex': (this.logger = {
log: sinon.stub(),
warn() {},
err() {},
err() {}
}),
'./Errors': Errors,
},
'./Errors': Errors
}
})
this.doc_id = ObjectId().toString()
this.project_id = ObjectId().toString()
@ -99,7 +99,7 @@ describe('DocManager', function () {
this.DocManager._getDoc = sinon.stub()
return (this.doc = {
_id: this.doc_id,
lines: ['2134'],
lines: ['2134']
})
})
@ -117,7 +117,7 @@ describe('DocManager', function () {
deleted: true,
version: true,
ranges: true,
inS3: true,
inS3: true
})
.should.equal(true)
return done()
@ -154,7 +154,7 @@ describe('DocManager', function () {
this.DocManager._getDoc
.calledWith(this.project_id, this.doc_id, {
lines: true,
inS3: true,
inS3: true
})
.should.equal(true)
return done()
@ -181,7 +181,7 @@ describe('DocManager', function () {
this.doc = {
_id: this.doc_id,
project_id: this.project_id,
lines: ['mock-lines'],
lines: ['mock-lines']
}
this.version = 42
this.MongoManager.findDoc = sinon.stub()
@ -302,7 +302,7 @@ describe('DocManager', function () {
_id: this.doc_id,
project_id: this.project_id,
lines: ['mock-lines'],
inS3: true,
inS3: true
}
this.MongoManager.findDoc.yields(null, this.doc)
this.DocArchiveManager.unarchiveDoc = (
@ -368,8 +368,8 @@ describe('DocManager', function () {
{
_id: this.doc_id,
project_id: this.project_id,
lines: ['mock-lines'],
},
lines: ['mock-lines']
}
]
this.MongoManager.getProjectsDocs = sinon
.stub()
@ -490,10 +490,10 @@ describe('DocManager', function () {
op: { i: 'foo', p: 3 },
meta: {
user_id: ObjectId().toString(),
ts: new Date().toString(),
},
},
],
ts: new Date().toString()
}
}
]
}
this.newRanges = {
changes: [
@ -502,10 +502,10 @@ describe('DocManager', function () {
op: { i: 'bar', p: 6 },
meta: {
user_id: ObjectId().toString(),
ts: new Date().toString(),
},
},
],
ts: new Date().toString()
}
}
]
}
this.version = 42
this.doc = {
@ -514,7 +514,7 @@ describe('DocManager', function () {
lines: this.oldDocLines,
rev: (this.rev = 5),
version: this.version,
ranges: this.originalRanges,
ranges: this.originalRanges
}
this.MongoManager.upsertIntoDocCollection = sinon.stub().callsArg(3)
@ -543,7 +543,7 @@ describe('DocManager', function () {
lines: true,
version: true,
ranges: true,
inS3: true,
inS3: true
})
.should.equal(true)
})
@ -789,7 +789,7 @@ describe('DocManager', function () {
return this.MongoManager.upsertIntoDocCollection
.calledWith(this.project_id, this.doc_id, {
lines: this.newDocLines,
ranges: this.originalRanges,
ranges: this.originalRanges
})
.should.equal(true)
})

View file

@ -29,17 +29,17 @@ describe('HttpController', function () {
'./DocArchiveManager': (this.DocArchiveManager = {}),
'logger-sharelatex': (this.logger = {
log: sinon.stub(),
error: sinon.stub(),
error: sinon.stub()
}),
'./HealthChecker': {},
'./HealthChecker': {}
},
globals: { process },
globals: { process }
})
this.res = {
send: sinon.stub(),
sendStatus: sinon.stub(),
json: sinon.stub(),
setHeader: sinon.stub(),
setHeader: sinon.stub()
}
this.res.status = sinon.stub().returns(this.res)
this.req = { query: {} }
@ -50,14 +50,14 @@ describe('HttpController', function () {
_id: this.doc_id,
lines: ['mock', 'lines', ' here', '', '', ' spaces '],
version: 42,
rev: 5,
rev: 5
}
return (this.deletedDoc = {
deleted: true,
_id: this.doc_id,
lines: ['mock', 'lines', ' here', '', '', ' spaces '],
version: 42,
rev: 5,
rev: 5
})
})
@ -66,7 +66,7 @@ describe('HttpController', function () {
beforeEach(function () {
this.req.params = {
project_id: this.project_id,
doc_id: this.doc_id,
doc_id: this.doc_id
}
this.DocManager.getFullDoc = sinon
.stub()
@ -86,7 +86,7 @@ describe('HttpController', function () {
_id: this.doc_id,
lines: this.doc.lines,
rev: this.doc.rev,
version: this.doc.version,
version: this.doc.version
})
.should.equal(true)
})
@ -96,7 +96,7 @@ describe('HttpController', function () {
beforeEach(function () {
this.req.params = {
project_id: this.project_id,
doc_id: this.doc_id,
doc_id: this.doc_id
}
return (this.DocManager.getFullDoc = sinon
.stub()
@ -124,7 +124,7 @@ describe('HttpController', function () {
lines: this.doc.lines,
rev: this.doc.rev,
deleted: true,
version: this.doc.version,
version: this.doc.version
})
.should.equal(true)
})
@ -135,7 +135,7 @@ describe('HttpController', function () {
beforeEach(function () {
this.req.params = {
project_id: this.project_id,
doc_id: this.doc_id,
doc_id: this.doc_id
}
this.DocManager.getDocLines = sinon.stub().callsArgWith(2, null, this.doc)
return this.HttpController.getRawDoc(this.req, this.res, this.next)
@ -169,13 +169,13 @@ describe('HttpController', function () {
{
_id: ObjectId(),
lines: ['mock', 'lines', 'one'],
rev: 2,
rev: 2
},
{
_id: ObjectId(),
lines: ['mock', 'lines', 'two'],
rev: 4,
},
rev: 4
}
]
this.DocManager.getAllNonDeletedDocs = sinon
.stub()
@ -195,13 +195,13 @@ describe('HttpController', function () {
{
_id: this.docs[0]._id.toString(),
lines: this.docs[0].lines,
rev: this.docs[0].rev,
rev: this.docs[0].rev
},
{
_id: this.docs[1]._id.toString(),
lines: this.docs[1].lines,
rev: this.docs[1].rev,
},
rev: this.docs[1].rev
}
])
.should.equal(true)
})
@ -214,14 +214,14 @@ describe('HttpController', function () {
{
_id: ObjectId(),
lines: ['mock', 'lines', 'one'],
rev: 2,
rev: 2
},
null,
{
_id: ObjectId(),
lines: ['mock', 'lines', 'two'],
rev: 4,
},
rev: 4
}
]
this.DocManager.getAllNonDeletedDocs = sinon
.stub()
@ -235,13 +235,13 @@ describe('HttpController', function () {
{
_id: this.docs[0]._id.toString(),
lines: this.docs[0].lines,
rev: this.docs[0].rev,
rev: this.docs[0].rev
},
{
_id: this.docs[2]._id.toString(),
lines: this.docs[2].lines,
rev: this.docs[2].rev,
},
rev: this.docs[2].rev
}
])
.should.equal(true)
})
@ -251,7 +251,7 @@ describe('HttpController', function () {
.calledWith(
{
err: sinon.match.has('message', 'null doc'),
project_id: this.project_id,
project_id: this.project_id
},
'encountered null doc'
)
@ -267,12 +267,12 @@ describe('HttpController', function () {
this.docs = [
{
_id: ObjectId(),
ranges: { mock_ranges: 'one' },
ranges: { mock_ranges: 'one' }
},
{
_id: ObjectId(),
ranges: { mock_ranges: 'two' },
},
ranges: { mock_ranges: 'two' }
}
]
this.DocManager.getAllNonDeletedDocs = sinon
.stub()
@ -291,12 +291,12 @@ describe('HttpController', function () {
.calledWith([
{
_id: this.docs[0]._id.toString(),
ranges: this.docs[0].ranges,
ranges: this.docs[0].ranges
},
{
_id: this.docs[1]._id.toString(),
ranges: this.docs[1].ranges,
},
ranges: this.docs[1].ranges
}
])
.should.equal(true)
})
@ -307,7 +307,7 @@ describe('HttpController', function () {
beforeEach(function () {
return (this.req.params = {
project_id: this.project_id,
doc_id: this.doc_id,
doc_id: this.doc_id
})
})
@ -316,7 +316,7 @@ describe('HttpController', function () {
this.req.body = {
lines: (this.lines = ['hello', 'world']),
version: (this.version = 42),
ranges: (this.ranges = { changes: 'mock' }),
ranges: (this.ranges = { changes: 'mock' })
}
this.DocManager.updateDoc = sinon
.stub()
@ -348,7 +348,7 @@ describe('HttpController', function () {
this.req.body = {
lines: (this.lines = ['hello', 'world']),
version: (this.version = 42),
ranges: {},
ranges: {}
}
this.DocManager.updateDoc = sinon
.stub()
@ -416,7 +416,7 @@ describe('HttpController', function () {
this.req.body = {
lines: (this.lines = Array(2049).fill('a'.repeat(1024))),
version: (this.version = 42),
ranges: (this.ranges = { changes: 'mock' }),
ranges: (this.ranges = { changes: 'mock' })
}
return this.HttpController.updateDoc(this.req, this.res, this.next)
})
@ -435,7 +435,7 @@ describe('HttpController', function () {
beforeEach(function () {
this.req.params = {
project_id: this.project_id,
doc_id: this.doc_id,
doc_id: this.doc_id
}
this.DocManager.deleteDoc = sinon.stub().callsArg(2)
return this.HttpController.deleteDoc(this.req, this.res, this.next)

View file

@ -25,14 +25,14 @@ describe('MongoManager', function () {
requires: {
'./mongojs': {
db: (this.db = { docs: {}, docOps: {} }),
ObjectId,
ObjectId
},
'metrics-sharelatex': { timeAsyncMethod: sinon.stub() },
'logger-sharelatex': { log() {} },
'logger-sharelatex': { log() {} }
},
globals: {
console,
},
console
}
})
this.project_id = ObjectId().toString()
this.doc_id = ObjectId().toString()
@ -58,7 +58,7 @@ describe('MongoManager', function () {
.calledWith(
{
_id: ObjectId(this.doc_id),
project_id: ObjectId(this.project_id),
project_id: ObjectId(this.project_id)
},
this.filter
)
@ -97,7 +97,7 @@ describe('MongoManager', function () {
.calledWith(
{
project_id: ObjectId(this.project_id),
deleted: { $ne: true },
deleted: { $ne: true }
},
this.filter
)
@ -125,7 +125,7 @@ describe('MongoManager', function () {
return this.db.docs.find
.calledWith(
{
project_id: ObjectId(this.project_id),
project_id: ObjectId(this.project_id)
},
this.filter
)
@ -189,7 +189,7 @@ describe('MongoManager', function () {
const args = this.db.docs.update.args[0]
assert.deepEqual(args[0], {
_id: ObjectId(this.doc_id),
project_id: ObjectId(this.project_id),
project_id: ObjectId(this.project_id)
})
assert.equal(args[1].$set.deleted, true)
return done()
@ -218,13 +218,13 @@ describe('MongoManager', function () {
it('should destroy the doc', function () {
return sinon.assert.calledWith(this.db.docs.remove, {
_id: ObjectId('123456789012'),
_id: ObjectId('123456789012')
})
})
return it('should destroy the docOps', function () {
return sinon.assert.calledWith(this.db.docOps.remove, {
doc_id: ObjectId('123456789012'),
doc_id: ObjectId('123456789012')
})
})
})
@ -275,15 +275,15 @@ describe('MongoManager', function () {
return this.db.docOps.update
.calledWith(
{
doc_id: ObjectId(this.doc_id),
doc_id: ObjectId(this.doc_id)
},
{
$set: {
version: this.version,
},
version: this.version
}
},
{
upsert: true,
upsert: true
}
)
.should.equal(true)

View file

@ -27,9 +27,9 @@ describe('RangeManager', function () {
return (this.RangeManager = SandboxedModule.require(modulePath, {
requires: {
'./mongojs': {
ObjectId,
},
},
ObjectId
}
}
}))
})
@ -47,16 +47,16 @@ describe('RangeManager', function () {
op: { i: 'foo', p: 3 },
metadata: {
user_id,
ts,
},
},
ts
}
}
],
comments: [
{
id: comment_id,
op: { c: 'foo', p: 3, t: thread_id },
},
],
op: { c: 'foo', p: 3, t: thread_id }
}
]
}).should.deep.equal({
changes: [
{
@ -64,16 +64,16 @@ describe('RangeManager', function () {
op: { i: 'foo', p: 3 },
metadata: {
user_id: ObjectId(user_id),
ts: new Date(ts),
},
},
ts: new Date(ts)
}
}
],
comments: [
{
id: ObjectId(comment_id),
op: { c: 'foo', p: 3, t: ObjectId(thread_id) },
},
],
op: { c: 'foo', p: 3, t: ObjectId(thread_id) }
}
]
})
})
@ -86,29 +86,29 @@ describe('RangeManager', function () {
{
id: change_id,
metadata: {
user_id,
},
},
user_id
}
}
],
comments: [
{
id: comment_id,
},
],
id: comment_id
}
]
}).should.deep.equal({
changes: [
{
id: change_id,
metadata: {
user_id,
},
},
user_id
}
}
],
comments: [
{
id: comment_id,
},
],
id: comment_id
}
]
})
})
@ -125,16 +125,16 @@ describe('RangeManager', function () {
op: { i: 'foo', p: 3 },
metadata: {
user_id,
ts,
},
},
ts
}
}
],
comments: [
{
id: comment_id,
op: { c: 'foo', p: 3, t: thread_id },
},
],
op: { c: 'foo', p: 3, t: thread_id }
}
]
}
const ranges1_copy = JSON.parse(JSON.stringify(ranges1)) // jsonRangesToMongo modifies in place
const ranges2 = JSON.parse(
@ -153,16 +153,16 @@ describe('RangeManager', function () {
op: { i: 'foo', p: 3 },
metadata: {
user_id: ObjectId(),
ts: new Date(),
},
},
ts: new Date()
}
}
],
comments: [
{
id: ObjectId(),
op: { c: 'foo', p: 3, t: ObjectId() },
},
],
op: { c: 'foo', p: 3, t: ObjectId() }
}
]
}
return (this.ranges_copy = this.RangeManager.jsonRangesToMongo(
JSON.parse(JSON.stringify(this.ranges))