Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 45 additions & 6 deletions apps/billing-web/e2e/checkout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import type { BillingOpStatusResponse } from '@comfyorg/ingest-types'

import type { MockCloud } from './fixtures/cloud'
import { E2E_USER } from './fixtures/env'
import { expectStraightToHost } from './fixtures/planless'
import { CLOUD_ORIGIN, E2E_USER } from './fixtures/env'
import {
expectPlanlessLinkToLeaveFor,
expectStraightToPricingTable
} from './fixtures/planless'
import {
challengeRequiredOperation,
contactSupportOperation,
Expand Down Expand Up @@ -418,8 +421,44 @@ test('a checkout link naming a team credit stop quotes it along with the plan',
})

test.describe('a checkout link that names no plan goes back to the host to choose one', () => {
test('on the Team tab when the link names a team', async ({ page }) => {
await expectPlanlessLinkToLeaveFor(
page,
{ workspace: 'ws_team_e2e', team_credit_stop_id: 'stop_700' },
`${CLOUD_ORIGIN}/?pricing=team&workspace=ws_team_e2e`
)
})

test("to a platform link's own return_to when billing may follow it", async ({
page
}) => {
await expectPlanlessLinkToLeaveFor(
page,
{ product: 'platform', workspace: 'ws_e2e' },
`${CLOUD_ORIGIN}/?workspace=ws_e2e`
)
})

test('never to the cloud for a platform link this deployment has no platform page for', async ({
page,
signIn
}) => {
await signIn(CHECKOUT)
const platformLink = entryPath('checkout', {
product: 'platform',
return_to: 'nowhere'
})

await page.goto(platformLink)

await expect(
page.getByText("That link doesn't name a place we can send you back to.")
).toBeVisible()
await expect(page).toHaveURL(platformLink)
})

test('for a signed-out visitor', async ({ page }) => {
await expectStraightToHost(page, 'ws_team_e2e')
await expectStraightToPricingTable(page, 'ws_team_e2e')
})

test('for a signed-in customer, in the tab they signed in on', async ({
Expand All @@ -431,7 +470,7 @@ test.describe('a checkout link that names no plan goes back to the host to choos
page.getByRole('button', { name: 'Pay and subscribe' })
).toBeVisible()

await expectStraightToHost(page, 'ws_e2e')
await expectStraightToPricingTable(page, 'ws_e2e')
})

test('for a signed-in customer the host opens a new tab for, before that tab has a session', async ({
Expand All @@ -440,7 +479,7 @@ test.describe('a checkout link that names no plan goes back to the host to choos
}) => {
await signIn(CHECKOUT)

await expectStraightToHost(await context.newPage(), 'ws_e2e')
await expectStraightToPricingTable(await context.newPage(), 'ws_e2e')
})

test('for a signed-in customer whose link names a workspace they cannot manage, never the refusal', async ({
Expand All @@ -455,7 +494,7 @@ test.describe('a checkout link that names no plan goes back to the host to choos
}))
const tab = await context.newPage()

await expectStraightToHost(tab, 'ws_not_a_member')
await expectStraightToPricingTable(tab, 'ws_not_a_member')
await expect(tab.getByRole('alert')).toHaveCount(0)
})
})
Expand Down
32 changes: 20 additions & 12 deletions apps/billing-web/e2e/fixtures/planless.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import type { Page } from '@playwright/test'

import { CLOUD_ORIGIN } from './env'
import { entryPath, expect } from './test'

const planlessCheckout = (workspace: string) =>
entryPath('checkout', { workspace })

/**
* Opens a checkout link that names no plan and expects what the embedded
* checkout always did with it: straight back to the host, the link's
* workspace echoed, with no sign-in page shown and no session minted.
* Opens a checkout link that names no plan and expects it to leave for
* `destination` at once, with no sign-in page shown and no session minted.
*/
export async function expectStraightToHost(
export async function expectPlanlessLinkToLeaveFor(
tab: Page,
workspace: string
link: Record<string, string>,
destination: string
): Promise<void> {
const shown: string[] = []
const mints: string[] = []
Expand All @@ -24,12 +22,22 @@ export async function expectStraightToHost(
mints.push(request.url())
})

await tab.goto(planlessCheckout(workspace))
await tab.goto(entryPath('checkout', link))

await expect(tab).toHaveURL(
`https://testcloud.comfy.org/?workspace=${workspace}`
)
await expect(tab).toHaveURL(destination)
await expect(tab.getByRole('heading', { name: 'Host app' })).toBeVisible()
expect(shown).not.toContain('/sign-in')
expect(mints, 'a link that goes back mints no session').toEqual([])
}

/** The host's pricing table, in the link's workspace: where a plan is picked. */
export async function expectStraightToPricingTable(
tab: Page,
workspace: string
): Promise<void> {
await expectPlanlessLinkToLeaveFor(
tab,
{ workspace },
`${CLOUD_ORIGIN}/?pricing=1&workspace=${workspace}`
)
}
6 changes: 3 additions & 3 deletions apps/billing-web/e2e/full-page-endings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
pendingOperation,
succeededOperation
} from './fixtures/scenario'
import { expectStraightToHost } from './fixtures/planless'
import { expectStraightToPricingTable } from './fixtures/planless'
import { installFakeStripe } from './fixtures/stripe'
import { entryPath, expect, test as base } from './fixtures/test'

Expand Down Expand Up @@ -435,7 +435,7 @@ test('433-6840: a checkout link that names no plan, routed once the tab is signe
test('a signed-out visitor on the flag still goes back to the host for a checkout link that names no plan', async ({
page
}) => {
await expectStraightToHost(page, 'ws_team_e2e')
await expectStraightToPricingTable(page, 'ws_team_e2e')
})

test('a checkout link that names no plan, opened by the host in a new tab, goes back to the host even for a signed-in customer on the flag', async ({
Expand All @@ -444,7 +444,7 @@ test('a checkout link that names no plan, opened by the host in a new tab, goes
}) => {
await signIn(CHECKOUT)

await expectStraightToHost(await context.newPage(), 'ws_e2e')
await expectStraightToPricingTable(await context.newPage(), 'ws_e2e')
})

test("433-6840: a checkout link the contract cannot read is the checkout's 404 on the full page, and still the entry error on the embedded one", async ({
Expand Down
104 changes: 94 additions & 10 deletions apps/billing-web/src/router.planless.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { createMemoryHistory } from 'vue-router'

import type { BillingEnvironment } from '@comfyorg/billing-contract'

import type { BillingWebSessionPhase } from '@/router'

const h = vi.hoisted(() => ({
Expand Down Expand Up @@ -48,7 +50,7 @@ function flagAnswers(variant: string) {

const PLANLESS =
'/v1/checkout?product=comfyui&return_to=comfyui_workspace&workspace=ws-team'
const HOST = 'https://testcloud.comfy.org/?workspace=ws-team'
const PRICING_TABLE = 'https://testcloud.comfy.org/?pricing=1&workspace=ws-team'

beforeEach(() => {
vi.resetModules()
Expand All @@ -57,10 +59,13 @@ beforeEach(() => {
h.bind.mockReset()
})

async function openPlanless(visitor: {
livePhase: BillingWebSessionPhase | undefined
flag: string
}) {
async function openPlanless(
visitor: {
livePhase: BillingWebSessionPhase | undefined
flag: string
},
path: string = PLANLESS
) {
h.livePhase = visitor.livePhase
flagAnswers(visitor.flag)
const { createBillingRouter } = await import('@/router')
Expand All @@ -72,7 +77,7 @@ async function openPlanless(visitor: {
undefined,
leave
)
await router.push(PLANLESS)
await router.push(path)
return { router, leave, ...useBillingEntry() }
}

Expand Down Expand Up @@ -113,26 +118,26 @@ describe('a checkout link that names no plan', () => {
flag: 'full_page'
}
])(
'sends $name straight back to the host, without asking for a session or the flag',
'sends $name straight to the pricing table, without asking for a session or the flag',
async (visitor) => {
const { router, leave } = await openPlanless(visitor)

expect(leave).toHaveBeenCalledExactlyOnceWith(HOST)
expect(leave).toHaveBeenCalledExactlyOnceWith(PRICING_TABLE)
expect(router.currentRoute.value.path).not.toBe('/sign-in')
expect(h.bind).not.toHaveBeenCalled()
expect(fetchMock).not.toHaveBeenCalled()
}
)

it.for(['embedded', 'unreachable'])(
'sends a signed-in customer whose flag reads %s back to the host',
'sends a signed-in customer whose flag reads %s to the pricing table',
async (flag) => {
const { router, leave } = await openPlanless({
livePhase: 'authenticated',
flag
})

expect(leave).toHaveBeenCalledExactlyOnceWith(HOST)
expect(leave).toHaveBeenCalledExactlyOnceWith(PRICING_TABLE)
expect(router.currentRoute.value.path).not.toBe('/sign-in')
expect(h.bind).not.toHaveBeenCalled()
}
Expand All @@ -156,6 +161,85 @@ describe('a checkout link that names no plan', () => {
})
})

describe('where a checkout link that names no plan sends the customer to pick one', () => {
const SIGNED_OUT = { livePhase: 'signed-out', flag: 'embedded' } as const

it.for<{
name: string
env: BillingEnvironment
query: string
destination: string
}>([
{
name: 'a cloud link to the pricing table',
env: 'staging',
query: 'product=comfyui&return_to=comfyui_workspace&workspace=ws-1',
destination: 'https://stagingcloud.comfy.org/?pricing=1&workspace=ws-1'
},
{
name: 'a cloud link without a return_to to the pricing table',
env: 'production',
query: 'product=comfyui',
destination: 'https://cloud.comfy.org/?pricing=1'
},
{
name: 'a cloud link that names a team to the Team tab',
env: 'staging',
query:
'product=comfyui&return_to=comfyui_workspace&workspace=ws-1&team_credit_stop_id=stop_700',
destination: 'https://stagingcloud.comfy.org/?pricing=team&workspace=ws-1'
},
{
name: 'a platform link to its return_to',
env: 'staging',
query: 'product=platform&return_to=platform_account&workspace=ws-1',
destination: 'https://stagingplatform.comfy.org/?workspace=ws-1'
},
{
name: 'a platform link to a return_to in another product',
env: 'production',
query: 'product=platform&return_to=comfyui_credits',
destination: 'https://cloud.comfy.org/?settings=plan-credits'
},
{
name: 'a platform link with an unregistered return_to to the platform billing page',
env: 'staging',
query: 'product=platform&return_to=https://evil.test&workspace=ws-1',
destination:
'https://stagingplatform.comfy.org/profile/billing?workspace=ws-1'
},
{
name: 'a platform link without a return_to to the platform billing page',
env: 'production',
query: 'product=platform',
destination: 'https://platform.comfy.org/profile/billing'
}
])('sends $name', async ({ env, query, destination }) => {
vi.stubEnv('VITE_BILLING_ENV', env)

const { router, leave } = await openPlanless(
SIGNED_OUT,
`/v1/checkout?${query}`
)

expect(leave).toHaveBeenCalledExactlyOnceWith(destination)
expect(router.currentRoute.value.path).not.toBe('/sign-in')
expect(h.bind).not.toHaveBeenCalled()
expect(fetchMock).not.toHaveBeenCalled()
})

it('explains a platform link where this deployment has no platform to send it to', async () => {
const { leave, entry, error } = await openPlanless(
SIGNED_OUT,
'/v1/checkout?product=platform&return_to=platform_account'
)

expect(leave).not.toHaveBeenCalled()
expect(entry.value).toBeUndefined()
expect(error.value).toBe('UNKNOWN_RETURN_TARGET')
})
})

describe('a planless checkout link the customer navigates away from', () => {
const LATER =
'/v1/subscription?product=comfyui&return_to=comfyui_workspace&workspace=ws-other'
Expand Down
29 changes: 18 additions & 11 deletions apps/billing-web/src/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,26 @@ describe('plan selection, which the host app owns', () => {
}

it.for([
`/v1/pricing?${ENTRY_QUERY}&workspace=ws-team`,
`/v1/checkout?${ENTRY_QUERY}&workspace=ws-team`
])('sends %s back to the host without rebinding the tab', async (path) => {
const { router, onEntryWorkspace, leave } = hostBoundRouter()
[
`/v1/pricing?${ENTRY_QUERY}&workspace=ws-team`,
'https://testcloud.comfy.org/?workspace=ws-team'
],
[
`/v1/checkout?${ENTRY_QUERY}&workspace=ws-team`,
'https://testcloud.comfy.org/?pricing=1&workspace=ws-team'
]
])(
'sends %s to %s without rebinding the tab',
async ([path, destination]) => {
const { router, onEntryWorkspace, leave } = hostBoundRouter()

await router.push(path)
await router.push(path)

expect(leave).toHaveBeenCalledExactlyOnceWith(
'https://testcloud.comfy.org/?workspace=ws-team'
)
expect(onEntryWorkspace).not.toHaveBeenCalled()
expect(router.currentRoute.value.path).not.toBe('/sign-in')
})
expect(leave).toHaveBeenCalledExactlyOnceWith(destination)
expect(onEntryWorkspace).not.toHaveBeenCalled()
expect(router.currentRoute.value.path).not.toBe('/sign-in')
}
)

it('keeps a checkout that names a plan', async () => {
const { router, leave } = hostBoundRouter('authenticated')
Expand Down
Loading
Loading