mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Merge pull request #9798 from overleaf/ta-em-gs-best-subscription-fix
Fix Best Subscription Check GitOrigin-RevId: a7ea5063d4287a421b96222763a59c15652c8d6f
This commit is contained in:
@@ -478,6 +478,7 @@ const ProjectController = {
|
||||
}
|
||||
SubscriptionViewModelBuilder.getBestSubscription(
|
||||
{ _id: userId },
|
||||
{ id: userId, ip: req.ip },
|
||||
(err, subscription) => {
|
||||
if (err) {
|
||||
// do not fail loading the project list when fetching the best subscription fails
|
||||
|
||||
@@ -340,7 +340,7 @@ function buildUsersSubscriptionViewModel(user, callback) {
|
||||
* @param {{_id: string}} user
|
||||
* @returns {Promise<Subscription>}
|
||||
*/
|
||||
async function getBestSubscription(user) {
|
||||
async function getBestSubscription(user, requesterData = {}) {
|
||||
let [
|
||||
individualSubscription,
|
||||
memberGroupSubscriptions,
|
||||
@@ -350,14 +350,19 @@ async function getBestSubscription(user) {
|
||||
SubscriptionLocator.promises.getMemberSubscriptions(user),
|
||||
InstitutionsGetter.promises.getCurrentInstitutionsWithLicence(user._id),
|
||||
])
|
||||
if (individualSubscription && !individualSubscription.recurly?.state) {
|
||||
if (
|
||||
individualSubscription &&
|
||||
individualSubscription.recurlySubscription_id &&
|
||||
!individualSubscription.recurly?.state
|
||||
) {
|
||||
const recurlySubscription = await RecurlyWrapper.promises.getSubscription(
|
||||
individualSubscription.recurlySubscription_id,
|
||||
{ includeAccount: true }
|
||||
)
|
||||
await SubscriptionUpdater.promises.updateSubscriptionFromRecurly(
|
||||
recurlySubscription,
|
||||
individualSubscription
|
||||
individualSubscription,
|
||||
requesterData
|
||||
)
|
||||
individualSubscription =
|
||||
await SubscriptionLocator.promises.getUsersSubscription(user)
|
||||
|
||||
@@ -27,6 +27,12 @@ describe('SubscriptionViewModelBuilder', function () {
|
||||
},
|
||||
}
|
||||
|
||||
this.individualCustomSubscription = {
|
||||
planCode: this.planCode,
|
||||
plan: this.plan,
|
||||
recurlySubscription_id: this.recurlySubscription_id,
|
||||
}
|
||||
|
||||
this.groupPlanCode = 'group_collaborator_monthly'
|
||||
this.groupPlanFeatures = {
|
||||
compileGroup: 'priority',
|
||||
@@ -123,6 +129,24 @@ describe('SubscriptionViewModelBuilder', function () {
|
||||
})
|
||||
|
||||
describe('with a individual subscription only', function () {
|
||||
it('should return a individual subscription when user has non-Recurly one', async function () {
|
||||
this.SubscriptionLocator.promises.getUsersSubscription
|
||||
.withArgs(this.user)
|
||||
.resolves(this.individualCustomSubscription)
|
||||
|
||||
const usersBestSubscription =
|
||||
await this.SubscriptionViewModelBuilder.promises.getBestSubscription(
|
||||
this.user
|
||||
)
|
||||
|
||||
assert.deepEqual(usersBestSubscription, {
|
||||
type: 'individual',
|
||||
subscription: this.individualCustomSubscription,
|
||||
plan: this.plan,
|
||||
remainingTrialDays: -1,
|
||||
})
|
||||
})
|
||||
|
||||
it('should return a individual subscription when user has an active one', async function () {
|
||||
this.SubscriptionLocator.promises.getUsersSubscription
|
||||
.withArgs(this.user)
|
||||
@@ -205,9 +229,11 @@ describe('SubscriptionViewModelBuilder', function () {
|
||||
})
|
||||
.resolves(this.recurlySubscription)
|
||||
|
||||
const requesterData = { id: this.user._id, ip: '1.2.3.4' }
|
||||
const usersBestSubscription =
|
||||
await this.SubscriptionViewModelBuilder.promises.getBestSubscription(
|
||||
this.user
|
||||
this.user,
|
||||
requesterData
|
||||
)
|
||||
|
||||
sinon.assert.calledWith(
|
||||
@@ -218,7 +244,8 @@ describe('SubscriptionViewModelBuilder', function () {
|
||||
sinon.assert.calledWith(
|
||||
this.SubscriptionUpdater.promises.updateSubscriptionFromRecurly,
|
||||
this.recurlySubscription,
|
||||
this.individualSubscriptionWithoutRecurly
|
||||
this.individualSubscriptionWithoutRecurly,
|
||||
requesterData
|
||||
)
|
||||
assert.deepEqual(usersBestSubscription, {
|
||||
type: 'individual',
|
||||
|
||||
Reference in New Issue
Block a user