Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
test(web): exercise account deletion mutation owners (#44767)
Stephen Zhoua5cf299d1b6f
diff --git a/web/app/account/(commonLayout)/delete-account/components/__tests__/check-email.spec.tsx b/web/app/account/(commonLayout)/delete-account/components/__tests__/check-email.spec.tsxindex 7d84ef05820..fed4eabcc10 100644--- a/web/app/account/(commonLayout)/delete-account/components/__tests__/check-email.spec.tsx+++ b/web/app/account/(commonLayout)/delete-account/components/__tests__/check-email.spec.tsx@@ -1,23 +1,30 @@import { screen, waitFor } from '@testing-library/react'import userEvent from '@testing-library/user-event'+import { consoleClient } from '@/service/console'import { renderWithAccountProfile } from '@/test/console/account-profile'+import { useAccountDeleteStore } from '../../state'import CheckEmail from '../check-email'-const mockGetDeleteEmailVerifyCode = vi.fn()--vi.mock('../../state', () => ({- useSendDeleteAccountEmail: () => ({- isPending: false,- mutateAsync: mockGetDeleteEmailVerifyCode,- }),-}))+vi.mock('@/service/console', async (importOriginal) => {+ const actual = await importOriginal<typeof import('@/service/console')>()+ const { withConsoleClientResponses } = await import('@/test/console/service-responses')+ return {+ ...actual,+ consoleClient: withConsoleClientResponses(actual.consoleClient, {+ 'account.delete.verify.get': vi.fn(),+ }),+ }+})describe('CheckEmail', () => {beforeEach(() => {- mockGetDeleteEmailVerifyCode.mockReset().mockResolvedValue({ result: 'success' })+ vi.mocked(consoleClient.account.delete.verify.get).mockResolvedValue({+ result: 'success',+ data: 'deletion-email-token',+ })})- it('submits with Enter only after the account email matches', async () => {+ it('requests and stores a verification token only after the account email matches', async () => {const user = userEvent.setup()const onConfirm = vi.fn()@@ -33,15 +40,16 @@ describe('CheckEmail', () => {await user.type(input, '[email protected]{Enter}')expect(submitButton).toBeDisabled()- expect(mockGetDeleteEmailVerifyCode).not.toHaveBeenCalled()+ expect(consoleClient.account.delete.verify.get).not.toHaveBeenCalled()await user.clear(input)await user.type(input, '[email protected]{Enter}')await waitFor(() => {- expect(mockGetDeleteEmailVerifyCode).toHaveBeenCalledOnce()+ expect(useAccountDeleteStore.getState().sendEmailToken).toBe('deletion-email-token')})expect(submitButton).toBeEnabled()+ expect(consoleClient.account.delete.verify.get).toHaveBeenCalledExactlyOnceWith()expect(onConfirm).toHaveBeenCalledOnce()})})diff --git a/web/app/account/(commonLayout)/delete-account/components/__tests__/feed-back.spec.tsx b/web/app/account/(commonLayout)/delete-account/components/__tests__/feed-back.spec.tsxindex 203eb430c2d..561927beb26 100644--- a/web/app/account/(commonLayout)/delete-account/components/__tests__/feed-back.spec.tsx+++ b/web/app/account/(commonLayout)/delete-account/components/__tests__/feed-back.spec.tsx@@ -1,31 +1,39 @@import { screen, waitFor } from '@testing-library/react'import userEvent from '@testing-library/user-event'+import { consoleClient } from '@/service/console'import { renderWithAccountProfile } from '@/test/console/account-profile'import FeedBack from '../feed-back'-const mockUseLogout = vi.fn()-const mockSendFeedback = vi.fn()-const mockLogout = vi.fn()--vi.mock('@/service/use-common', () => ({- useLogout: (...args: unknown[]) => mockUseLogout(...args),-}))+const { logout } = vi.hoisted(() => ({ logout: vi.fn() }))++vi.mock('@/service/console', async (importOriginal) => {+ const actual = await importOriginal<typeof import('@/service/console')>()+ const { withConsoleClientResponses, withConsoleResponses } =+ await import('@/test/console/service-responses')+ return {+ ...actual,+ consoleClient: withConsoleClientResponses(actual.consoleClient, {+ 'account.delete.feedback.post': vi.fn(),+ }),+ consoleQuery: withConsoleResponses(actual.consoleQuery, {+ 'logout.post': logout,+ }),+ }+})-vi.mock('../../state', () => ({- useDeleteAccountFeedback: () => ({- isPending: false,- mutateAsync: mockSendFeedback,- }),-}))+// Analytics is an external SDK; logout and its redirect remain real.+vi.mock('@/app/components/base/amplitude/utils', () => ({ resetUser: vi.fn() }))describe('FeedBack', () => {beforeEach(() => {- mockSendFeedback.mockReset().mockResolvedValue(undefined)- mockLogout.mockReset().mockResolvedValue(undefined)- mockUseLogout.mockReset().mockReturnValue({ mutateAsync: mockLogout })+ vi.mocked(consoleClient.account.delete.feedback.post).mockResolvedValue({ result: 'success' })+ logout.mockResolvedValue({ result: 'success' })})- it('labels and submits the optional feedback field through the form', async () => {+ afterEach(() => vi.restoreAllMocks())++ it('submits feedback and logs out to the account-deleted sign-in page', async () => {+ const replace = vi.spyOn(window.location, 'replace').mockImplementation(() => {})const user = userEvent.setup()const onConfirm = vi.fn()@@ -38,13 +46,12 @@ describe('FeedBack', () => {await user.click(screen.getByRole('button', { name: 'common.operation.submit' }))await waitFor(() => {- expect(mockSendFeedback).toHaveBeenCalledWith({- email: '[email protected]',- feedback: 'The workspace is no longer needed.',- })+ expect(replace).toHaveBeenCalledExactlyOnceWith('/signin?account_deleted=true')})expect(onConfirm).toHaveBeenCalledOnce()- expect(mockLogout).toHaveBeenCalledOnce()- expect(mockUseLogout).toHaveBeenCalledWith({ redirectTo: '/signin?account_deleted=true' })+ expect(consoleClient.account.delete.feedback.post).toHaveBeenCalledExactlyOnceWith({+ body: { email: '[email protected]', feedback: 'The workspace is no longer needed.' },+ })+ expect(logout).toHaveBeenCalledOnce()})})diff --git a/web/app/account/(commonLayout)/delete-account/components/__tests__/verify-email.spec.tsx b/web/app/account/(commonLayout)/delete-account/components/__tests__/verify-email.spec.tsxindex 561982d7c7b..8896c9d7291 100644--- a/web/app/account/(commonLayout)/delete-account/components/__tests__/verify-email.spec.tsx+++ b/web/app/account/(commonLayout)/delete-account/components/__tests__/verify-email.spec.tsx@@ -1,34 +1,53 @@-import { render, screen, waitFor } from '@testing-library/react'+import { screen, waitFor } from '@testing-library/react'import userEvent from '@testing-library/user-event'+import { useState } from 'react'+import { consoleClient } from '@/service/console'+import { renderWithAccountProfile } from '@/test/console/account-profile'+import CheckEmail from '../check-email'import VerifyEmail from '../verify-email'-const mockConfirmDeleteAccount = vi.fn()-const mockSendEmail = vi.fn()--vi.mock('../../state', () => ({- useAccountDeleteStore: (selector: (state: { sendEmailToken: string }) => string) =>- selector({ sendEmailToken: 'email-token' }),- useConfirmDeleteAccount: () => ({- isPending: false,- mutateAsync: mockConfirmDeleteAccount,- }),- useSendDeleteAccountEmail: () => ({ mutate: mockSendEmail }),-}))--vi.mock('@/app/components/signin/countdown', () => ({- default: () => null,-}))+vi.mock('@/service/console', async (importOriginal) => {+ const actual = await importOriginal<typeof import('@/service/console')>()+ const { withConsoleClientResponses } = await import('@/test/console/service-responses')+ return {+ ...actual,+ consoleClient: withConsoleClientResponses(actual.consoleClient, {+ 'account.delete.verify.get': vi.fn(),+ 'account.delete.post': vi.fn(),+ }),+ }+})describe('VerifyEmail', () => {beforeEach(() => {- mockConfirmDeleteAccount.mockReset().mockResolvedValue({ result: 'success' })+ vi.mocked(consoleClient.account.delete.verify.get).mockResolvedValue({+ result: 'success',+ data: 'issued-deletion-token',+ })+ vi.mocked(consoleClient.account.delete.post).mockResolvedValue({ result: 'success' })})- it('submits a complete verification code through the form', async () => {+ it('submits a complete verification code with the token issued for this account', async () => {const user = userEvent.setup()const onConfirm = vi.fn()- render(<VerifyEmail onCancel={vi.fn()} onConfirm={onConfirm} />)+ // Reach verification through the real email request so the token comes from its owner.+ function DeleteAccountFlow() {+ const [sent, setSent] = useState(false)+ return sent ? (+ <VerifyEmail onCancel={() => setSent(false)} onConfirm={onConfirm} />+ ) : (+ <CheckEmail onCancel={vi.fn()} onConfirm={() => setSent(true)} />+ )+ }+ renderWithAccountProfile(<DeleteAccountFlow />, {+ accountProfile: { email: '[email protected]' },+ })+ await user.type(+ screen.getByRole('textbox', { name: 'accountSettings.account.deleteLabel' }),+ '[email protected]{Enter}',+ )+ await screen.findByLabelText('accountSettings.account.verificationLabel')const input = screen.getByLabelText('accountSettings.account.verificationLabel')const submitButton = screen.getByRole('button', {@@ -42,16 +61,15 @@ describe('VerifyEmail', () => {expect(input).toHaveAttribute('aria-invalid', 'true')expect(input).toHaveAccessibleDescription('accountSettings.account.verificationPlaceholder')expect(input).toHaveFocus()- expect(mockConfirmDeleteAccount).not.toHaveBeenCalled()+ expect(consoleClient.account.delete.post).not.toHaveBeenCalled()await user.type(input, '123456')await user.keyboard('{Enter}')await waitFor(() => {- expect(mockConfirmDeleteAccount).toHaveBeenCalledWith({- code: '123456',- token: 'email-token',+ expect(consoleClient.account.delete.post).toHaveBeenCalledWith({+ body: { code: '123456', token: 'issued-deletion-token' },})})expect(onConfirm).toHaveBeenCalledOnce()