Merge pull request #12205 from overleaf/em-camel-case-docstore

Camel case variables in docstore

GitOrigin-RevId: e6c2015cfb63ce125fd32ba8b4f904712b2bb9aa
This commit is contained in:
Eric Mc Sween
2023-03-17 09:05:12 +00:00
committed by Copybot
parent df3c7e48ab
commit 49f1312b27
8 changed files with 157 additions and 188 deletions
@@ -1,5 +1,4 @@
/* eslint-disable
camelcase,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
@@ -113,10 +112,10 @@ describe('Archiving', function () {
return DocstoreClient.getS3Doc(
this.project_id,
doc._id,
(error, s3_doc) => {
(error, s3Doc) => {
if (error) return callback(error)
s3_doc.lines.should.deep.equal(doc.lines)
s3_doc.ranges.should.deep.equal(doc.ranges)
s3Doc.lines.should.deep.equal(doc.lines)
s3Doc.ranges.should.deep.equal(doc.ranges)
callback()
}
)
@@ -130,8 +129,8 @@ describe('Archiving', function () {
before(function (done) {
return DocstoreClient.getAllDocs(
this.project_id,
(error, res, fetched_docs) => {
this.fetched_docs = fetched_docs
(error, res, fetchedDocs) => {
this.fetched_docs = fetchedDocs
if (error != null) {
throw error
}
@@ -231,12 +230,12 @@ describe('Archiving', function () {
return DocstoreClient.getS3Doc(
this.project_id,
this.doc._id,
(error, s3_doc) => {
(error, s3Doc) => {
if (error != null) {
throw error
}
s3_doc.lines.should.deep.equal(this.doc.lines)
s3_doc.ranges.should.deep.equal(this.doc.ranges)
s3Doc.lines.should.deep.equal(this.doc.lines)
s3Doc.ranges.should.deep.equal(this.doc.ranges)
return done()
}
)
@@ -246,8 +245,8 @@ describe('Archiving', function () {
beforeEach(function (done) {
return DocstoreClient.getAllDocs(
this.project_id,
(error, res, fetched_docs) => {
this.fetched_docs = fetched_docs
(error, res, fetchedDocs) => {
this.fetched_docs = fetchedDocs
if (error != null) {
throw error
}
@@ -291,8 +290,8 @@ describe('Archiving', function () {
beforeEach(function (done) {
DocstoreClient.getAllDocs(
this.project_id,
(error, res, fetched_docs) => {
this.fetched_docs = fetched_docs
(error, res, fetchedDocs) => {
this.fetched_docs = fetchedDocs
if (error) {
return done(error)
}
@@ -375,18 +374,14 @@ describe('Archiving', function () {
})
it('should set the doc in s3 correctly', function (done) {
DocstoreClient.getS3Doc(
this.project_id,
this.doc._id,
(error, s3_doc) => {
if (error) {
return done(error)
}
s3_doc.lines.should.deep.equal(this.doc.lines)
s3_doc.ranges.should.deep.equal(this.doc.ranges)
done()
DocstoreClient.getS3Doc(this.project_id, this.doc._id, (error, s3Doc) => {
if (error) {
return done(error)
}
)
s3Doc.lines.should.deep.equal(this.doc.lines)
s3Doc.ranges.should.deep.equal(this.doc.ranges)
done()
})
})
})
@@ -395,12 +390,12 @@ describe('Archiving', function () {
this.project_id = ObjectId()
this.timeout(1000 * 30)
const quarterMegInBytes = 250000
const big_line = require('crypto')
const bigLine = require('crypto')
.randomBytes(quarterMegInBytes)
.toString('hex')
this.doc = {
_id: ObjectId(),
lines: [big_line, big_line, big_line, big_line],
lines: [bigLine, bigLine, bigLine, bigLine],
ranges: {},
version: 2,
}
@@ -446,12 +441,12 @@ describe('Archiving', function () {
return DocstoreClient.getS3Doc(
this.project_id,
this.doc._id,
(error, s3_doc) => {
(error, s3Doc) => {
if (error != null) {
throw error
}
s3_doc.lines.should.deep.equal(this.doc.lines)
s3_doc.ranges.should.deep.equal(this.doc.ranges)
s3Doc.lines.should.deep.equal(this.doc.lines)
s3Doc.ranges.should.deep.equal(this.doc.ranges)
return done()
}
)
@@ -461,8 +456,8 @@ describe('Archiving', function () {
before(function (done) {
return DocstoreClient.getAllDocs(
this.project_id,
(error, res, fetched_docs) => {
this.fetched_docs = fetched_docs
(error, res, fetchedDocs) => {
this.fetched_docs = fetchedDocs
if (error != null) {
throw error
}
@@ -920,12 +915,12 @@ describe('Archiving', function () {
return DocstoreClient.getS3Doc(
this.project_id,
this.doc._id,
(error, s3_doc) => {
(error, s3Doc) => {
if (error != null) {
throw error
}
s3_doc.lines.should.deep.equal(this.doc.lines)
s3_doc.ranges.should.deep.equal(this.doc.ranges)
s3Doc.lines.should.deep.equal(this.doc.lines)
s3Doc.ranges.should.deep.equal(this.doc.ranges)
return done()
}
)
@@ -935,8 +930,8 @@ describe('Archiving', function () {
before(function (done) {
return DocstoreClient.getAllDocs(
this.project_id,
(error, res, fetched_docs) => {
this.fetched_docs = fetched_docs
(error, res, fetchedDocs) => {
this.fetched_docs = fetchedDocs
if (error != null) {
throw error
}
@@ -1039,13 +1034,13 @@ describe('Archiving', function () {
return DocstoreClient.getS3Doc(
this.project_id,
this.doc._id,
(error, s3_doc) => {
(error, s3Doc) => {
if (error != null) {
throw error
}
s3_doc.lines.should.deep.equal(this.doc.lines)
s3Doc.lines.should.deep.equal(this.doc.lines)
const ranges = JSON.parse(JSON.stringify(this.doc.ranges)) // ObjectId -> String
s3_doc.ranges.should.deep.equal(ranges)
s3Doc.ranges.should.deep.equal(ranges)
return done()
}
)
@@ -1055,8 +1050,8 @@ describe('Archiving', function () {
before(function (done) {
return DocstoreClient.getAllDocs(
this.project_id,
(error, res, fetched_docs) => {
this.fetched_docs = fetched_docs
(error, res, fetchedDocs) => {
this.fetched_docs = fetchedDocs
if (error != null) {
throw error
}
@@ -1136,12 +1131,12 @@ describe('Archiving', function () {
return DocstoreClient.getS3Doc(
this.project_id,
this.doc._id,
(error, s3_doc) => {
(error, s3Doc) => {
if (error != null) {
throw error
}
s3_doc.lines.should.deep.equal(this.doc.lines)
s3_doc.ranges.should.deep.equal(this.doc.ranges)
s3Doc.lines.should.deep.equal(this.doc.lines)
s3Doc.ranges.should.deep.equal(this.doc.ranges)
return done()
}
)
@@ -1151,8 +1146,8 @@ describe('Archiving', function () {
before(function (done) {
return DocstoreClient.getAllDocs(
this.project_id,
(error, res, fetched_docs) => {
this.fetched_docs = fetched_docs
(error, res, fetchedDocs) => {
this.fetched_docs = fetchedDocs
if (error != null) {
throw error
}
@@ -1202,8 +1197,8 @@ describe('Archiving', function () {
}
DocstoreClient.getAllDocs(
this.project_id,
(error, res, fetched_docs) => {
this.fetched_docs = fetched_docs
(error, res, fetchedDocs) => {
this.fetched_docs = fetchedDocs
if (error != null) {
throw error
}
@@ -1,5 +1,4 @@
/* eslint-disable
camelcase,
no-unused-vars,
*/
// TODO: This file was created by bulk-decaffeinate.
@@ -70,10 +69,10 @@ describe('Getting a doc', function () {
describe('when the doc does not exist', function () {
return it('should return a 404', function (done) {
const missing_doc_id = ObjectId()
const missingDocId = ObjectId()
return DocstoreClient.getDoc(
this.project_id,
missing_doc_id,
missingDocId,
{},
(error, res, doc) => {
if (error) return done(error)
@@ -1,5 +1,4 @@
/* eslint-disable
camelcase,
no-dupe-keys,
no-return-assign,
no-unused-vars,
@@ -254,11 +253,7 @@ describe('DocManager', function () {
inS3: true,
}
this.MongoManager.findDoc.yields(null, this.doc)
this.DocArchiveManager.unarchiveDoc = (
project_id,
doc_id,
callback
) => {
this.DocArchiveManager.unarchiveDoc = (projectId, docId, callback) => {
this.doc.inS3 = false
return callback()
}
@@ -497,8 +492,8 @@ describe('DocManager', function () {
it('should log a warning', function () {
expect(this.logger.warn).to.have.been.calledWith(
sinon.match({
project_id: this.project_id,
doc_id: this.doc_id,
projectId: this.project_id,
docId: this.doc_id,
err: this.err,
}),
'archiving a single doc in the background failed'
@@ -1,5 +1,4 @@
/* eslint-disable
camelcase,
no-return-assign,
no-unused-vars,
*/
@@ -32,110 +31,110 @@ describe('RangeManager', function () {
describe('jsonRangesToMongo', function () {
it('should convert ObjectIds and dates to proper objects', function () {
const change_id = ObjectId().toString()
const comment_id = ObjectId().toString()
const user_id = ObjectId().toString()
const thread_id = ObjectId().toString()
const changeId = ObjectId().toString()
const commentId = ObjectId().toString()
const userId = ObjectId().toString()
const threadId = ObjectId().toString()
const ts = new Date().toJSON()
return this.RangeManager.jsonRangesToMongo({
changes: [
{
id: change_id,
id: changeId,
op: { i: 'foo', p: 3 },
metadata: {
user_id,
user_id: userId,
ts,
},
},
],
comments: [
{
id: comment_id,
op: { c: 'foo', p: 3, t: thread_id },
id: commentId,
op: { c: 'foo', p: 3, t: threadId },
},
],
}).should.deep.equal({
changes: [
{
id: ObjectId(change_id),
id: ObjectId(changeId),
op: { i: 'foo', p: 3 },
metadata: {
user_id: ObjectId(user_id),
user_id: ObjectId(userId),
ts: new Date(ts),
},
},
],
comments: [
{
id: ObjectId(comment_id),
op: { c: 'foo', p: 3, t: ObjectId(thread_id) },
id: ObjectId(commentId),
op: { c: 'foo', p: 3, t: ObjectId(threadId) },
},
],
})
})
it('should leave malformed ObjectIds as they are', function () {
const change_id = 'foo'
const comment_id = 'bar'
const user_id = 'baz'
const changeId = 'foo'
const commentId = 'bar'
const userId = 'baz'
return this.RangeManager.jsonRangesToMongo({
changes: [
{
id: change_id,
id: changeId,
metadata: {
user_id,
user_id: userId,
},
},
],
comments: [
{
id: comment_id,
id: commentId,
},
],
}).should.deep.equal({
changes: [
{
id: change_id,
id: changeId,
metadata: {
user_id,
user_id: userId,
},
},
],
comments: [
{
id: comment_id,
id: commentId,
},
],
})
})
return it('should be consistent when transformed through json -> mongo -> json', function () {
const change_id = ObjectId().toString()
const comment_id = ObjectId().toString()
const user_id = ObjectId().toString()
const thread_id = ObjectId().toString()
const changeId = ObjectId().toString()
const commentId = ObjectId().toString()
const userId = ObjectId().toString()
const threadId = ObjectId().toString()
const ts = new Date().toJSON()
const ranges1 = {
changes: [
{
id: change_id,
id: changeId,
op: { i: 'foo', p: 3 },
metadata: {
user_id,
user_id: userId,
ts,
},
},
],
comments: [
{
id: comment_id,
op: { c: 'foo', p: 3, t: thread_id },
id: commentId,
op: { c: 'foo', p: 3, t: threadId },
},
],
}
const ranges1_copy = JSON.parse(JSON.stringify(ranges1)) // jsonRangesToMongo modifies in place
const ranges1Copy = JSON.parse(JSON.stringify(ranges1)) // jsonRangesToMongo modifies in place
const ranges2 = JSON.parse(
JSON.stringify(this.RangeManager.jsonRangesToMongo(ranges1_copy))
JSON.stringify(this.RangeManager.jsonRangesToMongo(ranges1Copy))
)
return ranges1.should.deep.equal(ranges2)
})