🐛 (stripe) Update additional items when they didn't exist
This commit is contained in:
committed by
Baptiste Arnaud
parent
c94a6581be
commit
f83e0efea2
@ -190,11 +190,13 @@ export const ProPlanContent = ({
|
|||||||
size="sm"
|
size="sm"
|
||||||
isLoading={selectedChatsLimitIndex === undefined}
|
isLoading={selectedChatsLimitIndex === undefined}
|
||||||
>
|
>
|
||||||
{parseNumberWithCommas(
|
{selectedChatsLimitIndex !== undefined
|
||||||
chatsLimit.PRO.totalIncluded +
|
? parseNumberWithCommas(
|
||||||
chatsLimit.PRO.increaseStep.amount *
|
chatsLimit.PRO.totalIncluded +
|
||||||
(selectedChatsLimitIndex ?? 0)
|
chatsLimit.PRO.increaseStep.amount *
|
||||||
)}
|
selectedChatsLimitIndex
|
||||||
|
)
|
||||||
|
: undefined}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
<MenuList>
|
<MenuList>
|
||||||
{selectedChatsLimitIndex !== 0 && (
|
{selectedChatsLimitIndex !== 0 && (
|
||||||
@ -252,11 +254,13 @@ export const ProPlanContent = ({
|
|||||||
size="sm"
|
size="sm"
|
||||||
isLoading={selectedStorageLimitIndex === undefined}
|
isLoading={selectedStorageLimitIndex === undefined}
|
||||||
>
|
>
|
||||||
{parseNumberWithCommas(
|
{selectedStorageLimitIndex !== undefined
|
||||||
storageLimit.PRO.totalIncluded +
|
? parseNumberWithCommas(
|
||||||
storageLimit.PRO.increaseStep.amount *
|
storageLimit.PRO.totalIncluded +
|
||||||
(selectedStorageLimitIndex ?? 0)
|
storageLimit.PRO.increaseStep.amount *
|
||||||
)}
|
selectedStorageLimitIndex
|
||||||
|
)
|
||||||
|
: undefined}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
<MenuList>
|
<MenuList>
|
||||||
{selectedStorageLimitIndex !== 0 && (
|
{selectedStorageLimitIndex !== 0 && (
|
||||||
|
@ -142,11 +142,13 @@ export const StarterPlanContent = ({
|
|||||||
size="sm"
|
size="sm"
|
||||||
isLoading={selectedChatsLimitIndex === undefined}
|
isLoading={selectedChatsLimitIndex === undefined}
|
||||||
>
|
>
|
||||||
{parseNumberWithCommas(
|
{selectedChatsLimitIndex !== undefined
|
||||||
chatsLimit.STARTER.totalIncluded +
|
? parseNumberWithCommas(
|
||||||
chatsLimit.STARTER.increaseStep.amount *
|
chatsLimit.STARTER.totalIncluded +
|
||||||
(selectedChatsLimitIndex ?? 0)
|
chatsLimit.STARTER.increaseStep.amount *
|
||||||
)}
|
selectedChatsLimitIndex
|
||||||
|
)
|
||||||
|
: undefined}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
<MenuList>
|
<MenuList>
|
||||||
{selectedChatsLimitIndex !== 0 && (
|
{selectedChatsLimitIndex !== 0 && (
|
||||||
@ -206,11 +208,13 @@ export const StarterPlanContent = ({
|
|||||||
size="sm"
|
size="sm"
|
||||||
isLoading={selectedStorageLimitIndex === undefined}
|
isLoading={selectedStorageLimitIndex === undefined}
|
||||||
>
|
>
|
||||||
{parseNumberWithCommas(
|
{selectedStorageLimitIndex !== undefined
|
||||||
storageLimit.STARTER.totalIncluded +
|
? parseNumberWithCommas(
|
||||||
storageLimit.STARTER.increaseStep.amount *
|
storageLimit.STARTER.totalIncluded +
|
||||||
(selectedStorageLimitIndex ?? 0)
|
storageLimit.STARTER.increaseStep.amount *
|
||||||
)}
|
selectedStorageLimitIndex
|
||||||
|
)
|
||||||
|
: undefined}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
<MenuList>
|
<MenuList>
|
||||||
{selectedStorageLimitIndex !== 0 && (
|
{selectedStorageLimitIndex !== 0 && (
|
||||||
|
@ -138,22 +138,22 @@ const updateSubscription = async (req: NextApiRequest) => {
|
|||||||
: process.env.STRIPE_PRO_PRICE_ID,
|
: process.env.STRIPE_PRO_PRICE_ID,
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
},
|
},
|
||||||
currentAdditionalChatsItemId
|
additionalChats === 0 && !currentAdditionalChatsItemId
|
||||||
? {
|
? undefined
|
||||||
|
: {
|
||||||
id: currentAdditionalChatsItemId,
|
id: currentAdditionalChatsItemId,
|
||||||
price: process.env.STRIPE_ADDITIONAL_CHATS_PRICE_ID,
|
price: process.env.STRIPE_ADDITIONAL_CHATS_PRICE_ID,
|
||||||
quantity: additionalChats,
|
quantity: additionalChats,
|
||||||
deleted: additionalChats === 0,
|
deleted: additionalChats === 0,
|
||||||
}
|
},
|
||||||
: undefined,
|
additionalStorage === 0 && !currentAdditionalStorageItemId
|
||||||
currentAdditionalStorageItemId
|
? undefined
|
||||||
? {
|
: {
|
||||||
id: currentAdditionalStorageItemId,
|
id: currentAdditionalStorageItemId,
|
||||||
price: process.env.STRIPE_ADDITIONAL_STORAGE_PRICE_ID,
|
price: process.env.STRIPE_ADDITIONAL_STORAGE_PRICE_ID,
|
||||||
quantity: additionalStorage,
|
quantity: additionalStorage,
|
||||||
deleted: additionalStorage === 0,
|
deleted: additionalStorage === 0,
|
||||||
}
|
},
|
||||||
: undefined,
|
|
||||||
].filter(isDefined)
|
].filter(isDefined)
|
||||||
await stripe.subscriptions.update(subscription.id, {
|
await stripe.subscriptions.update(subscription.id, {
|
||||||
items,
|
items,
|
||||||
|
@ -95,38 +95,36 @@ test('plan changes should work', async ({ page }) => {
|
|||||||
price: process.env.STRIPE_STARTER_PRICE_ID,
|
price: process.env.STRIPE_STARTER_PRICE_ID,
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
price: process.env.STRIPE_ADDITIONAL_CHATS_PRICE_ID,
|
|
||||||
quantity: 3,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
price: process.env.STRIPE_ADDITIONAL_STORAGE_PRICE_ID,
|
|
||||||
quantity: 2,
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
{ plan: Plan.STARTER, additionalChatsIndex: 3, additionalStorageIndex: 2 }
|
{ plan: Plan.STARTER, additionalChatsIndex: 0, additionalStorageIndex: 0 }
|
||||||
)
|
)
|
||||||
|
|
||||||
// Update plan with additional quotas
|
// Update plan with additional quotas
|
||||||
await page.goto('/typebots')
|
await page.goto('/typebots')
|
||||||
await page.click('text=Settings & Members')
|
await page.click('text=Settings & Members')
|
||||||
await page.click('text=Billing & Usage')
|
await page.click('text=Billing & Usage')
|
||||||
await expect(page.locator('text="/ 3,500"')).toBeVisible()
|
await expect(page.locator('text="/ 2,000"')).toBeVisible()
|
||||||
await expect(page.locator('text="/ 4 GB"')).toBeVisible()
|
await expect(page.locator('text="/ 2 GB"')).toBeVisible()
|
||||||
await expect(page.locator('button >> text="3,500"')).toBeVisible()
|
await expect(page.locator('button >> text="2,000"')).toBeVisible()
|
||||||
await expect(page.locator('button >> text="4"')).toBeVisible()
|
await expect(page.locator('button >> text="2"')).toBeVisible()
|
||||||
await expect(page.locator('text="$73"')).toBeVisible()
|
|
||||||
await page.click('button >> text="3,500"')
|
|
||||||
await page.click('button >> text="2,000"')
|
await page.click('button >> text="2,000"')
|
||||||
|
await page.click('button >> text="3,500"')
|
||||||
|
await page.click('button >> text="2"')
|
||||||
await page.click('button >> text="4"')
|
await page.click('button >> text="4"')
|
||||||
await page.click('button >> text="6"')
|
await expect(page.locator('text="$73"')).toBeVisible()
|
||||||
await expect(page.locator('text="$47"')).toBeVisible()
|
|
||||||
await page.click('button >> text=Update')
|
await page.click('button >> text=Update')
|
||||||
await expect(
|
await expect(
|
||||||
page.locator(
|
page.locator(
|
||||||
'text="Workspace STARTER plan successfully updated 🎉" >> nth=0'
|
'text="Workspace STARTER plan successfully updated 🎉" >> nth=0'
|
||||||
)
|
)
|
||||||
).toBeVisible()
|
).toBeVisible()
|
||||||
|
await page.click('text="Members"')
|
||||||
|
await page.click('text="Billing & Usage"')
|
||||||
|
await expect(page.locator('text="$73"')).toBeVisible()
|
||||||
|
await expect(page.locator('text="/ 3,500"')).toBeVisible()
|
||||||
|
await expect(page.locator('text="/ 4 GB"')).toBeVisible()
|
||||||
|
await expect(page.locator('button >> text="3,500"')).toBeVisible()
|
||||||
|
await expect(page.locator('button >> text="4"')).toBeVisible()
|
||||||
|
|
||||||
// Upgrade to PRO
|
// Upgrade to PRO
|
||||||
await page.click('button >> text="10,000"')
|
await page.click('button >> text="10,000"')
|
||||||
|
Reference in New Issue
Block a user