From 9789a158a72989641df15c821eb5c1d9faadfce0 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Wed, 23 Sep 2020 10:50:14 +0200 Subject: [PATCH] Merge pull request #3183 from overleaf/jpa-add-missing-db-stub [misc] unit tests: add missing module stubs for (transient) db imports GitOrigin-RevId: 9a16f1ab9b42608d839922fb339189697bc9ed22 --- services/web/app/src/infrastructure/mongojs.js | 10 ++++++++++ .../unit/src/Subscription/SubscriptionUpdaterTests.js | 1 + 2 files changed, 11 insertions(+) diff --git a/services/web/app/src/infrastructure/mongojs.js b/services/web/app/src/infrastructure/mongojs.js index e3a1e5ae49..88d540e2b7 100644 --- a/services/web/app/src/infrastructure/mongojs.js +++ b/services/web/app/src/infrastructure/mongojs.js @@ -5,6 +5,16 @@ // Fix any style issues and re-enable lint. const Settings = require('settings-sharelatex') const mongojs = require('mongojs') + +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?' + ) +} + const db = mongojs(Settings.mongo.url, [ 'projects', 'users', diff --git a/services/web/test/unit/src/Subscription/SubscriptionUpdaterTests.js b/services/web/test/unit/src/Subscription/SubscriptionUpdaterTests.js index 82708a533d..31bcba6ce0 100644 --- a/services/web/test/unit/src/Subscription/SubscriptionUpdaterTests.js +++ b/services/web/test/unit/src/Subscription/SubscriptionUpdaterTests.js @@ -110,6 +110,7 @@ describe('SubscriptionUpdater', function() { warn() {} }, 'settings-sharelatex': this.Settings, + '../../infrastructure/mongojs': { db: {}, ObjectId }, './FeaturesUpdater': this.FeaturesUpdater, '../../models/DeletedSubscription': { DeletedSubscription: this.DeletedSubscription