Skip to content

Commit

Permalink
feat: plan override when creating a subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
ansmonjol committed Oct 9, 2023
1 parent c87ec47 commit 4c5ad74
Show file tree
Hide file tree
Showing 37 changed files with 3,266 additions and 2,860 deletions.
62 changes: 31 additions & 31 deletions cypress/e2e/10-resources/t60-coupons-create-edit-apply.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,62 @@ const couponName = `Coupon-${Math.round(Math.random() * 10000)}`
describe('Coupons', () => {
it('should be able create a coupon with plan limitation', () => {
cy.visit('/coupons')
cy.get(`[data-test="add-coupon"]`).click()
cy.get(`[data-test="add-coupon"]`).click({ force: true })
cy.get('[data-test="submit"]').should('be.disabled')
cy.get('input[name="name"]').type(couponName)
cy.get('input[name="code"]').type(couponName)
cy.get('input[name="amountCents"]').type('30')
cy.get('[data-test="submit"]').should('be.enabled')

// Set plan limitation
cy.get('[data-test="checkbox-hasPlanOrBillableMetricLimit"]').click()
cy.get('[data-test="add-plan-limit"]').click()
cy.get('input[name="selectedPlan"]').click()
cy.get('[data-option-index="0"]').click()
cy.get('[data-test="submitAddPlanToCouponDialog"]').click()
cy.get('[data-test="checkbox-hasPlanOrBillableMetricLimit"]').click({ force: true })
cy.get('[data-test="add-plan-limit"]').click({ force: true })
cy.get('input[name="selectedPlan"]').click({ force: true })
cy.get('[data-option-index="0"]').click({ force: true })
cy.get('[data-test="submitAddPlanToCouponDialog"]').click({ force: true })

// Submit form
cy.get('[data-test="submit"]').click()
cy.get('[data-test="submit"]').click({ force: true })
cy.get(`[data-test="${couponName}"]`).should('exist')
})

it('should be able to edit the same coupon', () => {
cy.visit('/coupons')
cy.get(`[data-test="${couponName}"]`).click()
cy.get(`[data-test="${couponName}"]`).click({ force: true })
cy.get('[data-test="submit"]').should('be.disabled')
cy.get('[data-test="limited-plan-0"]').within(() => {
cy.get(`[data-test="delete-limited-plan-0"]`).click()
cy.get(`[data-test="delete-limited-plan-0"]`).click({ force: true })
})
cy.get('[data-test="limited-plan-0"]').should('not.exist')
cy.get('[data-test="add-plan-limit"]').click()
cy.get('input[name="selectedPlan"]').click()
cy.get('[data-option-index="0"]').click()
cy.get('[data-test="submitAddPlanToCouponDialog"]').click()
cy.get('[data-test="add-plan-limit"]').click({ force: true })
cy.get('input[name="selectedPlan"]').click({ force: true })
cy.get('[data-option-index="0"]').click({ force: true })
cy.get('[data-test="submitAddPlanToCouponDialog"]').click({ force: true })
cy.get('[data-test="submit"]').should('be.disabled')
cy.get('input[name="amountCents"]').type('1')

cy.get('[data-test="submit"]').click()
cy.get('[data-test="submit"]').click({ force: true })
cy.get(`[data-test="${couponName}"]`).should('exist')
})

it('should be able to apply the coupon to a customer', () => {
cy.visit('/customers')
cy.get(`[data-test="${customerName}"]`).click()
cy.get('[data-test="customer-actions"]').click()
cy.get('[data-test="apply-coupon-action"]').click()
cy.get('input[name="selectCoupon"]').click()
cy.get('[data-option-index="0"]').click()
cy.get(`[data-test="${customerName}"]`).click({ force: true })
cy.get('[data-test="customer-actions"]').click({ force: true })
cy.get('[data-test="apply-coupon-action"]').click({ force: true })
cy.get('input[name="selectCoupon"]').click({ force: true })
cy.get('[data-option-index="0"]').click({ force: true })
cy.get(`[data-test="plan-limitation-section"]`).should('exist')

// Test errors
cy.get('input[name="amountCurrency"]').click()
cy.get('[data-test="UAH"]').click()
cy.get('[data-test="submit"]').click()
cy.get('input[name="amountCurrency"]').click({ force: true })
cy.get('[data-test="UAH"]').click({ force: true })
cy.get('[data-test="submit"]').click({ force: true })
cy.get(`[data-test="alert-type-danger"]`).should('exist', 1)

// Reset values to be valid
cy.get('input[name="amountCurrency"]').click()
cy.get('[data-test="USD"]').click()
cy.get('input[name="amountCurrency"]').click({ force: true })
cy.get('[data-test="USD"]').click({ force: true })

cy.get('[data-test="submit"]').click()
cy.get(`[data-test="customer-coupon-container"]`).within(() => {
Expand All @@ -70,18 +70,18 @@ describe('Coupons', () => {

it('should not able to apply the same coupon to a customer multiple time', () => {
cy.visit('/customers')
cy.get(`[data-test="${customerName}"]`).click()
cy.get('[data-test="customer-actions"]').click()
cy.get('[data-test="apply-coupon-action"]').click()
cy.get('input[name="selectCoupon"]').click()
cy.get('[data-option-index="0"]').click()
cy.get('[data-test="submit"]').click()
cy.get(`[data-test="${customerName}"]`).click({ force: true })
cy.get('[data-test="customer-actions"]').click({ force: true })
cy.get('[data-test="apply-coupon-action"]').click({ force: true })
cy.get('input[name="selectCoupon"]').click({ force: true })
cy.get('[data-option-index="0"]').click({ force: true })
cy.get('[data-test="submit"]').click({ force: true })
cy.get(`[data-test="alert-type-danger"]`).should('exist', 1)
})

it('should not be able to edit an applied coupon', () => {
cy.visit('/coupons')
cy.get(`[data-test="${couponName}"]`).click()
cy.get(`[data-test="${couponName}"]`).click({ force: true })
cy.get('input[name="name"]').should('not.be.disabled')
cy.get('input[name="code"]').should('be.disabled')
cy.get('[data-test="submit"]').should('be.disabled')
Expand Down
97 changes: 32 additions & 65 deletions cypress/e2e/t10-add-subscription.cy.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,37 @@
// TODO: uncomment, flaky test
// import { DateTime } from 'luxon'
import { DateTime } from 'luxon'

// import { customerName, userEmail, userPassword } from '../support/reusableConstants'
import { customerName } from '../support/reusableConstants'

// describe('Add and edit subscription', () => {
// const subscriptionName = `Subscription-${Math.round(Math.random() * 10000)}`
// const subscriptionAt = DateTime.now().plus({ days: 2 }).toISO()
// const inputFormatedDate = DateTime.fromISO(subscriptionAt).toFormat('LL/dd/yyyy')
// const formatedDate = DateTime.fromISO(subscriptionAt).toFormat('LLL. dd, yyyy')
// const newSubscriptionName = `updated-${subscriptionName}`
// const newsubscriptionAt = DateTime.now().minus({ days: 10 }).toISO()
// const newInputFormatedDate = DateTime.fromISO(newsubscriptionAt).toFormat('LL/dd/yyyy')
// const newFormatedDate = DateTime.fromISO(newsubscriptionAt).toFormat('LLL. dd, yyyy')
describe('Subscritions', () => {
beforeEach(() => {
cy.visit('/customers')
cy.get(`[data-test="${customerName}"]`).click()
})

// beforeEach(() => {
// cy.login(userEmail, userPassword)
// cy.visit('/customers')
// cy.get(`[data-test="${customerName}"]`).click()
// })
const subscriptionName = `Subscription-${Math.round(Math.random() * 10000)}`
const subscriptionAt = DateTime.now().plus({ days: 2 }).toISO()
const inputFormatedDate = DateTime.fromISO(subscriptionAt as string).toFormat('LL/dd/yyyy')

// it('should be able to add a subscription to customer', () => {
// cy.get(`[data-test="add-subscription"]`).click()
// cy.get('[data-test="submit"]').should('be.disabled')
// cy.get('input[name="planId"]').click()
// cy.get('[data-option-index="0"]').click()
// cy.get('input[name="name"]').type(subscriptionName)
// cy.get('input[name="subscriptionAt"]').clear().type(inputFormatedDate)
// cy.get('[data-test="submit"]').click()
// cy.get('[data-test="submit"]').should('not.exist')
// cy.contains(subscriptionName).should('exist')
// cy.contains(formatedDate).should('exist')
// })
it('should be able to add a subscription in the future to customer', () => {
cy.get(`[data-test="add-subscription"]`).click()
cy.url().should('include', '/create/subscription')
cy.get('[data-test="submit"]').should('be.disabled')
cy.get('input[name="planId"]').click()
cy.get('[data-option-index="0"]').click()
cy.get('input[name="name"]').clear().type(subscriptionName)
cy.get('input[name="subscriptionAt"]').clear().type(inputFormatedDate)
cy.get('[data-test="submit"]').click()
cy.get('[data-test="submit"]').should('not.exist')
cy.contains(subscriptionName).should('exist')
})

// it('should be able to edit subscription', () => {
// cy.get(`[data-test="${subscriptionName}"]`).within(() => {
// cy.contains('Pending').should('exist')
// cy.get(`[data-test="menu-subscription"]`).click()
// })
// cy.get(`[data-test="edit-subscription"]`).click()
// cy.get('input[name="name"]').should('have.value', subscriptionName)
// cy.get('input[name="subscriptionAt"]').should('have.value', inputFormatedDate)
// cy.get('[data-test="submit-edit-subscription"]').should('be.disabled')
// cy.get('input[name="name"]').clear().type(newSubscriptionName)
// cy.get('input[name="subscriptionAt"]').clear().type(newInputFormatedDate)
// cy.get('[data-test="submit-edit-subscription"]').click()
// cy.contains(subscriptionName).should('exist')
// cy.contains(newFormatedDate).should('exist')
// })

// it('should not be able to edit subscription date on active subscription', () => {
// cy.get(`[data-test="${subscriptionName}"]`).within(() => {
// cy.contains('Pending').should('exist')
// cy.contains('Active').should('not.exist')
// cy.get(`[data-test="menu-subscription"]`).click()
// })
// cy.get(`[data-test="edit-subscription"]`).click()
// cy.get('input[name="name"]').should('have.value', newSubscriptionName)
// cy.get('input[name="subscriptionAt"]').should('be.disabled')
// })

// it('should be able to terminate the subscription', () => {
// cy.get(`[data-test="${newSubscriptionName}"]`).within(() => {
// cy.get(`[data-test="menu-subscription"]`).click()
// })
// cy.get(`[data-test="terminate-subscription"]`).click()
// cy.get(`[data-test="warning-confirm"]`).click()
// cy.contains(newSubscriptionName).should('not.exist')
// })
// })
it('should be able to cancel a future subscription', () => {
cy.get(`[data-test="${subscriptionName}"]`).within(() => {
cy.contains('Pending').should('exist')
cy.get(`[data-test="menu-subscription"]`).click()
})
cy.get(`[data-test="terminate-subscription"]`).click()
cy.get(`[data-test="warning-confirm"]`).click()
cy.contains(subscriptionName).should('not.exist')
})
})
39 changes: 13 additions & 26 deletions ditto/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@
"text_62d7f6178ec94cd09370e2b9": "Subscription name (optional)",
"text_62d7f6178ec94cd09370e2cb": "Type a subscription name",
"text_62d7f6178ec94cd09370e2d9": "This value can be used to differentiate plans",
"text_62d7f6178ec94cd09370e393": "Type a subscription name",
"text_62d7f6178ec94cd09370e69a": "Plan successfully changed",
"text_62d7f6178ec94cd09370e32d": "Subscription name (optional)",
"text_62e38a4631937146a6d6d5dd": "Subscription name successfully edited",
"text_62d7f6178ec94cd09370e2f3": "Terminate subscription?",
"text_62d7f6178ec94cd09370e313": "You’re about to terminate {{subscriptionName}} subscription. The customer will pay usage fees and pro rata of subscription fees. Are you sure?",
"text_62d7f6178ec94cd09370e351": "Terminate subscription",
Expand All @@ -115,7 +111,6 @@
"text_62442e40cea25600b0b6d84c": "Add a plan",
"text_62442e40cea25600b0b6d84a": "Plans",
"text_62442e40cea25600b0b6d852": "Plan name",
"text_62442e40cea25600b0b6d854": "# customers",
"text_62442e40cea25600b0b6d856": "# charges",
"text_62442e40cea25600b0b6d858": "Creation date",
"text_624451f920b6a500aab37618": "Add your first plan",
Expand Down Expand Up @@ -332,15 +327,10 @@
"text_625434c7bb2cb40124c81a29": "Plan",
"text_625434c7bb2cb40124c81a31": "Search or select a plan",
"text_625434c7bb2cb40124c81a37": "No plans",
"text_62544f170d205200f09d5938": "Plan successfully added",
"text_62681c60582e4f00aa82938a": "Downgrading to {{planName}} on {{dateStartNewPlan}}",
"text_6335e50b0b089e1d8ed50960": "{{planName}} will be activated on {{startDate}}",
"text_6335e50b0b089e1d8ed508da": "As the subscription is pending, the new plan will take effect on the start date defined previously",
"text_6335e8900c69f8ebdfef530c": "Edit subscription",
"text_6335e8900c69f8ebdfef530e": "Edit subscription",
"text_6335e8900c69f8ebdfef5310": "Change the name and the date of this subscription",
"text_6335e8900c69f8ebdfef5312": "Subscription information",
"text_6335e8900c69f8ebdfef531c": "Edit subscription",
"text_626c0c09812bbc00e4c59df1": "Account information",
"text_626c0c09812bbc00e4c59dff": "Company information (optional)",
"text_626c0c09812bbc00e4c59e01": "Legal name",
Expand Down Expand Up @@ -738,12 +728,24 @@
"text_64d27259d9a4cd00c1659a7e": "Recurring",
"text_64d27292062d9600b089aacb": "The calculated value is not reset to 0, it is persistent over all billable periods",
"text_64d272b4df12dc008076e232": "The calculated value is reset to 0 at the beginning of each period",
"text_64dd2711d878ad007212de91": "Subscription external id already existing on another subscription, please type a new one",
"text_651a8ab50fd34e005d1c1dc7": "customer",
"text_651fd3f644384c00999fbd81": "External Salesforce Id (optional)",
"text_651fd408a57493006d00504e": "Type an external Salesforce Id",
"text_651fd41846f44c0064408b07": "Enter an existing Salesforce Account ID to link this customer with a Salesforce Account",
"text_651fd42936a03200c126c683": "External Salesforce Id",
"text_65118a52df984447c1869463": "Assign plan",
"text_65118a52df984447c1869469": "Select a plan to setup the subscription",
"text_65118a52df984447c186940f": "Assign a plan to {{customerName}}",
"text_65118a52df984447c1869472": "Add an external id",
"text_65118a52df984447c186947c": "Add a subscription name",
"text_65118a52df984447c18694d0": "Override plan",
"text_65118a52df984447c18694da": "Make adjustments to this plan when creating the subscription",
"text_65118a52df984447c18694ee": "Leaving deletes your choices",
"text_65118a52df984447c18694fe": "By clicking ‘Leave’, the subscription and data you’re creating will be deleted. Are you sure you want to leave?",
"text_65118a52df984447c186962f": "Plan successfully assigned",
"text_65118a52df984447c18694c6": "Upgrade or downgrade subscription",
"text_65118a52df984447c18695f9": "Subscription successfully upgraded/downgraded",
"text_65118a52df984447c186962e": "Subscription successfully updated",
"text_645d071272418a14c1c76a5f": "Connect to Adyen",
"text_645d071272418a14c1c76a6b": "To connect to Adyen, please enter the API key generated from your Adyen account and the Merchant Account.",
"text_645d071272418a14c1c76ad8": "Connect to Adyen",
Expand Down Expand Up @@ -992,22 +994,7 @@
"text_62ea7cd44cd4b14bb9ac1da2": "Subscription will be billed every {{day}} of the week.",
"text_62ebd597d5d5130a03ced107": "Beginning of year",
"text_62ebd597d5d5130a03ced101": "Beginning of week",
"text_632b3780e409ac86609cbd05": "Plan successfully overwritten",
"text_6328e70de459381ed4ba50bc": "Add a plan to {{customerName}}",
"text_6328e70de459381ed4ba50c0": "Add a plan to {{customerName}}",
"text_6328e70de459381ed4ba50c4": "Adjust plan’s details and add it to this customer to start a new subscription.",
"text_6328e70de459381ed4ba50d4": "Add plan to {{customerName}}",
"text_6328e70de459381ed4ba50be": "Upgrade/downgrade {{customerName}}’s plan",
"text_6328e70de459381ed4ba50c2": "Upgrade or downgrade plan",
"text_6328e70de459381ed4ba50c6": "Upgrade or downgrade the current plan to another one.",
"text_6328e70de459381ed4ba50ca": "Subscription information",
"text_6328e70de459381ed4ba50d6": "The subscription upgrade will take effect immediately for your customer\nHowever, the downgrade will be effective after {{subscriptionEndDate}}",
"text_6328e70de459381ed4ba50da": "Upgrade/downgrade plan",
"text_6328e911e1eede3a429e8861": "Overwrite",
"text_6329fd60c32c30152678a6e8": "Duplicate {{planName}}",
"text_6329fd60c32c30152678a6f4": "Duplicate {{planName}}",
"text_6329fd60c32c30152678a6f6": "Create a new plan with charges based on an existing one.",
"text_6329fd60c32c30152678a73c": "Duplicate plan",
"text_632a2d437e341dcc76817556": "Code already existing, please type a new one",
"text_63fcc3218d35b9377840f59b": "Metadata",
"text_63fcc3218d35b9377840f59f": "Add metadata to the customer account and choose whether or not it should appear on the invoice.",
Expand Down
5 changes: 5 additions & 0 deletions ditto/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,14 @@ sources:
fileName: 👍 [Ready for dev] - B.Metrics - Add last aggregation type
- name: 👍 [Ready for dev] - Plans - Invoice display names
id: 65018c8af04a866c7bcc6cb8
fileName: 👍 [Ready for dev] - Plans - Invoice display names
- name: 👍 [Ready for dev] - Billable metrics - Weighted sum
id: 6500621fbbf7ebe75d11e890
fileName: 👍 [Ready for dev] - Billable metrics - Weighted sum
- name: 👍 [Ready for dev] - Customers - Add subscription end date
id: 64ef55a23bdcf2d86567cbed
fileName: 👍 [Ready for dev] - Customers - Add subscription end date
- name: ⚙️ [WIP] - Subscription/Plans - Overrides plans and subscriptions
id: 65118a3c24d30a816a60ca92
format: flat
variants: true
3 changes: 3 additions & 0 deletions ditto/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ module.exports = {
"project_645d070fa825baf410cec70c": {
"base": require('./-wip---settings--customers---lago-x-adyen-connection__base.json')
},
"project_65118a3c24d30a816a60ca92": {
"base": require('./-wip---subscriptionplans---overrides-plans-and-subscriptions__base.json')
},
"project_64999d7a720a1412d1a72cf6": {
"base": require('./add-missing-keys__base.json')
},
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@graphql-codegen/typescript": "4.0.1",
"@graphql-codegen/typescript-operations": "4.0.1",
"@graphql-codegen/typescript-react-apollo": "3.3.7",
"@parcel/watcher": "^2.3.0",
"@svgr/webpack": "8.1.0",
"@testing-library/dom": "^9.3.1",
"@testing-library/jest-dom": "6.1.2",
Expand Down
Loading

0 comments on commit 4c5ad74

Please sign in to comment.