diff --git a/lib/recurly/pricing/subscription/calculations.js b/lib/recurly/pricing/subscription/calculations.js index 0659af4ff..bc2791db9 100644 --- a/lib/recurly/pricing/subscription/calculations.js +++ b/lib/recurly/pricing/subscription/calculations.js @@ -193,7 +193,10 @@ export default class Calculations { let unitPrice; // Price per unit, displayed on the label let totalPrice; // Total price for the addon - if (isTieredAddOn(addon)) { + if (this.planQuantity < 1) { + unitPrice = 0; + totalPrice = 0; + } else if (isTieredAddOn(addon)) { const currencyCode = this.pricing.currencyCode; totalPrice = getTieredPricingTotal(addon, selectedQuantity, currencyCode); unitPrice = getTieredPricingUnitAmount(addon, selectedQuantity, currencyCode); diff --git a/test/unit/pricing/subscription/subscription.test.js b/test/unit/pricing/subscription/subscription.test.js index e539a79e8..13b128cad 100644 --- a/test/unit/pricing/subscription/subscription.test.js +++ b/test/unit/pricing/subscription/subscription.test.js @@ -271,6 +271,24 @@ describe('Recurly.Pricing.Subscription', function () { }); }); }); + + describe('when the plan quantity is zero', () => { + it('calculates to zero', function (done) { + this.pricing + .plan('basic', { quantity: 0 }) + .addon('snarf', { quantity: 2 }) + .done(price => { + assert.equal(this.pricing.items.addons.length, 1); + assert.equal(this.pricing.items.addons[0].code, 'snarf'); + assert.equal(this.pricing.items.addons[0].quantity, 2); + assert.equal(price.now.addons, '0.00'); + assert.equal(price.next.addons, '0.00'); + assert.equal(price.now.total, '0.00'); + assert.equal(price.next.total, '0.00'); + done(); + }); + }); + }); }); describe('with usage addons', () => {