Skip to content

Commit

Permalink
Fix check for $0 billing limit
Browse files Browse the repository at this point in the history
  • Loading branch information
zlwaterfield committed Aug 21, 2024
1 parent 795380b commit 5ba1b93
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
32 changes: 32 additions & 0 deletions cypress/e2e/billing-limits.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,38 @@ describe('Billing Limits', () => {
)
})

it('Show existing limit and allow user to change set to $0', () => {
cy.intercept('GET', '/api/billing/', (req) => {
req.reply({
statusCode: 200,
body: {
...require('../fixtures/api/billing/billing.json'),
custom_limits_usd: { product_analytics: 100 },
},
})
}).as('getBilling')
cy.visit('/organization/billing')
cy.wait('@getBilling')

cy.intercept('PATCH', '/api/billing/', (req) => {
req.reply({
statusCode: 200,
body: {
...require('../fixtures/api/billing/billing.json'),
custom_limits_usd: { product_analytics: 0 },
},
})
}).as('patchBilling')

cy.get('[data-attr="billing-limit-input-wrapper-product_analytics"]').scrollIntoView()
cy.get('[data-attr="billing-limit-set-product_analytics"]').should('be.visible')
cy.contains('Edit limit').click()
cy.get('[data-attr="billing-limit-input-product_analytics"]').clear().type('0')
cy.get('[data-attr="save-billing-limit-product_analytics"]').click()
cy.wait('@patchBilling')
cy.get('[data-attr="billing-limit-set-product_analytics"]').should('contain', 'You have a $0 billing limit set')
})

it('Show existing limit and allow user to remove it', () => {
cy.intercept('GET', '/api/billing/', (req) => {
req.reply({
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/scenes/billing/billingProductLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ export const billingProductLogic = kea<billingProductLogicType>([
return product.usage_key ? billing?.custom_limits_usd?.[product.usage_key] ?? null : null
},
],
hasCustomLimitSet: [(s) => [s.customLimitUsd], (customLimitUsd) => !!customLimitUsd && customLimitUsd >= 0],
hasCustomLimitSet: [
(s) => [s.customLimitUsd],
(customLimitUsd) => (!!customLimitUsd || customLimitUsd === 0) && customLimitUsd >= 0,
],
currentAndUpgradePlans: [
(_s, p) => [p.product],
(product) => {
Expand Down

0 comments on commit 5ba1b93

Please sign in to comment.