Merge pull request #16912 from overleaf/dp-mongoose-callback-referal-features

Promisify ReferalFeatures and ReferalFeaturesTests

GitOrigin-RevId: 25c1d80c5aea2883f62b95b8646a5670340c5cf2
This commit is contained in:
David
2024-02-09 09:07:18 +00:00
committed by Copybot
parent 144e22c209
commit d4e9d1bd89
2 changed files with 40 additions and 39 deletions
@@ -1,5 +1,6 @@
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
const { expect } = require('chai')
const modulePath = require('path').join(
__dirname,
'../../../../app/src/Features/Referal/ReferalFeatures.js'
@@ -15,7 +16,6 @@ describe('ReferalFeatures', function () {
'@overleaf/settings': (this.Settings = {}),
},
})
this.callback = sinon.stub()
this.referal_id = 'referal-id-123'
this.referal_medium = 'twitter'
this.user_id = 'user-id-123'
@@ -23,7 +23,7 @@ describe('ReferalFeatures', function () {
})
describe('getBonusFeatures', function () {
beforeEach(function () {
beforeEach(async function () {
this.refered_user_count = 3
this.Settings.bonus_features = {
3: {
@@ -37,23 +37,25 @@ describe('ReferalFeatures', function () {
features: { collaborators: 1, dropbox: false, versioning: false },
}
this.User.findOne = sinon.stub().callsArgWith(2, null, stubbedUser)
this.ReferalFeatures.getBonusFeatures(this.user_id, this.callback)
this.User.findOne = sinon.stub().returns({
exec: sinon.stub().resolves(stubbedUser),
})
this.features = await this.ReferalFeatures.promises.getBonusFeatures(
this.user_id
)
})
it('should get the users number of refered user', function () {
this.User.findOne.calledWith({ _id: this.user_id }).should.equal(true)
})
it('should call the callback with the features', function () {
this.callback
.calledWith(null, this.Settings.bonus_features[3])
.should.equal(true)
it('should return the features', function () {
expect(this.features).to.equal(this.Settings.bonus_features[3])
})
})
describe('when the user is not at a bonus level', function () {
beforeEach(function () {
beforeEach(async function () {
this.refered_user_count = 0
this.Settings.bonus_features = {
1: {
@@ -62,18 +64,23 @@ describe('ReferalFeatures', function () {
versioning: false,
},
}
this.User.findOne = sinon
.stub()
.callsArgWith(2, null, { refered_user_count: this.refered_user_count })
this.ReferalFeatures.getBonusFeatures(this.user_id, this.callback)
this.User.findOne = sinon.stub().returns({
exec: sinon
.stub()
.resolves({ refered_user_count: this.refered_user_count }),
})
this.features = await this.ReferalFeatures.promises.getBonusFeatures(
this.user_id
)
})
it('should get the users number of refered user', function () {
this.User.findOne.calledWith({ _id: this.user_id }).should.equal(true)
})
it('should call the callback with no features', function () {
this.callback.calledWith(null, {}).should.equal(true)
it('should return an empty feature set', function () {
expect(this.features).to.be.empty
})
})
})