mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Change property name for recurly status cache to recurlyStatus (#11154)
* Change property name for recurly status cache to recurlyStatus Co-authored-by: Lucie Germain <lucie.germain@overleaf.com> GitOrigin-RevId: a1ff69d531519cd15b82ef72974e9702f43409ac
This commit is contained in:
parent
69fe1749ce
commit
0b6c69dc55
4 changed files with 61 additions and 7 deletions
|
@ -249,7 +249,7 @@ async function updateSubscriptionFromRecurly(
|
|||
|
||||
subscription.recurlySubscription_id = recurlySubscription.uuid
|
||||
subscription.planCode = updatedPlanCode
|
||||
subscription.recurly = {
|
||||
subscription.recurlyStatus = {
|
||||
state: recurlySubscription.state,
|
||||
trialStartedAt: recurlySubscription.trial_started_at,
|
||||
trialEndsAt: recurlySubscription.trial_ends_at,
|
||||
|
|
|
@ -193,6 +193,7 @@ function buildUsersSubscriptionViewModel(user, callback) {
|
|||
// Subscription DB object contains a recurly property, used to cache trial info
|
||||
// on the project-list. However, this can cause the wrong template to render,
|
||||
// if we do not have any subscription data from Recurly (recurlySubscription)
|
||||
// TODO: Delete this workaround once recurly cache property name migration rolled out.
|
||||
if (personalSubscription) {
|
||||
delete personalSubscription.recurly
|
||||
}
|
||||
|
@ -354,7 +355,7 @@ async function getBestSubscription(user) {
|
|||
individualSubscription &&
|
||||
!individualSubscription.customAccount &&
|
||||
individualSubscription.recurlySubscription_id &&
|
||||
!individualSubscription.recurly?.state
|
||||
!individualSubscription.recurlyStatus?.state
|
||||
) {
|
||||
const recurlySubscription = await RecurlyWrapper.promises.getSubscription(
|
||||
individualSubscription.recurlySubscription_id,
|
||||
|
@ -480,7 +481,7 @@ function _isPlanEqualOrBetter(planA, planB) {
|
|||
|
||||
function _getRemainingTrialDays(subscription) {
|
||||
const now = new Date()
|
||||
const trialEndDate = subscription.recurly?.trialEndsAt
|
||||
const trialEndDate = subscription.recurlyStatus?.trialEndsAt
|
||||
return trialEndDate && trialEndDate > now
|
||||
? Math.ceil(
|
||||
(trialEndDate.getTime() - now.getTime()) / (24 * 60 * 60 * 1000)
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/* eslint-disable no-unused-vars */
|
||||
|
||||
const Helpers = require('./lib/helpers')
|
||||
|
||||
exports.tags = ['saas']
|
||||
|
||||
exports.migrate = async client => {
|
||||
const { db } = client
|
||||
// 'recurly' -> 'recurlyStatus'
|
||||
await db.subscriptions.updateMany(
|
||||
{
|
||||
$and: [
|
||||
{ recurlyStatus: { $exists: false } },
|
||||
{ recurly: { $exists: true } },
|
||||
],
|
||||
},
|
||||
{ $rename: { recurly: 'recurlyStatus' } }
|
||||
)
|
||||
// some records may have already recached the recurly status, discard old cache
|
||||
await db.subscriptions.updateMany(
|
||||
{
|
||||
$and: [
|
||||
{ recurlyStatus: { $exists: true } },
|
||||
{ recurly: { $exists: true } },
|
||||
],
|
||||
},
|
||||
{ $unset: { recurly: 1 } }
|
||||
)
|
||||
}
|
||||
|
||||
exports.rollback = async client => {
|
||||
const { db } = client
|
||||
// 'recurlyStatus' -> 'recurly'
|
||||
await db.subscriptions.updateMany(
|
||||
{
|
||||
$and: [
|
||||
{ recurly: { $exists: false } },
|
||||
{ recurlyStatus: { $exists: true } },
|
||||
],
|
||||
},
|
||||
{ $rename: { recurlyStatus: 'recurly' } }
|
||||
)
|
||||
// some records may have already recached the recurly status, discard old cache
|
||||
await db.subscriptions.updateMany(
|
||||
{
|
||||
$and: [
|
||||
{ recurlyStatus: { $exists: true } },
|
||||
{ recurly: { $exists: true } },
|
||||
],
|
||||
},
|
||||
{ $unset: { recurlyStatus: 1 } }
|
||||
)
|
||||
}
|
|
@ -22,7 +22,7 @@ describe('SubscriptionViewModelBuilder', function () {
|
|||
planCode: this.planCode,
|
||||
plan: this.plan,
|
||||
recurlySubscription_id: this.recurlySubscription_id,
|
||||
recurly: {
|
||||
recurlyStatus: {
|
||||
state: 'active',
|
||||
},
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ describe('SubscriptionViewModelBuilder', function () {
|
|||
this.groupSubscription = {
|
||||
planCode: this.groupPlanCode,
|
||||
plan: this.plan,
|
||||
recurly: {
|
||||
recurlyStatus: {
|
||||
state: 'active',
|
||||
},
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ describe('SubscriptionViewModelBuilder', function () {
|
|||
it('should return a individual subscription with remaining free trial days', async function () {
|
||||
const threeDaysLater = new Date()
|
||||
threeDaysLater.setDate(threeDaysLater.getDate() + 3)
|
||||
this.individualSubscription.recurly.trialEndsAt = threeDaysLater
|
||||
this.individualSubscription.recurlyStatus.trialEndsAt = threeDaysLater
|
||||
this.SubscriptionLocator.promises.getUsersSubscription
|
||||
.withArgs(this.user)
|
||||
.resolves(this.individualSubscription)
|
||||
|
@ -189,7 +189,7 @@ describe('SubscriptionViewModelBuilder', function () {
|
|||
it('should return a individual subscription with free trial on last day', async function () {
|
||||
const threeHoursLater = new Date()
|
||||
threeHoursLater.setTime(threeHoursLater.getTime() + 3 * 60 * 60 * 1000)
|
||||
this.individualSubscription.recurly.trialEndsAt = threeHoursLater
|
||||
this.individualSubscription.recurlyStatus.trialEndsAt = threeHoursLater
|
||||
this.SubscriptionLocator.promises.getUsersSubscription
|
||||
.withArgs(this.user)
|
||||
.resolves(this.individualSubscription)
|
||||
|
|
Loading…
Reference in a new issue