Merge pull request #21957 from overleaf/ls-compute-immediate-charge-for-subscription-update

compute immediate charge for subscription update

GitOrigin-RevId: 4e5162660b26e6e9db69827a59aa8e0048fa7d5d
This commit is contained in:
Liangjun Song
2024-11-22 09:05:12 +00:00
committed by Copybot
parent 583923a4d0
commit ac8d8d6edc
6 changed files with 120 additions and 14 deletions
@@ -98,6 +98,7 @@ describe('RecurlyClient', function () {
this.client = client = {
getAccount: sinon.stub(),
listAccountSubscriptions: sinon.stub(),
previewSubscriptionChange: sinon.stub(),
}
this.recurly = {
errors: recurly.errors,
@@ -381,4 +382,65 @@ describe('RecurlyClient', function () {
)
})
})
describe('previewSubscriptionChange', function () {
describe('compute immediate charge', function () {
it('only has charge invoice', async function () {
this.client.previewSubscriptionChange.resolves({
plan: { code: 'test_code', name: 'test name' },
unitAmount: 0,
invoiceCollection: {
chargeInvoice: {
subtotal: 100,
tax: 20,
total: 120,
},
},
})
const { immediateCharge } =
await this.RecurlyClient.promises.previewSubscriptionChange(
new RecurlySubscriptionChangeRequest({
subscription: this.subscription,
timeframe: 'now',
planCode: 'new-plan',
})
)
expect(immediateCharge.subtotal).to.be.equal(100)
expect(immediateCharge.tax).to.be.equal(20)
expect(immediateCharge.total).to.be.equal(120)
})
it('credit invoice with imprecise float number', async function () {
this.client.previewSubscriptionChange.resolves({
plan: { code: 'test_code', name: 'test name' },
unitAmount: 0,
invoiceCollection: {
chargeInvoice: {
subtotal: 100.3,
tax: 20.3,
total: 120.3,
},
creditInvoices: [
{
subtotal: -20.1,
tax: -4.1,
total: -24.1,
},
],
},
})
const { immediateCharge } =
await this.RecurlyClient.promises.previewSubscriptionChange(
new RecurlySubscriptionChangeRequest({
subscription: this.subscription,
timeframe: 'now',
planCode: 'new-plan',
})
)
expect(immediateCharge.subtotal).to.be.equal(80.2)
expect(immediateCharge.tax).to.be.equal(16.2)
expect(immediateCharge.total).to.be.equal(96.2)
})
})
})
})