diff --git a/services/web/app/src/infrastructure/Mongoose.js b/services/web/app/src/infrastructure/Mongoose.js index 4f49ad6576..123538999b 100644 --- a/services/web/app/src/infrastructure/Mongoose.js +++ b/services/web/app/src/infrastructure/Mongoose.js @@ -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, { diff --git a/services/web/app/src/infrastructure/RedisWrapper.js b/services/web/app/src/infrastructure/RedisWrapper.js index 07b288e06b..cb41e6ff3b 100644 --- a/services/web/app/src/infrastructure/RedisWrapper.js +++ b/services/web/app/src/infrastructure/RedisWrapper.js @@ -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) } } diff --git a/services/web/app/src/models/Project.js b/services/web/app/src/models/Project.js index ccc4e08337..2d290567ba 100644 --- a/services/web/app/src/models/Project.js +++ b/services/web/app/src/models/Project.js @@ -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 diff --git a/services/web/test/unit/src/Security/RateLimiterMiddlewareTests.js b/services/web/test/unit/src/Security/RateLimiterMiddlewareTests.js index 57c369a8e4..81b76b50a7 100644 --- a/services/web/test/unit/src/Security/RateLimiterMiddlewareTests.js +++ b/services/web/test/unit/src/Security/RateLimiterMiddlewareTests.js @@ -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 } diff --git a/services/web/test/unit/src/helpers/models/Doc.js b/services/web/test/unit/src/helpers/models/Doc.js new file mode 100644 index 0000000000..ac7bed3683 --- /dev/null +++ b/services/web/test/unit/src/helpers/models/Doc.js @@ -0,0 +1,3 @@ +const mockModel = require('../MockModel') + +module.exports = mockModel('Doc') diff --git a/services/web/test/unit/src/helpers/models/File.js b/services/web/test/unit/src/helpers/models/File.js new file mode 100644 index 0000000000..3c57aa363e --- /dev/null +++ b/services/web/test/unit/src/helpers/models/File.js @@ -0,0 +1,3 @@ +const mockModel = require('../MockModel') + +module.exports = mockModel('File') diff --git a/services/web/test/unit/src/helpers/models/Folder.js b/services/web/test/unit/src/helpers/models/Folder.js new file mode 100644 index 0000000000..e6e40007df --- /dev/null +++ b/services/web/test/unit/src/helpers/models/Folder.js @@ -0,0 +1,6 @@ +const mockModel = require('../MockModel') + +module.exports = mockModel('Folder', { + './Doc': require('./Doc'), + './File': require('./File') +}) diff --git a/services/web/test/unit/src/helpers/models/Project.js b/services/web/test/unit/src/helpers/models/Project.js index 34b080b4fc..e12f163331 100644 --- a/services/web/test/unit/src/helpers/models/Project.js +++ b/services/web/test/unit/src/helpers/models/Project.js @@ -1,3 +1,5 @@ const mockModel = require('../MockModel') -module.exports = mockModel('Project') +module.exports = mockModel('Project', { + './Folder': require('./Folder') +}) diff --git a/services/web/test/unit/src/infrastructure/RedisWrapperTests.js b/services/web/test/unit/src/infrastructure/RedisWrapperTests.js deleted file mode 100644 index 2245a9bc47..0000000000 --- a/services/web/test/unit/src/infrastructure/RedisWrapperTests.js +++ /dev/null @@ -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) - }) - }) -})