Merge pull request #5088 from overleaf/em-queue-feature-refreshes
Perform some user refreshes in the background GitOrigin-RevId: 3aec73c827bf0f7de7bd9caa369dfc653eac5dd0
This commit is contained in:
Vendored
+1
@@ -60,6 +60,7 @@ function getSandboxedModuleRequires() {
|
||||
]
|
||||
const externalLibs = [
|
||||
'async',
|
||||
'bull',
|
||||
'json2csv',
|
||||
'lodash',
|
||||
'marked',
|
||||
|
||||
@@ -125,6 +125,7 @@ describe('SubscriptionUpdater', function () {
|
||||
|
||||
this.FeaturesUpdater = {
|
||||
promises: {
|
||||
scheduleRefreshFeatures: sinon.stub().resolves(),
|
||||
refreshFeatures: sinon.stub().resolves({}),
|
||||
},
|
||||
}
|
||||
@@ -249,9 +250,9 @@ describe('SubscriptionUpdater', function () {
|
||||
this.recurlySubscription.plan.plan_code
|
||||
)
|
||||
this.subscription.save.called.should.equal(true)
|
||||
this.FeaturesUpdater.promises.refreshFeatures
|
||||
.calledWith(this.adminUser._id)
|
||||
.should.equal(true)
|
||||
expect(
|
||||
this.FeaturesUpdater.promises.scheduleRefreshFeatures
|
||||
).to.have.been.calledWith(this.adminUser._id)
|
||||
})
|
||||
|
||||
it('should remove the subscription when expired', async function () {
|
||||
@@ -270,18 +271,18 @@ describe('SubscriptionUpdater', function () {
|
||||
this.subscription,
|
||||
{}
|
||||
)
|
||||
this.FeaturesUpdater.promises.refreshFeatures
|
||||
.calledWith(this.adminUser._id)
|
||||
.should.equal(true)
|
||||
this.FeaturesUpdater.promises.refreshFeatures
|
||||
.calledWith(this.allUserIds[0])
|
||||
.should.equal(true)
|
||||
this.FeaturesUpdater.promises.refreshFeatures
|
||||
.calledWith(this.allUserIds[1])
|
||||
.should.equal(true)
|
||||
this.FeaturesUpdater.promises.refreshFeatures
|
||||
.calledWith(this.allUserIds[2])
|
||||
.should.equal(true)
|
||||
expect(
|
||||
this.FeaturesUpdater.promises.scheduleRefreshFeatures
|
||||
).to.have.been.calledWith(this.adminUser._id)
|
||||
expect(
|
||||
this.FeaturesUpdater.promises.scheduleRefreshFeatures
|
||||
).to.have.been.calledWith(this.allUserIds[0])
|
||||
expect(
|
||||
this.FeaturesUpdater.promises.scheduleRefreshFeatures
|
||||
).to.have.been.calledWith(this.allUserIds[1])
|
||||
expect(
|
||||
this.FeaturesUpdater.promises.scheduleRefreshFeatures
|
||||
).to.have.been.calledWith(this.allUserIds[2])
|
||||
})
|
||||
|
||||
it('should set group to true and save how many members can be added to group', async function () {
|
||||
@@ -538,16 +539,16 @@ describe('SubscriptionUpdater', function () {
|
||||
})
|
||||
|
||||
it('should downgrade the admin_id', function () {
|
||||
this.FeaturesUpdater.promises.refreshFeatures
|
||||
.calledWith(this.subscription.admin_id)
|
||||
.should.equal(true)
|
||||
expect(
|
||||
this.FeaturesUpdater.promises.scheduleRefreshFeatures
|
||||
).to.have.been.calledWith(this.subscription.admin_id)
|
||||
})
|
||||
|
||||
it('should downgrade all of the members', function () {
|
||||
for (const userId of this.subscription.member_ids) {
|
||||
this.FeaturesUpdater.promises.refreshFeatures
|
||||
.calledWith(userId)
|
||||
.should.equal(true)
|
||||
expect(
|
||||
this.FeaturesUpdater.promises.scheduleRefreshFeatures
|
||||
).to.have.been.calledWith(userId)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const { expect } = require('chai')
|
||||
const {
|
||||
promisifyAll,
|
||||
promisifyClass,
|
||||
callbackifyMultiResult,
|
||||
} = require('../../../../app/src/util/promises')
|
||||
|
||||
@@ -48,7 +49,7 @@ describe('promisifyAll', function () {
|
||||
return a + b
|
||||
},
|
||||
}
|
||||
this.promisified = promisifyAll(this.module, { without: 'syncAdd' })
|
||||
this.promisified = promisifyAll(this.module, { without: ['syncAdd'] })
|
||||
})
|
||||
|
||||
it('does not promisify excluded functions', function () {
|
||||
@@ -88,6 +89,93 @@ describe('promisifyAll', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('promisifyClass', function () {
|
||||
describe('basic functionality', function () {
|
||||
before(function () {
|
||||
this.Class = class {
|
||||
constructor(a) {
|
||||
this.a = a
|
||||
}
|
||||
|
||||
asyncAdd(b, callback) {
|
||||
callback(null, this.a + b)
|
||||
}
|
||||
}
|
||||
this.Promisified = promisifyClass(this.Class)
|
||||
})
|
||||
|
||||
it('promisifies the class methods', async function () {
|
||||
const adder = new this.Promisified(1)
|
||||
const sum = await adder.asyncAdd(2)
|
||||
expect(sum).to.equal(3)
|
||||
})
|
||||
})
|
||||
|
||||
describe('without option', function () {
|
||||
before(function () {
|
||||
this.Class = class {
|
||||
constructor(a) {
|
||||
this.a = a
|
||||
}
|
||||
|
||||
asyncAdd(b, callback) {
|
||||
callback(null, this.a + b)
|
||||
}
|
||||
|
||||
syncAdd(b) {
|
||||
return this.a + b
|
||||
}
|
||||
}
|
||||
this.Promisified = promisifyClass(this.Class, { without: ['syncAdd'] })
|
||||
})
|
||||
|
||||
it('does not promisify excluded functions', function () {
|
||||
const adder = new this.Promisified(10)
|
||||
const sum = adder.syncAdd(12)
|
||||
expect(sum).to.equal(22)
|
||||
})
|
||||
|
||||
it('promisifies other functions', async function () {
|
||||
const adder = new this.Promisified(23)
|
||||
const sum = await adder.asyncAdd(3)
|
||||
expect(sum).to.equal(26)
|
||||
})
|
||||
})
|
||||
|
||||
describe('multiResult option', function () {
|
||||
before(function () {
|
||||
this.Class = class {
|
||||
constructor(a) {
|
||||
this.a = a
|
||||
}
|
||||
|
||||
asyncAdd(b, callback) {
|
||||
callback(null, this.a + b)
|
||||
}
|
||||
|
||||
asyncArithmetic(b, callback) {
|
||||
callback(null, this.a + b, this.a * b)
|
||||
}
|
||||
}
|
||||
this.Promisified = promisifyClass(this.Class, {
|
||||
multiResult: { asyncArithmetic: ['sum', 'product'] },
|
||||
})
|
||||
})
|
||||
|
||||
it('promisifies multi-result functions', async function () {
|
||||
const adder = new this.Promisified(3)
|
||||
const result = await adder.asyncArithmetic(6)
|
||||
expect(result).to.deep.equal({ sum: 9, product: 18 })
|
||||
})
|
||||
|
||||
it('promisifies other functions normally', async function () {
|
||||
const adder = new this.Promisified(6)
|
||||
const sum = await adder.asyncAdd(1)
|
||||
expect(sum).to.equal(7)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('callbackifyMultiResult', function () {
|
||||
it('callbackifies a multi-result function', function (done) {
|
||||
async function asyncArithmetic(a, b) {
|
||||
|
||||
Reference in New Issue
Block a user