mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-13 21:53:43 +01:00
Convert files to ES modules
GitOrigin-RevId: 713430521d60f37ee20906bb2d5d0a56849a729d
This commit is contained in:
@@ -9,11 +9,11 @@
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const sinon = require('sinon')
|
||||
const modulePath = '../../../app/js/NotificationsController.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const assert = require('node:assert')
|
||||
import { stub } from 'sinon'
|
||||
import { require as _require } from 'sandboxed-module'
|
||||
import assert from 'node:assert'
|
||||
|
||||
const modulePath = '../../../app/js/NotificationsController.js'
|
||||
const userId = '51dc93e6fb625a261300003b'
|
||||
const notificationId = 'fb625a26f09d'
|
||||
const notificationKey = 'my-notification-key'
|
||||
@@ -22,11 +22,11 @@ describe('Notifications Controller', function () {
|
||||
beforeEach(function () {
|
||||
const self = this
|
||||
this.notifications = {}
|
||||
this.controller = SandboxedModule.require(modulePath, {
|
||||
this.controller = _require(modulePath, {
|
||||
requires: {
|
||||
'./Notifications': this.notifications,
|
||||
'@overleaf/metrics': {
|
||||
inc: sinon.stub(),
|
||||
inc: stub(),
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -42,9 +42,11 @@ describe('Notifications Controller', function () {
|
||||
|
||||
describe('getUserNotifications', function () {
|
||||
return it('should ask the notifications for the users notifications', function (done) {
|
||||
this.notifications.getUserNotifications = sinon
|
||||
.stub()
|
||||
.callsArgWith(1, null, this.stubbedNotification)
|
||||
this.notifications.getUserNotifications = stub().callsArgWith(
|
||||
1,
|
||||
null,
|
||||
this.stubbedNotification
|
||||
)
|
||||
const req = {
|
||||
params: {
|
||||
user_id: userId,
|
||||
@@ -64,7 +66,7 @@ describe('Notifications Controller', function () {
|
||||
|
||||
describe('addNotification', function () {
|
||||
return it('should tell the notifications to add the notification for the user', function (done) {
|
||||
this.notifications.addNotification = sinon.stub().callsArgWith(2)
|
||||
this.notifications.addNotification = stub().callsArgWith(2)
|
||||
const req = {
|
||||
params: {
|
||||
user_id: userId,
|
||||
@@ -85,7 +87,7 @@ describe('Notifications Controller', function () {
|
||||
|
||||
describe('removeNotificationId', function () {
|
||||
return it('should tell the notifications to mark the notification Id as read', function (done) {
|
||||
this.notifications.removeNotificationId = sinon.stub().callsArgWith(2)
|
||||
this.notifications.removeNotificationId = stub().callsArgWith(2)
|
||||
const req = {
|
||||
params: {
|
||||
user_id: userId,
|
||||
@@ -106,7 +108,7 @@ describe('Notifications Controller', function () {
|
||||
|
||||
describe('removeNotificationKey', function () {
|
||||
return it('should tell the notifications to mark the notification Key as read', function (done) {
|
||||
this.notifications.removeNotificationKey = sinon.stub().callsArgWith(2)
|
||||
this.notifications.removeNotificationKey = stub().callsArgWith(2)
|
||||
const req = {
|
||||
params: {
|
||||
user_id: userId,
|
||||
@@ -127,9 +129,7 @@ describe('Notifications Controller', function () {
|
||||
|
||||
return describe('removeNotificationByKeyOnly', function () {
|
||||
return it('should tell the notifications to mark the notification Key as read', function (done) {
|
||||
this.notifications.removeNotificationByKeyOnly = sinon
|
||||
.stub()
|
||||
.callsArgWith(1)
|
||||
this.notifications.removeNotificationByKeyOnly = stub().callsArgWith(1)
|
||||
const req = {
|
||||
params: {
|
||||
key: notificationKey,
|
||||
|
||||
@@ -10,24 +10,24 @@
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const sinon = require('sinon')
|
||||
const { expect } = require('chai')
|
||||
const modulePath = '../../../app/js/Notifications.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const assert = require('node:assert')
|
||||
const { ObjectId } = require('mongodb-legacy')
|
||||
import { stub, assert as _assert } from 'sinon'
|
||||
import { expect } from 'chai'
|
||||
import { require as _require } from 'sandboxed-module'
|
||||
import { deepEqual } from 'node:assert'
|
||||
import { ObjectId } from 'mongodb-legacy'
|
||||
|
||||
const modulePath = '../../../app/js/Notifications.js'
|
||||
const userId = '51dc93e6fb625a261300003b'
|
||||
const notificationId = '574ee8d6f40c3a244e704249'
|
||||
const notificationKey = 'notification-key'
|
||||
|
||||
describe('Notifications Tests', function () {
|
||||
beforeEach(function () {
|
||||
this.findToArrayStub = sinon.stub()
|
||||
this.findStub = sinon.stub().returns({ toArray: this.findToArrayStub })
|
||||
this.countStub = sinon.stub()
|
||||
this.updateOneStub = sinon.stub()
|
||||
this.deleteOneStub = sinon.stub()
|
||||
this.findToArrayStub = stub()
|
||||
this.findStub = stub().returns({ toArray: this.findToArrayStub })
|
||||
this.countStub = stub()
|
||||
this.updateOneStub = stub()
|
||||
this.deleteOneStub = stub()
|
||||
this.db = {
|
||||
notifications: {
|
||||
find: this.findStub,
|
||||
@@ -37,7 +37,7 @@ describe('Notifications Tests', function () {
|
||||
},
|
||||
}
|
||||
|
||||
this.notifications = SandboxedModule.require(modulePath, {
|
||||
this.notifications = _require(modulePath, {
|
||||
requires: {
|
||||
'@overleaf/settings': {},
|
||||
'./mongodb': { db: this.db, ObjectId },
|
||||
@@ -61,7 +61,7 @@ describe('Notifications Tests', function () {
|
||||
(err, notifications) => {
|
||||
if (err) return done(err)
|
||||
notifications.should.equal(this.stubbedNotificationArray)
|
||||
assert.deepEqual(this.findStub.args[0][0], {
|
||||
deepEqual(this.findStub.args[0][0], {
|
||||
user_id: new ObjectId(userId),
|
||||
templateKey: { $exists: true },
|
||||
})
|
||||
@@ -99,7 +99,7 @@ describe('Notifications Tests', function () {
|
||||
this.stubbedNotification,
|
||||
err => {
|
||||
expect(err).not.to.exist
|
||||
sinon.assert.calledWith(
|
||||
_assert.calledWith(
|
||||
this.updateOneStub,
|
||||
this.expectedQuery,
|
||||
{ $set: this.expectedDocument },
|
||||
@@ -121,7 +121,7 @@ describe('Notifications Tests', function () {
|
||||
this.stubbedNotification,
|
||||
err => {
|
||||
expect(err).not.to.exist
|
||||
sinon.assert.notCalled(this.updateOneStub)
|
||||
_assert.notCalled(this.updateOneStub)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
@@ -134,7 +134,7 @@ describe('Notifications Tests', function () {
|
||||
this.stubbedNotification,
|
||||
err => {
|
||||
expect(err).not.to.exist
|
||||
sinon.assert.calledWith(
|
||||
_assert.calledWith(
|
||||
this.updateOneStub,
|
||||
this.expectedQuery,
|
||||
{ $set: this.expectedDocument },
|
||||
@@ -174,7 +174,7 @@ describe('Notifications Tests', function () {
|
||||
this.stubbedNotification,
|
||||
err => {
|
||||
expect(err).not.to.exist
|
||||
sinon.assert.calledWith(
|
||||
_assert.calledWith(
|
||||
this.updateOneStub,
|
||||
this.expectedQuery,
|
||||
{ $set: this.expectedDocument },
|
||||
@@ -210,7 +210,7 @@ describe('Notifications Tests', function () {
|
||||
this.stubbedNotification,
|
||||
err => {
|
||||
;(err instanceof Error).should.equal(true)
|
||||
sinon.assert.notCalled(this.updateOneStub)
|
||||
_assert.notCalled(this.updateOneStub)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
@@ -234,8 +234,8 @@ describe('Notifications Tests', function () {
|
||||
const updateOperation = {
|
||||
$unset: { templateKey: true, messageOpts: true },
|
||||
}
|
||||
assert.deepEqual(this.updateOneStub.args[0][0], searchOps)
|
||||
assert.deepEqual(this.updateOneStub.args[0][1], updateOperation)
|
||||
deepEqual(this.updateOneStub.args[0][0], searchOps)
|
||||
deepEqual(this.updateOneStub.args[0][1], updateOperation)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
@@ -258,8 +258,8 @@ describe('Notifications Tests', function () {
|
||||
const updateOperation = {
|
||||
$unset: { templateKey: true },
|
||||
}
|
||||
assert.deepEqual(this.updateOneStub.args[0][0], searchOps)
|
||||
assert.deepEqual(this.updateOneStub.args[0][1], updateOperation)
|
||||
deepEqual(this.updateOneStub.args[0][0], searchOps)
|
||||
deepEqual(this.updateOneStub.args[0][1], updateOperation)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
@@ -276,8 +276,8 @@ describe('Notifications Tests', function () {
|
||||
if (err) return done(err)
|
||||
const searchOps = { key: notificationKey }
|
||||
const updateOperation = { $unset: { templateKey: true } }
|
||||
assert.deepEqual(this.updateOneStub.args[0][0], searchOps)
|
||||
assert.deepEqual(this.updateOneStub.args[0][1], updateOperation)
|
||||
deepEqual(this.updateOneStub.args[0][0], searchOps)
|
||||
deepEqual(this.updateOneStub.args[0][1], updateOperation)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
@@ -293,7 +293,7 @@ describe('Notifications Tests', function () {
|
||||
err => {
|
||||
if (err) return done(err)
|
||||
const searchOps = { key: notificationKey }
|
||||
assert.deepEqual(this.deleteOneStub.args[0][0], searchOps)
|
||||
deepEqual(this.deleteOneStub.args[0][0], searchOps)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user