mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
[misc] migrate the app to the native mongo driver
acceptance tests to follow in a separate commit.
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const app = require('../../../../app')
|
||||
const { waitForDb } = require('../../../../app/js/mongodb')
|
||||
require('logger-sharelatex')
|
||||
const logger = require('logger-sharelatex')
|
||||
const Settings = require('settings-sharelatex')
|
||||
@@ -29,9 +30,10 @@ module.exports = {
|
||||
return callback()
|
||||
} else if (this.initing) {
|
||||
return this.callbacks.push(callback)
|
||||
} else {
|
||||
this.initing = true
|
||||
this.callbacks.push(callback)
|
||||
}
|
||||
this.initing = true
|
||||
this.callbacks.push(callback)
|
||||
waitForDb().then(() => {
|
||||
return app.listen(
|
||||
__guard__(
|
||||
Settings.internal != null
|
||||
@@ -56,7 +58,7 @@ module.exports = {
|
||||
})()
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
function __guard__(value, transform) {
|
||||
|
||||
@@ -14,7 +14,7 @@ chai.should()
|
||||
const sinon = require('sinon')
|
||||
const modulePath = '../../../../app/js/MongoAWS.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const { ObjectId } = require('mongojs')
|
||||
const { ObjectId } = require('mongodb')
|
||||
const MemoryStream = require('memorystream')
|
||||
const zlib = require('zlib')
|
||||
|
||||
@@ -44,7 +44,7 @@ describe('MongoAWS', function () {
|
||||
'aws-sdk': (this.awssdk = {}),
|
||||
fs: (this.fs = {}),
|
||||
's3-streams': (this.S3S = {}),
|
||||
'./mongojs': { db: (this.db = {}), ObjectId },
|
||||
'./mongodb': { db: (this.db = {}), ObjectId },
|
||||
JSONStream: (this.JSONStream = {}),
|
||||
'readline-stream': (this.readline = sinon.stub()),
|
||||
'metrics-sharelatex': { inc() {} }
|
||||
@@ -92,7 +92,9 @@ describe('MongoAWS', function () {
|
||||
this.S3S.ReadStream = () =>
|
||||
MemoryStream.createReadStream(zbuf, { readable: true })
|
||||
this.db.docHistory = {}
|
||||
this.db.docHistory.insert = sinon.stub().callsArgWith(1, null, 'pack')
|
||||
this.db.docHistory.insertOne = sinon
|
||||
.stub()
|
||||
.yields(null, { insertedId: ObjectId() })
|
||||
|
||||
return this.MongoAWS.unArchivePack(
|
||||
this.project_id,
|
||||
@@ -107,7 +109,7 @@ describe('MongoAWS', function () {
|
||||
})
|
||||
|
||||
return it('should call db.docHistory.insert', function () {
|
||||
return this.db.docHistory.insert.called.should.equal(true)
|
||||
return this.db.docHistory.insertOne.called.should.equal(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -16,7 +16,7 @@ const { expect } = chai
|
||||
const modulePath = '../../../../app/js/MongoManager.js'
|
||||
const packModulePath = '../../../../app/js/PackManager.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const { ObjectId } = require('mongojs')
|
||||
const { ObjectId } = require('mongodb')
|
||||
const tk = require('timekeeper')
|
||||
|
||||
describe('MongoManager', function () {
|
||||
@@ -24,7 +24,7 @@ describe('MongoManager', function () {
|
||||
tk.freeze(new Date())
|
||||
this.MongoManager = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'./mongojs': { db: (this.db = {}), ObjectId },
|
||||
'./mongodb': { db: (this.db = {}), ObjectId },
|
||||
'./PackManager': (this.PackManager = {}),
|
||||
'metrics-sharelatex': { timeAsyncMethod() {} },
|
||||
'logger-sharelatex': { log() {} }
|
||||
@@ -156,7 +156,7 @@ describe('MongoManager', function () {
|
||||
|
||||
describe('backportProjectId', function () {
|
||||
beforeEach(function () {
|
||||
this.db.docHistory = { update: sinon.stub().callsArg(3) }
|
||||
this.db.docHistory = { updateMany: sinon.stub().yields() }
|
||||
return this.MongoManager.backportProjectId(
|
||||
this.project_id,
|
||||
this.doc_id,
|
||||
@@ -165,7 +165,7 @@ describe('MongoManager', function () {
|
||||
})
|
||||
|
||||
it("should insert the project_id into all entries for the doc_id which don't have it set", function () {
|
||||
return this.db.docHistory.update
|
||||
return this.db.docHistory.updateMany
|
||||
.calledWith(
|
||||
{
|
||||
doc_id: ObjectId(this.doc_id),
|
||||
@@ -173,9 +173,6 @@ describe('MongoManager', function () {
|
||||
},
|
||||
{
|
||||
$set: { project_id: ObjectId(this.project_id) }
|
||||
},
|
||||
{
|
||||
multi: true
|
||||
}
|
||||
)
|
||||
.should.equal(true)
|
||||
@@ -213,7 +210,7 @@ describe('MongoManager', function () {
|
||||
beforeEach(function () {
|
||||
this.metadata = { mock: 'metadata' }
|
||||
this.db.projectHistoryMetaData = {
|
||||
update: sinon.stub().callsArgWith(3, null, [this.metadata])
|
||||
updateOne: sinon.stub().yields()
|
||||
}
|
||||
return this.MongoManager.setProjectMetaData(
|
||||
this.project_id,
|
||||
@@ -223,7 +220,7 @@ describe('MongoManager', function () {
|
||||
})
|
||||
|
||||
it('should upsert the metadata into the DB', function () {
|
||||
return this.db.projectHistoryMetaData.update
|
||||
return this.db.projectHistoryMetaData.updateOne
|
||||
.calledWith(
|
||||
{
|
||||
project_id: ObjectId(this.project_id)
|
||||
|
||||
@@ -17,7 +17,7 @@ const should = chai.should()
|
||||
const { expect } = chai
|
||||
const modulePath = '../../../../app/js/PackManager.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const { ObjectId } = require('mongojs')
|
||||
const { ObjectId } = require('mongodb')
|
||||
const _ = require('underscore')
|
||||
|
||||
const tk = require('timekeeper')
|
||||
@@ -28,7 +28,7 @@ describe('PackManager', function () {
|
||||
this.PackManager = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
bson: require('bson'),
|
||||
'./mongojs': { db: (this.db = {}), ObjectId },
|
||||
'./mongodb': { db: (this.db = {}), ObjectId },
|
||||
'./LockManager': {},
|
||||
'./MongoAWS': {},
|
||||
'logger-sharelatex': { log: sinon.stub(), error: sinon.stub() },
|
||||
@@ -65,7 +65,7 @@ describe('PackManager', function () {
|
||||
{ op: 'op-4', meta: 'meta-4', v: 4 }
|
||||
]
|
||||
return (this.db.docHistory = {
|
||||
save: sinon.stub().callsArg(1),
|
||||
insertOne: sinon.stub().yields(),
|
||||
insert: sinon.stub().callsArg(1),
|
||||
updateOne: sinon.stub().yields(),
|
||||
findAndModify: sinon.stub().callsArg(1)
|
||||
@@ -390,7 +390,7 @@ describe('PackManager', function () {
|
||||
|
||||
return describe('for a small update that will expire', function () {
|
||||
it('should insert the update into mongo', function () {
|
||||
return this.db.docHistory.save
|
||||
return this.db.docHistory.insertOne
|
||||
.calledWithMatch({
|
||||
pack: this.newUpdates,
|
||||
project_id: ObjectId(this.project_id),
|
||||
@@ -403,7 +403,7 @@ describe('PackManager', function () {
|
||||
})
|
||||
|
||||
it('should set an expiry time in the future', function () {
|
||||
return this.db.docHistory.save
|
||||
return this.db.docHistory.insertOne
|
||||
.calledWithMatch({
|
||||
expiresAt: new Date(Date.now() + 7 * 24 * 3600 * 1000)
|
||||
})
|
||||
@@ -496,7 +496,7 @@ describe('PackManager', function () {
|
||||
|
||||
return describe('for a small update that will not expire', function () {
|
||||
it('should insert the update into mongo', function () {
|
||||
return this.db.docHistory.save
|
||||
return this.db.docHistory.insertOne
|
||||
.calledWithMatch({
|
||||
pack: this.newUpdates,
|
||||
project_id: ObjectId(this.project_id),
|
||||
@@ -509,7 +509,7 @@ describe('PackManager', function () {
|
||||
})
|
||||
|
||||
it('should not set any expiry time', function () {
|
||||
return this.db.docHistory.save
|
||||
return this.db.docHistory.insertOne
|
||||
.neverCalledWithMatch(sinon.match.has('expiresAt'))
|
||||
.should.equal(true)
|
||||
})
|
||||
@@ -546,7 +546,7 @@ describe('PackManager', function () {
|
||||
|
||||
return describe('for a small update that will expire', function () {
|
||||
it('should insert the update into mongo', function () {
|
||||
return this.db.docHistory.save
|
||||
return this.db.docHistory.insertOne
|
||||
.calledWithMatch({
|
||||
pack: this.newUpdates,
|
||||
project_id: ObjectId(this.project_id),
|
||||
@@ -559,7 +559,7 @@ describe('PackManager', function () {
|
||||
})
|
||||
|
||||
it('should set an expiry time in the future', function () {
|
||||
return this.db.docHistory.save
|
||||
return this.db.docHistory.insertOne
|
||||
.calledWithMatch({
|
||||
expiresAt: new Date(Date.now() + 7 * 24 * 3600 * 1000)
|
||||
})
|
||||
|
||||
@@ -17,6 +17,7 @@ const sinon = require('sinon')
|
||||
const chai = require('chai')
|
||||
const should = chai.should()
|
||||
const { expect } = chai
|
||||
const { ObjectId } = require('mongodb')
|
||||
const modulePath = '../../../../app/js/UpdatesManager.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
|
||||
@@ -864,7 +865,6 @@ describe('UpdatesManager', function () {
|
||||
describe('fillUserInfo', function () {
|
||||
describe('with valid users', function () {
|
||||
beforeEach(function (done) {
|
||||
const { ObjectId } = require('mongojs')
|
||||
this.user_id_1 = ObjectId().toString()
|
||||
this.user_id_2 = ObjectId().toString()
|
||||
this.updates = [
|
||||
|
||||
Reference in New Issue
Block a user