Repository navigation
test: 1/6 set up real Cloud E2E #17481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4768e54
2ebbbbc
9fb511b
bd177a2
547243b
2570532
2139099
a6a7df4
bc83bc1
818c8c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { expect } from '@playwright/test' | ||
| import type { Locator, Page } from '@playwright/test' | ||
|
|
||
| export class LiveCloudOnboarding { | ||
| public readonly survey: Locator | ||
| public readonly canvas: Locator | ||
| public readonly next: Locator | ||
| public readonly submit: Locator | ||
| public readonly option: Locator | ||
| public readonly text: Locator | ||
|
|
||
| constructor(private readonly page: Page) { | ||
| this.survey = page.getByRole('heading', { | ||
| name: "Let's get to know you", | ||
| exact: true | ||
| }) | ||
| this.canvas = page.locator('#graph-canvas') | ||
| this.next = page.getByRole('button', { name: 'Next', exact: true }) | ||
| this.submit = page.getByRole('button', { name: 'Submit', exact: true }) | ||
| this.option = page | ||
| .getByRole('button', { pressed: false }) | ||
| .and(page.locator('[aria-pressed="false"]:not([id$="-other"])')) | ||
| .first() | ||
| this.text = page.getByRole('textbox') | ||
| } | ||
|
|
||
| async completeSurveyIfNeeded(frontend: string) { | ||
| const { survey, canvas, next, submit } = this | ||
| await expect(survey.or(canvas)).toBeVisible() | ||
| if (await survey.isVisible()) { | ||
| for (let step = 0; step < 20; step++) { | ||
| if (await this.answerSurveyQuestion(next, submit)) break | ||
| } | ||
| await expect( | ||
| submit, | ||
| 'Complete Cloud onboarding within 20 questions' | ||
| ).toBeEnabled() | ||
| const [response] = await Promise.all([ | ||
| this.page.waitForResponse( | ||
| (response) => | ||
| response.url() === `${frontend}/api/settings` && | ||
| response.request().method() === 'POST' | ||
| ), | ||
| submit.click() | ||
| ]) | ||
| expect(response.status(), 'Save Cloud onboarding survey').toBe(200) | ||
| await expect(survey).toBeHidden() | ||
| } | ||
| await expect(canvas).toBeVisible() | ||
| } | ||
|
|
||
| private async answerSurveyQuestion(next: Locator, submit: Locator) { | ||
| const { option, text } = this | ||
| await expect(option.or(text)).toBeVisible() | ||
| const control = (await option.isVisible()) ? option : text | ||
| const id = await control.getAttribute('id') | ||
| if (!id) throw new Error('Cloud survey control has no ID') | ||
| const answered = this.page.locator(`[id=${JSON.stringify(id)}]`) | ||
| if (await option.isVisible()) await control.click() | ||
| else await control.fill('Automated billing E2E') | ||
| await expect | ||
| .poll( | ||
| async () => | ||
| !(await answered.isVisible()) || | ||
| ((await next.isVisible()) && (await next.isEnabled())) || | ||
| ((await submit.isVisible()) && (await submit.isEnabled())) | ||
| ) | ||
| .toBe(true) | ||
| if ((await submit.isVisible()) && (await submit.isEnabled())) return true | ||
| if ((await next.isVisible()) && (await next.isEnabled())) await next.click() | ||
| await expect(answered).toBeHidden() | ||
| return false | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import { getLiveCloudEnvironment } from '@e2e/fixtures/utils/liveCloudBillingConfig' | ||
| import { | ||
| zBillingStatusResponse, | ||
| zCurrentWorkspaceResponse, | ||
| zListSavedPaymentMethodsResponse, | ||
| zPaymentPortalResponse | ||
| } from '@comfyorg/ingest-types/zod' | ||
| import type { APIRequestContext, TestInfo } from '@playwright/test' | ||
| import { expect } from '@playwright/test' | ||
| import type { z } from 'zod' | ||
|
|
||
| export class LiveCloudBillingSession { | ||
| private readonly environment: ReturnType<typeof getLiveCloudEnvironment> | ||
| constructor( | ||
| private readonly request: APIRequestContext, | ||
| private readonly backend: string, | ||
| private readonly headers: Record<string, string> | ||
| ) { | ||
| this.environment = getLiveCloudEnvironment(backend) | ||
| } | ||
|
|
||
| async read<T>(path: string, schema: z.ZodType<T>): Promise<T> { | ||
| const response = await this.request | ||
| .get(new URL(path, this.backend).href, { | ||
| headers: this.headers, | ||
| maxRedirects: 0 | ||
| }) | ||
| .catch(() => { | ||
| throw new Error(`Cloud billing request failed: ${path}`) | ||
| }) | ||
| expect(response.status(), `GET ${path}`).toBe(200) | ||
| return schema.parse(await response.json()) | ||
| } | ||
|
|
||
| async post<T>( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2 — Bind this write to its generated request contract. This public helper accepts an arbitrary path, a hand-written |
||
| path: string, | ||
| data: Record<string, number | string>, | ||
| schema: z.ZodType<T>, | ||
| acceptedStatuses = [200] | ||
| ): Promise<T> { | ||
| const response = await this.request | ||
| .post(new URL(path, this.backend).href, { | ||
| data, | ||
| headers: this.headers, | ||
| maxRedirects: 0 | ||
| }) | ||
| .catch(() => { | ||
| throw new Error(`Cloud billing request failed: ${path}`) | ||
| }) | ||
| expect(acceptedStatuses, `POST ${path}`).toContain(response.status()) | ||
| return schema.parse(await response.json()) | ||
| } | ||
|
|
||
| async assertNoCardAccount(testInfo: TestInfo) { | ||
| const workspace = await this.read( | ||
| '/api/workspaces/current', | ||
| zCurrentWorkspaceResponse | ||
| ) | ||
| expect(workspace.type).toBe('personal') | ||
| expect(workspace.role).toBe('owner') | ||
| const status = await this.read( | ||
| '/api/billing/status', | ||
| zBillingStatusResponse | ||
| ) | ||
| if (this.environment.stripeMode === 'live') { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: this
The failure path that matters is the one the message names: if a disposable account somehow arrives with a saved card (a retried run reusing an address, or a downstream PR passing a permanent account into this helper), the checkout-recovery scenarios in #17870 / #17545 would silently exercise the saved-card flow instead of the card-entry flow and still report green, because the guard meant to catch that never executed. Should the condition be inverted — assert the account has no saved cards in |
||
| const paymentMethods = await this.read( | ||
| '/api/billing/payment-methods', | ||
| zListSavedPaymentMethodsResponse | ||
| ) | ||
| expect( | ||
| paymentMethods, | ||
| 'Checkout recovery requires an account without saved payment methods' | ||
| ).toHaveLength(0) | ||
| } | ||
| await testInfo.attach('billing-preflight.json', { | ||
| body: JSON.stringify({ | ||
| workspaceId: workspace.id, | ||
| isActive: status.is_active, | ||
| billingStatus: status.billing_status, | ||
| subscriptionTier: status.subscription_tier, | ||
| backend: this.backend | ||
| }), | ||
| contentType: 'application/json' | ||
| }) | ||
| if (status.is_active) expect(status.subscription_tier).toBe('FREE') | ||
| else | ||
| expect(['inactive', 'awaiting_payment_method']).toContain( | ||
| status.billing_status | ||
| ) | ||
| } | ||
|
|
||
| async ensureProvisioned(returnUrl: string) { | ||
| await this.post( | ||
| '/api/billing/payment-portal', | ||
| { return_url: returnUrl }, | ||
| zPaymentPortalResponse | ||
| ) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.