Merge pull request #15341 from overleaf/csh-issue-11625-mongo-ug-5-notifications

Upgrade mongodb module for notifications from 4.11.0 to 6.1.0

GitOrigin-RevId: 8e185d2d9128e2bc889bbc00a7f21fbee0f27daa
This commit is contained in:
Christopher Hoskin
2023-10-19 14:48:08 +01:00
committed by Copybot
parent 3b48b32754
commit 02fa5c3a99
5 changed files with 89 additions and 76 deletions

View File

@@ -18,11 +18,11 @@ const logger = require('@overleaf/logger')
module.exports = {
check(callback) {
const userId = ObjectId()
const userId = new ObjectId()
const cleanupNotifications = callback =>
db.notifications.remove({ user_id: userId }, callback)
let notificationKey = `smoke-test-notification-${ObjectId()}`
let notificationKey = `smoke-test-notification-${new ObjectId()}`
const getOpts = endPath => ({
url: `http://localhost:${port}/user/${userId}${endPath}`,
timeout: 5000,

View File

@@ -20,7 +20,7 @@ module.exports = Notifications = {
callback = function () {}
}
const query = {
user_id: ObjectId(userId),
user_id: new ObjectId(userId),
templateKey: { $exists: true },
}
db.notifications.find(query).toArray(callback)
@@ -31,7 +31,7 @@ module.exports = Notifications = {
callback = function () {}
}
const query = {
user_id: ObjectId(userId),
user_id: new ObjectId(userId),
key: notification.key,
}
return db.notifications.count(query, function (err, count) {
@@ -54,7 +54,7 @@ module.exports = Notifications = {
return callback()
}
const doc = {
user_id: ObjectId(userId),
user_id: new ObjectId(userId),
key: notification.key,
messageOpts: notification.messageOpts,
templateKey: notification.templateKey,
@@ -88,8 +88,8 @@ module.exports = Notifications = {
removeNotificationId(userId, notificationId, callback) {
const searchOps = {
user_id: ObjectId(userId),
_id: ObjectId(notificationId),
user_id: new ObjectId(userId),
_id: new ObjectId(notificationId),
}
const updateOperation = { $unset: { templateKey: true, messageOpts: true } }
db.notifications.updateOne(searchOps, updateOperation, callback)
@@ -97,7 +97,7 @@ module.exports = Notifications = {
removeNotificationKey(userId, notificationKey, callback) {
const searchOps = {
user_id: ObjectId(userId),
user_id: new ObjectId(userId),
key: notificationKey,
}
const updateOperation = { $unset: { templateKey: true } }

View File

@@ -26,7 +26,7 @@
"bunyan": "^1.8.15",
"express": "^4.18.2",
"method-override": "^3.0.0",
"mongodb": "^4.11.0",
"mongodb": "^6.1.0",
"request": "^2.88.2"
},
"devDependencies": {

View File

@@ -18,7 +18,7 @@ const assert = require('assert')
const { ObjectId } = require('mongodb')
const userId = '51dc93e6fb625a261300003b'
const notificationId = 'fb625a26f09d'
const notificationId = '574ee8d6f40c3a244e704249'
const notificationKey = 'notification-key'
describe('Notifications Tests', function () {
@@ -46,7 +46,7 @@ describe('Notifications Tests', function () {
})
this.stubbedNotification = {
user_id: ObjectId(userId),
user_id: new ObjectId(userId),
key: 'notification-key',
messageOpts: 'some info',
templateKey: 'template-key',
@@ -63,7 +63,7 @@ describe('Notifications Tests', function () {
if (err) return done(err)
notifications.should.equal(this.stubbedNotificationArray)
assert.deepEqual(this.findStub.args[0][0], {
user_id: ObjectId(userId),
user_id: new ObjectId(userId),
templateKey: { $exists: true },
})
return done()
@@ -75,7 +75,7 @@ describe('Notifications Tests', function () {
describe('addNotification', function () {
beforeEach(function () {
this.stubbedNotification = {
user_id: ObjectId(userId),
user_id: new ObjectId(userId),
key: 'notification-key',
messageOpts: 'some info',
templateKey: 'template-key',
@@ -150,7 +150,7 @@ describe('Notifications Tests', function () {
describe('when the notification is set to expire', function () {
beforeEach(function () {
this.stubbedNotification = {
user_id: ObjectId(userId),
user_id: new ObjectId(userId),
key: 'notification-key',
messageOpts: 'some info',
templateKey: 'template-key',
@@ -190,7 +190,7 @@ describe('Notifications Tests', function () {
return describe('when the notification has a nonsensical expires field', function () {
beforeEach(function () {
this.stubbedNotification = {
user_id: ObjectId(userId),
user_id: new ObjectId(userId),
key: 'notification-key',
messageOpts: 'some info',
templateKey: 'template-key',
@@ -229,8 +229,8 @@ describe('Notifications Tests', function () {
err => {
if (err) return done(err)
const searchOps = {
user_id: ObjectId(userId),
_id: ObjectId(notificationId),
user_id: new ObjectId(userId),
_id: new ObjectId(notificationId),
}
const updateOperation = {
$unset: { templateKey: true, messageOpts: true },
@@ -253,7 +253,7 @@ describe('Notifications Tests', function () {
err => {
if (err) return done(err)
const searchOps = {
user_id: ObjectId(userId),
user_id: new ObjectId(userId),
key: notificationKey,
}
const updateOperation = {