Merge pull request #21556 from overleaf/em-subscription-change-interstitial
Add-on purchase preview page GitOrigin-RevId: 660e39a94e6112af020ea783d6acf01a19432605
This commit is contained in:
@@ -32,6 +32,7 @@ describe('RecurlyClient', function () {
|
||||
name: 'My Add-On',
|
||||
quantity: 1,
|
||||
unitPrice: 2,
|
||||
preTaxTotal: 2,
|
||||
}
|
||||
|
||||
this.subscription = {
|
||||
@@ -46,6 +47,8 @@ describe('RecurlyClient', function () {
|
||||
taxRate: 0.1,
|
||||
taxAmount: 1.5,
|
||||
total: 16.5,
|
||||
periodStart: new Date(),
|
||||
periodEnd: new Date(),
|
||||
}
|
||||
|
||||
this.recurlySubscription = {
|
||||
@@ -73,6 +76,8 @@ describe('RecurlyClient', function () {
|
||||
tax: this.subscription.taxAmount,
|
||||
total: this.subscription.total,
|
||||
currency: this.subscription.currency,
|
||||
currentPeriodStartedAt: this.subscription.periodStart,
|
||||
currentPeriodEndsAt: this.subscription.periodEnd,
|
||||
}
|
||||
|
||||
this.recurlySubscriptionChange = new recurly.SubscriptionChange()
|
||||
@@ -203,7 +208,7 @@ describe('RecurlyClient', function () {
|
||||
it('handles plan changes', async function () {
|
||||
await this.RecurlyClient.promises.applySubscriptionChangeRequest(
|
||||
new RecurlySubscriptionChangeRequest({
|
||||
subscriptionId: this.subscription.id,
|
||||
subscription: this.subscription,
|
||||
timeframe: 'now',
|
||||
planCode: 'new-plan',
|
||||
})
|
||||
@@ -217,7 +222,7 @@ describe('RecurlyClient', function () {
|
||||
it('handles add-on changes', async function () {
|
||||
await this.RecurlyClient.promises.applySubscriptionChangeRequest(
|
||||
new RecurlySubscriptionChangeRequest({
|
||||
subscriptionId: this.subscription.id,
|
||||
subscription: this.subscription,
|
||||
timeframe: 'now',
|
||||
addOnUpdates: [
|
||||
new RecurlySubscriptionAddOnUpdate({
|
||||
@@ -240,10 +245,9 @@ describe('RecurlyClient', function () {
|
||||
it('should throw any API errors', async function () {
|
||||
this.client.createSubscriptionChange = sinon.stub().throws()
|
||||
await expect(
|
||||
this.RecurlyClient.promises.applySubscriptionChangeRequest(
|
||||
this.subscription.id,
|
||||
{}
|
||||
)
|
||||
this.RecurlyClient.promises.applySubscriptionChangeRequest({
|
||||
subscription: this.subscription,
|
||||
})
|
||||
).to.eventually.be.rejectedWith(Error)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -5,6 +5,8 @@ const { expect } = require('chai')
|
||||
const Errors = require('../../../../app/src/Features/Subscription/Errors')
|
||||
const {
|
||||
RecurlySubscriptionChangeRequest,
|
||||
RecurlySubscriptionChange,
|
||||
RecurlySubscription,
|
||||
} = require('../../../../app/src/Features/Subscription/RecurlyEntities')
|
||||
|
||||
const MODULE_PATH = '../../../../app/src/Features/Subscription/RecurlyEntities'
|
||||
@@ -71,7 +73,7 @@ describe('RecurlyEntities', function () {
|
||||
this.subscription.getRequestForPlanChange('premium-plan')
|
||||
expect(changeRequest).to.deep.equal(
|
||||
new RecurlySubscriptionChangeRequest({
|
||||
subscriptionId: this.subscription.id,
|
||||
subscription: this.subscription,
|
||||
timeframe: 'now',
|
||||
planCode: 'premium-plan',
|
||||
})
|
||||
@@ -84,7 +86,7 @@ describe('RecurlyEntities', function () {
|
||||
this.subscription.getRequestForPlanChange('cheap-plan')
|
||||
expect(changeRequest).to.deep.equal(
|
||||
new RecurlySubscriptionChangeRequest({
|
||||
subscriptionId: this.subscription.id,
|
||||
subscription: this.subscription,
|
||||
timeframe: 'term_end',
|
||||
planCode: 'cheap-plan',
|
||||
})
|
||||
@@ -102,7 +104,7 @@ describe('RecurlyEntities', function () {
|
||||
this.subscription.getRequestForAddOnPurchase('another-add-on')
|
||||
expect(changeRequest).to.deep.equal(
|
||||
new RecurlySubscriptionChangeRequest({
|
||||
subscriptionId: this.subscription.id,
|
||||
subscription: this.subscription,
|
||||
timeframe: 'now',
|
||||
addOnUpdates: [
|
||||
new RecurlySubscriptionAddOnUpdate({
|
||||
@@ -133,7 +135,7 @@ describe('RecurlyEntities', function () {
|
||||
)
|
||||
expect(changeRequest).to.deep.equal(
|
||||
new RecurlySubscriptionChangeRequest({
|
||||
subscriptionId: this.subscription.id,
|
||||
subscription: this.subscription,
|
||||
timeframe: 'term_end',
|
||||
addOnUpdates: [],
|
||||
})
|
||||
@@ -180,7 +182,7 @@ describe('RecurlyEntities', function () {
|
||||
this.subscription.getRequestForAddOnPurchase('some-add-on')
|
||||
expect(changeRequest).to.deep.equal(
|
||||
new RecurlySubscriptionChangeRequest({
|
||||
subscriptionId: this.subscription.id,
|
||||
subscription: this.subscription,
|
||||
timeframe: 'now',
|
||||
addOnUpdates: [
|
||||
new RecurlySubscriptionAddOnUpdate({
|
||||
@@ -203,4 +205,34 @@ describe('RecurlyEntities', function () {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('RecurlySubscriptionChange', function () {
|
||||
describe('constructor', function () {
|
||||
it('rounds the amounts when calculating the taxes', function () {
|
||||
const subscription = new RecurlySubscription({
|
||||
id: 'subscription-id',
|
||||
userId: 'user-id',
|
||||
planCode: 'premium-plan',
|
||||
planName: 'Premium plan',
|
||||
planPrice: 10,
|
||||
subtotal: 10,
|
||||
taxRate: 0.15,
|
||||
taxAmount: 1.5,
|
||||
currency: 'USD',
|
||||
total: 11.5,
|
||||
periodStart: new Date(),
|
||||
periodEnd: new Date(),
|
||||
})
|
||||
const change = new RecurlySubscriptionChange({
|
||||
subscription,
|
||||
nextPlanCode: 'promotional-plan',
|
||||
nextPlanName: 'Promotial plan',
|
||||
nextPlanPrice: 8.99,
|
||||
nextAddOns: [],
|
||||
})
|
||||
expect(change.tax).to.equal(1.35)
|
||||
expect(change.total).to.equal(10.34)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -122,6 +122,12 @@ describe('SubscriptionHandler', function () {
|
||||
},
|
||||
}
|
||||
|
||||
this.SubscriptionLocator = {
|
||||
promises: {
|
||||
getUsersSubscription: sinon.stub().resolves(this.subscription),
|
||||
},
|
||||
}
|
||||
|
||||
this.EmailHandler = {
|
||||
sendEmail: sinon.stub(),
|
||||
sendDeferredEmail: sinon.stub(),
|
||||
@@ -142,6 +148,7 @@ describe('SubscriptionHandler', function () {
|
||||
User: this.User,
|
||||
},
|
||||
'./SubscriptionUpdater': this.SubscriptionUpdater,
|
||||
'./SubscriptionLocator': this.SubscriptionLocator,
|
||||
'./LimitationsManager': this.LimitationsManager,
|
||||
'../Email/EmailHandler': this.EmailHandler,
|
||||
'../Analytics/AnalyticsManager': this.AnalyticsManager,
|
||||
@@ -267,7 +274,7 @@ describe('SubscriptionHandler', function () {
|
||||
this.RecurlyClient.promises.applySubscriptionChangeRequest
|
||||
).to.have.been.calledWith(
|
||||
new RecurlySubscriptionChangeRequest({
|
||||
subscriptionId: this.subscription.recurlySubscription_id,
|
||||
subscription: this.activeRecurlyClientSubscription,
|
||||
timeframe: 'now',
|
||||
planCode: this.plan_code,
|
||||
})
|
||||
@@ -380,7 +387,7 @@ describe('SubscriptionHandler', function () {
|
||||
this.RecurlyClient.promises.applySubscriptionChangeRequest
|
||||
).to.be.calledWith(
|
||||
new RecurlySubscriptionChangeRequest({
|
||||
subscriptionId: this.subscription.recurlySubscription_id,
|
||||
subscription: this.activeRecurlyClientSubscription,
|
||||
timeframe: 'now',
|
||||
planCode: this.plan_code,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user