mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #2583 from overleaf/spd-no-mongoredis-in-unittests
Clean up attempts to connect to Mongo and Redis in unit tests GitOrigin-RevId: 396813a04fc2aaf39a07e28613f8f1e0a7a2db8f
This commit is contained in:
parent
5c7251afce
commit
96cd1c869e
9 changed files with 37 additions and 77 deletions
|
@ -4,6 +4,15 @@ const logger = require('logger-sharelatex')
|
|||
|
||||
const POOL_SIZE = Settings.mongo.poolSize
|
||||
|
||||
if (
|
||||
typeof global.beforeEach === 'function' &&
|
||||
process.argv.join(' ').match(/unit/)
|
||||
) {
|
||||
throw new Error(
|
||||
'It looks like unit tests are running, but you are connecting to Mongo. Missing a stub?'
|
||||
)
|
||||
}
|
||||
|
||||
mongoose.connect(
|
||||
Settings.mongo.url,
|
||||
{
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
/* eslint-disable
|
||||
max-len,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
let Redis
|
||||
const Settings = require('settings-sharelatex')
|
||||
const redis = require('redis-sharelatex')
|
||||
|
||||
if (
|
||||
typeof global.beforeEach === 'function' &&
|
||||
process.argv.join(' ').match(/unit/)
|
||||
) {
|
||||
throw new Error(
|
||||
'It looks like unit tests are running, but you are connecting to Redis. Missing a stub?'
|
||||
)
|
||||
}
|
||||
|
||||
// A per-feature interface to Redis,
|
||||
// looks up the feature in `settings.redis`
|
||||
// and returns an appropriate client.
|
||||
// Necessary because we don't want to migrate web over
|
||||
// to redis-cluster all at once.
|
||||
module.exports = Redis = {
|
||||
module.exports = {
|
||||
// feature = 'websessions' | 'ratelimiter' | ...
|
||||
client(feature) {
|
||||
const redisFeatureSettings = Settings.redis[feature] || Settings.redis.web
|
||||
const rclient = redis.createClient(redisFeatureSettings)
|
||||
return rclient
|
||||
return redis.createClient(redisFeatureSettings)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const mongoose = require('../infrastructure/Mongoose')
|
||||
const _ = require('underscore')
|
||||
const { FolderSchema } = require('./Folder.js')
|
||||
const { FolderSchema } = require('./Folder')
|
||||
const Errors = require('../Features/Errors/Errors')
|
||||
|
||||
const concreteObjectId = mongoose.Types.ObjectId
|
||||
|
|
|
@ -40,6 +40,7 @@ describe('RateLimiterMiddleware', function() {
|
|||
'settings-sharelatex': (this.settings = {}),
|
||||
'../../infrastructure/RateLimiter': (this.RateLimiter = {}),
|
||||
'logger-sharelatex': (this.logger = { warn: sinon.stub() }),
|
||||
'./LoginRateLimiter': {},
|
||||
'../Authentication/AuthenticationController': this
|
||||
.AuthenticationController
|
||||
}
|
||||
|
|
3
services/web/test/unit/src/helpers/models/Doc.js
Normal file
3
services/web/test/unit/src/helpers/models/Doc.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
const mockModel = require('../MockModel')
|
||||
|
||||
module.exports = mockModel('Doc')
|
3
services/web/test/unit/src/helpers/models/File.js
Normal file
3
services/web/test/unit/src/helpers/models/File.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
const mockModel = require('../MockModel')
|
||||
|
||||
module.exports = mockModel('File')
|
6
services/web/test/unit/src/helpers/models/Folder.js
Normal file
6
services/web/test/unit/src/helpers/models/Folder.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
const mockModel = require('../MockModel')
|
||||
|
||||
module.exports = mockModel('Folder', {
|
||||
'./Doc': require('./Doc'),
|
||||
'./File': require('./File')
|
||||
})
|
|
@ -1,3 +1,5 @@
|
|||
const mockModel = require('../MockModel')
|
||||
|
||||
module.exports = mockModel('Project')
|
||||
module.exports = mockModel('Project', {
|
||||
'./Folder': require('./Folder')
|
||||
})
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
/* eslint-disable
|
||||
max-len,
|
||||
no-return-assign,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const { assert } = require('chai')
|
||||
const sinon = require('sinon')
|
||||
const chai = require('chai')
|
||||
const should = chai.should()
|
||||
const { expect } = chai
|
||||
const modulePath = '../../../../app/src/infrastructure/RedisWrapper.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe('RedisWrapper', function() {
|
||||
beforeEach(function() {
|
||||
this.settings = { redis: {} }
|
||||
this.redis = { createClient: sinon.stub() }
|
||||
return (this.RedisWrapper = SandboxedModule.require(modulePath, {
|
||||
globals: {
|
||||
console: console
|
||||
},
|
||||
requires: {
|
||||
'settings-sharelatex': this.settings,
|
||||
'redis-sharelatex': this.redis
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
describe('client', function() {
|
||||
it('should use the feature settings if present', function() {
|
||||
this.settings.redis = {
|
||||
my_feature: {
|
||||
port: '23456',
|
||||
host: 'otherhost',
|
||||
password: 'banana'
|
||||
}
|
||||
}
|
||||
this.RedisWrapper.client('my_feature')
|
||||
return this.redis.createClient
|
||||
.calledWith(this.settings.redis.my_feature)
|
||||
.should.equal(true)
|
||||
})
|
||||
|
||||
it('should use the web settings if feature not present', function() {
|
||||
this.settings.redis = {
|
||||
web: {
|
||||
port: '43',
|
||||
host: 'otherhost',
|
||||
password: 'banana'
|
||||
}
|
||||
}
|
||||
this.RedisWrapper.client('my_feature')
|
||||
return this.redis.createClient
|
||||
.calledWith(this.settings.redis.web)
|
||||
.should.equal(true)
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Reference in a new issue