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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -10,8 +10,8 @@ const Settings = {
internal: { internal: {
docstore: { docstore: {
port: 3016, port: 3016,
host: process.env.LISTEN_ADDRESS || 'localhost', host: process.env.LISTEN_ADDRESS || 'localhost'
}, }
}, },
mongo: {}, mongo: {},
@ -19,17 +19,17 @@ const Settings = {
docstore: { docstore: {
backend: process.env.BACKEND || 's3', backend: process.env.BACKEND || 's3',
healthCheck: { 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', bucket: process.env.BUCKET_NAME || process.env.AWS_BUCKET || 'bucket',
gcs: { gcs: {
unlockBeforeDelete: process.env.GCS_UNLOCK_BEFORE_DELETE === 'true', unlockBeforeDelete: process.env.GCS_UNLOCK_BEFORE_DELETE === 'true',
deletedBucketSuffix: process.env.GCS_DELETED_BUCKET_SUFFIX, 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) { if (process.env.MONGO_CONNECTION_STRING != null) {
@ -51,7 +51,7 @@ if (
bucket: process.env.AWS_BUCKET, bucket: process.env.AWS_BUCKET,
endpoint: process.env.AWS_S3_ENDPOINT, endpoint: process.env.AWS_S3_ENDPOINT,
pathStyle: process.env.AWS_S3_PATH_STYLE, 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 = { Settings.docstore.gcs.endpoint = {
apiEndpoint: process.env.GCS_API_ENDPOINT, apiEndpoint: process.env.GCS_API_ENDPOINT,
apiScheme: process.env.GCS_API_SCHEME, 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. // mapping of bucket names on the fallback, to bucket names on the primary.
// e.g. { myS3UserFilesBucketName: 'myGoogleUserFilesBucketName' } // e.g. { myS3UserFilesBucketName: 'myGoogleUserFilesBucketName' }
buckets: JSON.parse(process.env.FALLBACK_BUCKET_MAPPING || '{}'), 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(), _id: ObjectId(),
lines: ['one', 'two', 'three'], lines: ['one', 'two', 'three'],
ranges: {}, ranges: {},
version: 2, version: 2
}, },
{ {
_id: ObjectId(), _id: ObjectId(),
lines: ['aaa', 'bbb', 'ccc'], lines: ['aaa', 'bbb', 'ccc'],
ranges: {}, ranges: {},
version: 4, version: 4
}, }
] ]
const jobs = Array.from(this.docs).map((doc) => const jobs = Array.from(this.docs).map((doc) =>
((doc) => { ((doc) => {
@ -173,7 +173,7 @@ describe('Archiving', function () {
_id: ObjectId(), _id: ObjectId(),
lines: ['one', 'two', 'three'], lines: ['one', 'two', 'three'],
ranges: {}, ranges: {},
version: 2, version: 2
} }
return DocstoreClient.createDoc( return DocstoreClient.createDoc(
this.project_id, this.project_id,
@ -287,7 +287,7 @@ describe('Archiving', function () {
_id: ObjectId(), _id: ObjectId(),
lines: [big_line, big_line, big_line, big_line], lines: [big_line, big_line, big_line, big_line],
ranges: {}, ranges: {},
version: 2, version: 2
} }
return DocstoreClient.createDoc( return DocstoreClient.createDoc(
this.project_id, 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', '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', '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]', '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: {}, ranges: {},
version: 2, version: 2
} }
return DocstoreClient.createDoc( return DocstoreClient.createDoc(
this.project_id, this.project_id,
@ -857,17 +857,17 @@ describe('Archiving', function () {
op: { i: 'foo', p: 24 }, op: { i: 'foo', p: 24 },
metadata: { metadata: {
user_id: ObjectId(), user_id: ObjectId(),
ts: new Date('2017-01-27T16:10:44.194Z'), ts: new Date('2017-01-27T16:10:44.194Z')
}, }
}, },
{ {
id: ObjectId(), id: ObjectId(),
op: { d: 'bar', p: 50 }, op: { d: 'bar', p: 50 },
metadata: { metadata: {
user_id: ObjectId(), user_id: ObjectId(),
ts: new Date('2017-01-27T18:10:44.194Z'), ts: new Date('2017-01-27T18:10:44.194Z')
}, }
}, }
], ],
comments: [ comments: [
{ {
@ -875,12 +875,12 @@ describe('Archiving', function () {
op: { c: 'comment', p: 284, t: ObjectId() }, op: { c: 'comment', p: 284, t: ObjectId() },
metadata: { metadata: {
user_id: ObjectId(), 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( return DocstoreClient.createDoc(
this.project_id, this.project_id,
@ -971,7 +971,7 @@ describe('Archiving', function () {
_id: ObjectId(), _id: ObjectId(),
lines: ['abc', 'def', 'ghi'], lines: ['abc', 'def', 'ghi'],
ranges: {}, ranges: {},
version: 2, version: 2
} }
return DocstoreClient.createDoc( return DocstoreClient.createDoc(
this.project_id, this.project_id,
@ -1067,7 +1067,7 @@ describe('Archiving', function () {
_id: ObjectId(), _id: ObjectId(),
lines: ['abc', 'def', 'ghi'], lines: ['abc', 'def', 'ghi'],
ranges: {}, ranges: {},
version: 2, version: 2
} }
uploadContent( uploadContent(
`${this.project_id}/${this.doc._id}`, `${this.project_id}/${this.doc._id}`,
@ -1079,7 +1079,7 @@ describe('Archiving', function () {
project_id: this.project_id, project_id: this.project_id,
_id: this.doc._id, _id: this.doc._id,
rev: this.doc.version, rev: this.doc.version,
inS3: true, inS3: true
}, },
(error) => { (error) => {
if (error != null) { if (error != null) {

View file

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

View file

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

View file

@ -31,10 +31,10 @@ describe('Applying updates to a doc', function () {
op: { i: 'foo', p: 3 }, op: { i: 'foo', p: 3 },
meta: { meta: {
user_id: ObjectId().toString(), user_id: ObjectId().toString(),
ts: new Date().toString(), ts: new Date().toString()
}, }
}, }
], ]
} }
this.newRanges = { this.newRanges = {
changes: [ changes: [
@ -43,10 +43,10 @@ describe('Applying updates to a doc', function () {
op: { i: 'bar', p: 6 }, op: { i: 'bar', p: 6 },
meta: { meta: {
user_id: ObjectId().toString(), user_id: ObjectId().toString(),
ts: new Date().toString(), ts: new Date().toString()
}, }
}, }
], ]
} }
this.version = 42 this.version = 42
return DocstoreApp.ensureRunning(() => { 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}`, url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc/${doc_id}`,
json: true, json: true,
qs, qs
}, },
callback callback
) )
@ -67,7 +67,7 @@ module.exports = DocstoreClient = {
return request.get( return request.get(
{ {
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc`, url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/doc`,
json: true, json: true
}, },
(req, res, body) => { (req, res, body) => {
callback(req, res, body) callback(req, res, body)
@ -82,7 +82,7 @@ module.exports = DocstoreClient = {
return request.get( return request.get(
{ {
url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/ranges`, url: `http://localhost:${settings.internal.docstore.port}/project/${project_id}/ranges`,
json: true, json: true
}, },
callback callback
) )
@ -98,8 +98,8 @@ module.exports = DocstoreClient = {
json: { json: {
lines, lines,
version, version,
ranges, ranges
}, }
}, },
callback callback
) )
@ -111,7 +111,7 @@ module.exports = DocstoreClient = {
} }
return request.del( 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 callback
) )
@ -123,7 +123,7 @@ module.exports = DocstoreClient = {
} }
return request.post( 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 callback
) )
@ -135,7 +135,7 @@ module.exports = DocstoreClient = {
} }
return request.post( 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 callback
) )
@ -151,5 +151,5 @@ module.exports = DocstoreClient = {
callback(null, JSON.parse(data)) callback(null, JSON.parse(data))
}) })
.catch(callback) .catch(callback)
}, }
} }

View file

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

View file

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

View file

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

View file

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

View file

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