-
Notifications
You must be signed in to change notification settings - Fork 619
fix(billing): refresh workspace billing status after completed top-up (FE-932) #12787
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
Merged
dante01yoon
merged 2 commits into
main
from
jaewon/fe-932-refresh-workspace-billing-status-after-completed-top-up
Jun 19, 2026
+167
−2
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
177 changes: 177 additions & 0 deletions
177
src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| import { render, screen } from '@testing-library/vue' | ||
| import userEvent from '@testing-library/user-event' | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import { createI18n } from 'vue-i18n' | ||
|
|
||
| import TopUpCreditsDialogContentWorkspace from './TopUpCreditsDialogContentWorkspace.vue' | ||
|
|
||
| type TopupStatus = 'pending' | 'completed' | 'failed' | ||
|
|
||
| interface CreateTopupResponse { | ||
| billing_op_id: string | ||
| topup_id: string | ||
| status: TopupStatus | ||
| amount_cents: number | ||
| } | ||
|
|
||
| const mockFetchBalance = vi.fn() | ||
| const mockFetchStatus = vi.fn() | ||
| const mockCreateTopup = vi.fn<() => Promise<CreateTopupResponse>>() | ||
| const mockStartOperation = vi.fn() | ||
| const mockShowSettings = vi.fn() | ||
| const mockToastAdd = vi.fn() | ||
|
|
||
| vi.mock('@/composables/billing/useBillingContext', () => ({ | ||
| useBillingContext: () => ({ | ||
| fetchBalance: mockFetchBalance, | ||
| fetchStatus: mockFetchStatus | ||
| }) | ||
| })) | ||
|
|
||
| vi.mock('@/platform/workspace/api/workspaceApi', () => ({ | ||
| workspaceApi: { | ||
| createTopup: () => mockCreateTopup() | ||
| } | ||
| })) | ||
|
|
||
| vi.mock('@/platform/workspace/stores/billingOperationStore', () => ({ | ||
| useBillingOperationStore: () => ({ | ||
| hasPendingOperations: false, | ||
| startOperation: mockStartOperation | ||
| }) | ||
| })) | ||
|
|
||
| vi.mock('@/platform/settings/composables/useSettingsDialog', () => ({ | ||
| useSettingsDialog: () => ({ show: mockShowSettings }) | ||
| })) | ||
|
|
||
| vi.mock('@/stores/dialogStore', () => ({ | ||
| useDialogStore: () => ({ closeDialog: vi.fn() }) | ||
| })) | ||
|
|
||
| vi.mock('@/platform/telemetry', () => ({ | ||
| useTelemetry: () => ({ | ||
| trackApiCreditTopupButtonPurchaseClicked: vi.fn() | ||
| }) | ||
| })) | ||
|
|
||
| vi.mock('@/platform/telemetry/topupTracker', () => ({ | ||
| clearTopupTracking: vi.fn() | ||
| })) | ||
|
|
||
| vi.mock('@/composables/useExternalLink', () => ({ | ||
| useExternalLink: () => ({ | ||
| buildDocsUrl: () => 'https://docs.comfy.org', | ||
| docsPaths: { partnerNodesPricing: '' } | ||
| }) | ||
| })) | ||
|
|
||
| vi.mock('primevue/usetoast', () => ({ | ||
| useToast: () => ({ add: mockToastAdd }) | ||
| })) | ||
|
|
||
| vi.mock('@/base/credits/comfyCredits', () => ({ | ||
| creditsToUsd: (credits: number) => credits, | ||
| usdToCredits: (usd: number) => usd | ||
| })) | ||
|
|
||
| const i18n = createI18n({ | ||
| legacy: false, | ||
| locale: 'en', | ||
| messages: { | ||
| en: { | ||
| g: { close: 'Close' }, | ||
| subscription: { addCredits: 'Add credits' }, | ||
| credits: { | ||
| topUp: { | ||
| addMoreCredits: 'Add more credits', | ||
| addMoreCreditsToRun: 'Add more credits to run', | ||
| selectAmount: 'Select amount', | ||
| youPay: 'You pay', | ||
| youGet: 'You get', | ||
| purchaseSuccess: 'Credits added successfully!', | ||
| purchaseError: 'Purchase Failed', | ||
| purchaseErrorDetail: 'Failed to purchase credits: {error}', | ||
| unknownError: 'An unknown error occurred', | ||
| minRequired: 'Minimum required', | ||
| maxAllowed: 'Maximum allowed', | ||
| needMore: 'Need more?', | ||
| contactUs: 'Contact us', | ||
| viewPricing: 'View pricing', | ||
| insufficientWorkflowMessage: 'Insufficient credits' | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| function topupResponse( | ||
| status: CreateTopupResponse['status'] | ||
| ): CreateTopupResponse { | ||
| return { | ||
| billing_op_id: 'op-1', | ||
| topup_id: 'topup-1', | ||
| status, | ||
| amount_cents: 5000 | ||
| } | ||
| } | ||
|
|
||
| function renderDialog() { | ||
| return render(TopUpCreditsDialogContentWorkspace, { | ||
| global: { | ||
| plugins: [i18n], | ||
| stubs: { | ||
| FormattedNumberStepper: { | ||
| name: 'FormattedNumberStepper', | ||
| props: ['modelValue'], | ||
| template: '<div />' | ||
| } | ||
| } | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| async function clickAddCredits() { | ||
| const user = userEvent.setup() | ||
| await user.click(screen.getByRole('button', { name: 'Add credits' })) | ||
| } | ||
|
|
||
| describe('TopUpCreditsDialogContentWorkspace', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| mockFetchBalance.mockResolvedValue(undefined) | ||
| mockFetchStatus.mockResolvedValue(undefined) | ||
| }) | ||
|
|
||
| it('refreshes both balance and status after a completed top-up', async () => { | ||
| mockCreateTopup.mockResolvedValue(topupResponse('completed')) | ||
|
|
||
| renderDialog() | ||
| await clickAddCredits() | ||
|
|
||
| expect(mockFetchBalance).toHaveBeenCalledOnce() | ||
| expect(mockFetchStatus).toHaveBeenCalledOnce() | ||
| expect(mockShowSettings).toHaveBeenCalledWith('workspace') | ||
| }) | ||
|
|
||
| it('does not refresh balance or status for a pending top-up', async () => { | ||
| mockCreateTopup.mockResolvedValue(topupResponse('pending')) | ||
|
|
||
| renderDialog() | ||
| await clickAddCredits() | ||
|
|
||
| expect(mockStartOperation).toHaveBeenCalledWith('op-1', 'topup') | ||
| expect(mockFetchBalance).not.toHaveBeenCalled() | ||
| expect(mockFetchStatus).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('does not refresh balance or status for a failed top-up', async () => { | ||
| mockCreateTopup.mockResolvedValue(topupResponse('failed')) | ||
|
|
||
| renderDialog() | ||
| await clickAddCredits() | ||
|
|
||
| expect(mockFetchBalance).not.toHaveBeenCalled() | ||
| expect(mockFetchStatus).not.toHaveBeenCalled() | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.