Merge pull request #11432 from overleaf/revert-11154-tm-lg-subscription-recurly-cache-name

Revert "Change property name for recurly status cache to recurlyStatus"

GitOrigin-RevId: 6870e421516fd705343f3e8651d8637f791063df
This commit is contained in:
Thomas 2023-01-24 14:21:19 +01:00 committed by Copybot
parent 0b6c69dc55
commit f6ffae02a9
4 changed files with 7 additions and 61 deletions

View file

@ -249,7 +249,7 @@ async function updateSubscriptionFromRecurly(
subscription.recurlySubscription_id = recurlySubscription.uuid
subscription.planCode = updatedPlanCode
subscription.recurlyStatus = {
subscription.recurly = {
state: recurlySubscription.state,
trialStartedAt: recurlySubscription.trial_started_at,
trialEndsAt: recurlySubscription.trial_ends_at,

View file

@ -193,7 +193,6 @@ 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
}
@ -355,7 +354,7 @@ async function getBestSubscription(user) {
individualSubscription &&
!individualSubscription.customAccount &&
individualSubscription.recurlySubscription_id &&
!individualSubscription.recurlyStatus?.state
!individualSubscription.recurly?.state
) {
const recurlySubscription = await RecurlyWrapper.promises.getSubscription(
individualSubscription.recurlySubscription_id,
@ -481,7 +480,7 @@ function _isPlanEqualOrBetter(planA, planB) {
function _getRemainingTrialDays(subscription) {
const now = new Date()
const trialEndDate = subscription.recurlyStatus?.trialEndsAt
const trialEndDate = subscription.recurly?.trialEndsAt
return trialEndDate && trialEndDate > now
? Math.ceil(
(trialEndDate.getTime() - now.getTime()) / (24 * 60 * 60 * 1000)

View file

@ -1,53 +0,0 @@
/* 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 } }
)
}

View file

@ -22,7 +22,7 @@ describe('SubscriptionViewModelBuilder', function () {
planCode: this.planCode,
plan: this.plan,
recurlySubscription_id: this.recurlySubscription_id,
recurlyStatus: {
recurly: {
state: 'active',
},
}
@ -46,7 +46,7 @@ describe('SubscriptionViewModelBuilder', function () {
this.groupSubscription = {
planCode: this.groupPlanCode,
plan: this.plan,
recurlyStatus: {
recurly: {
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.recurlyStatus.trialEndsAt = threeDaysLater
this.individualSubscription.recurly.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.recurlyStatus.trialEndsAt = threeHoursLater
this.individualSubscription.recurly.trialEndsAt = threeHoursLater
this.SubscriptionLocator.promises.getUsersSubscription
.withArgs(this.user)
.resolves(this.individualSubscription)