mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
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:
@@ -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)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user