From 59de045a0ee694d20b0db30e87d667019c691784 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Fri, 13 Nov 2026 10:48:17 -0500 Subject: [PATCH 1/2] refactor(billing): settle the auto top-up review follow-ups - AddCreditsAutoTopUpField merges into AddCreditsAmountField; the amount step keeps its reserved note height and test ids. - useAddCreditsAutoTopUp uses centsToCredits. - The useBillingAutoTopUpCard mock is configured through its return value instead of a private state ref. --- .../addCredits/AddCreditsAmountField.vue | 54 +++++++++---- .../addCredits/AddCreditsAmountStep.vue | 4 + .../addCredits/AddCreditsAutoTopUpCard.vue | 17 +++-- .../addCredits/AddCreditsAutoTopUpField.vue | 76 ------------------- .../addCredits/useAddCreditsAutoTopUp.ts | 5 +- .../AddCreditsDialogContent.test.ts | 7 +- .../components/TopUpAutoTopUpCard.test.ts | 4 +- ...TopUpCreditsDialogContentWorkspace.test.ts | 7 +- .../__mocks__/useBillingAutoTopUpCard.ts | 35 +++++---- .../useAddCreditsAutoTopUpOffer.test.ts | 7 +- 10 files changed, 92 insertions(+), 124 deletions(-) delete mode 100644 packages/account-ui/src/billing/addCredits/AddCreditsAutoTopUpField.vue diff --git a/packages/account-ui/src/billing/addCredits/AddCreditsAmountField.vue b/packages/account-ui/src/billing/addCredits/AddCreditsAmountField.vue index 77ac175825c..b1a56a72a84 100644 --- a/packages/account-ui/src/billing/addCredits/AddCreditsAmountField.vue +++ b/packages/account-ui/src/billing/addCredits/AddCreditsAmountField.vue @@ -11,51 +11,79 @@ ) " > - +

- {{ error }} + {{ error ?? hint }}

diff --git a/packages/account-ui/src/billing/addCredits/useAddCreditsAutoTopUp.ts b/packages/account-ui/src/billing/addCredits/useAddCreditsAutoTopUp.ts index 530b712b0ad..acb8ca51d41 100644 --- a/packages/account-ui/src/billing/addCredits/useAddCreditsAutoTopUp.ts +++ b/packages/account-ui/src/billing/addCredits/useAddCreditsAutoTopUp.ts @@ -9,12 +9,13 @@ import type { import { autoTopUpActivationFor, autoTopUpTargetFor, - CREDITS_PER_USD, parseAutoTopUpForm, startAutoTopUpForm, validateAutoTopUp } from '@comfyorg/account-core/billing' +import { centsToCredits } from '#/billing/tab/creditsCardCopy' + export type AddCreditsAutoTopUpRequest = | { readonly kind: 'not_offered' } | { readonly kind: 'unchecked' } @@ -33,7 +34,7 @@ export function useAddCreditsAutoTopUp( const edits = shallowRef>({}) const creditsPicked = computed(() => - Math.round(((toValue(amountCents) ?? 0) * CREDITS_PER_USD) / 100) + centsToCredits(toValue(amountCents) ?? 0) ) const input = computed(() => { diff --git a/src/platform/billing/components/AddCreditsDialogContent.test.ts b/src/platform/billing/components/AddCreditsDialogContent.test.ts index 1377d4d855f..d80fa83cc9d 100644 --- a/src/platform/billing/components/AddCreditsDialogContent.test.ts +++ b/src/platform/billing/components/AddCreditsDialogContent.test.ts @@ -12,13 +12,14 @@ import enMessages from '@/locales/en/main.json' with { type: 'json' } import { readAutoTopUpActivation } from '@/platform/billing/addCredits/autoTopUpActivation' import { billingApi } from '@/platform/billing/api/billingApi' import { - autoTopUpCardState, + autoTopUpCard, loadedAutoTopUp } from '@/platform/billing/composables/__mocks__/useBillingAutoTopUpCard' import { autoTopUpEnabledFact, canManageAutoTopUpFact } from '@/platform/billing/composables/__mocks__/useBillingCapabilities' +import { useBillingAutoTopUpCard } from '@/platform/billing/composables/useBillingAutoTopUpCard' import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities' import { useBillingSdkStore } from '@/platform/billing/sdk/billingSdkStore' import { workspaceApi } from '@/platform/workspace/api/workspaceApi' @@ -178,7 +179,9 @@ function renderDialog({ capabilities.autoTopUpEnabled = autoTopUpEnabledFact(true) capabilities.canManageAutoTopUp = canManageAutoTopUpFact(true) capabilities.autoTopUpSetup = computed(() => ({ state: 'ready' })) - autoTopUpCardState.value = loadedAutoTopUp('off') + vi.mocked(useBillingAutoTopUpCard).mockReturnValue( + autoTopUpCard(loadedAutoTopUp('off')) + ) vi.mocked(useBillingSdkStore().readPaymentMethods).mockResolvedValue({ status: 'ok', value: [] diff --git a/src/platform/billing/components/TopUpAutoTopUpCard.test.ts b/src/platform/billing/components/TopUpAutoTopUpCard.test.ts index 51fd394a22f..499918de8af 100644 --- a/src/platform/billing/components/TopUpAutoTopUpCard.test.ts +++ b/src/platform/billing/components/TopUpAutoTopUpCard.test.ts @@ -8,7 +8,7 @@ import { createI18n } from 'vue-i18n' import enMessages from '@/locales/en/main.json' import { useTelemetry } from '@comfyorg/telemetry' import { - autoTopUpCardState, + autoTopUpCard, loadedAutoTopUp } from '@/platform/billing/composables/__mocks__/useBillingAutoTopUpCard' import { @@ -57,7 +57,7 @@ function renderCard(served: Partial = {}) { capabilities.autoTopUpEnabled = autoTopUpEnabledFact(enabled) capabilities.canManageAutoTopUp = canManageAutoTopUpFact(canManage) capabilities.autoTopUpSetup = computed(() => setup) - autoTopUpCardState.value = card + vi.mocked(useBillingAutoTopUpCard).mockReturnValue(autoTopUpCard(card)) render(TopUpAutoTopUpCard, { global: { plugins: [ diff --git a/src/platform/billing/components/TopUpCreditsDialogContentWorkspace.test.ts b/src/platform/billing/components/TopUpCreditsDialogContentWorkspace.test.ts index 0ffd5db8c19..a5596c66b16 100644 --- a/src/platform/billing/components/TopUpCreditsDialogContentWorkspace.test.ts +++ b/src/platform/billing/components/TopUpCreditsDialogContentWorkspace.test.ts @@ -41,13 +41,14 @@ import type { CreateTopupResponse } from '@comfyorg/billing-core' import { billingOperation } from '@/platform/billing/composables/billingOperationTestUtils' import type { BillingOperation } from '@/platform/billing/composables/billingOperationTestUtils' import { - autoTopUpCardState, + autoTopUpCard, loadedAutoTopUp } from '@/platform/billing/composables/__mocks__/useBillingAutoTopUpCard' import { autoTopUpEnabledFact, canManageAutoTopUpFact } from '@/platform/billing/composables/__mocks__/useBillingCapabilities' +import { useBillingAutoTopUpCard } from '@/platform/billing/legacy160/platform/billing/composables/useBillingAutoTopUpCard' import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities' import { mockBillingContext } from '@/utils/__tests__/mockBillingContext' @@ -2669,7 +2670,9 @@ describe('TopUpCreditsDialogContentWorkspace', () => { capabilities.autoTopUpSetup = computed(() => ({ state: 'ready' as const })) - autoTopUpCardState.value = loadedAutoTopUp('off') + vi.mocked(useBillingAutoTopUpCard).mockReturnValue( + autoTopUpCard(loadedAutoTopUp('off')) + ) }) it('sits above Add credits on the amount step', () => { diff --git a/src/platform/billing/composables/__mocks__/useBillingAutoTopUpCard.ts b/src/platform/billing/composables/__mocks__/useBillingAutoTopUpCard.ts index 2aa30e2b7e5..ce4d64939fc 100644 --- a/src/platform/billing/composables/__mocks__/useBillingAutoTopUpCard.ts +++ b/src/platform/billing/composables/__mocks__/useBillingAutoTopUpCard.ts @@ -1,5 +1,5 @@ -import { onTestFinished, vi } from 'vitest' -import { computed, shallowRef } from 'vue' +import { vi } from 'vitest' +import { computed } from 'vue' import type { AutoReloadSettings } from '@comfyorg/billing-core' import type { useBillingAutoTopUpCard as realUseBillingAutoTopUpCard } from '@/platform/billing/composables/useBillingAutoTopUpCard' @@ -38,21 +38,20 @@ export function loadedAutoTopUp( return { kind: 'loaded', settings: { ...offSettings, status } } } -export const autoTopUpCardState = shallowRef({ - kind: 'loading' -}) - -const card: AutoTopUpCard = { - scope: computed(() => 'workspace-test'), - state: computed(() => autoTopUpCardState.value), - isReady: computed(() => autoTopUpCardState.value.kind !== 'loading'), - ensureRead: vi.fn(), - retry: vi.fn(async () => undefined) +/** A card serving `state`; pass it to `vi.mocked(useBillingAutoTopUpCard).mockReturnValue`. */ +export function autoTopUpCard( + state: AutoTopUpCardState = { kind: 'loading' } +): AutoTopUpCard { + return { + scope: computed(() => 'workspace-test'), + state: computed(() => state), + isReady: computed(() => state.kind !== 'loading'), + ensureRead: vi.fn(), + retry: vi.fn(async () => undefined) + } } -export const useBillingAutoTopUpCard = vi.fn(() => { - onTestFinished(() => { - autoTopUpCardState.value = { kind: 'loading' } - }) - return card -}) +const card = autoTopUpCard() + +// The config's mockReset restores this loading card after each test. +export const useBillingAutoTopUpCard = vi.fn(() => card) diff --git a/src/platform/billing/composables/useAddCreditsAutoTopUpOffer.test.ts b/src/platform/billing/composables/useAddCreditsAutoTopUpOffer.test.ts index 8f8a9a2240d..57546df72c9 100644 --- a/src/platform/billing/composables/useAddCreditsAutoTopUpOffer.test.ts +++ b/src/platform/billing/composables/useAddCreditsAutoTopUpOffer.test.ts @@ -7,7 +7,7 @@ import { reportError } from '@comfyorg/telemetry/reportError' import { useFeatureFlags } from '@/composables/useFeatureFlags' import { activateBillingScope } from '@/platform/billing/__tests__/activateBillingScope' import { - autoTopUpCardState, + autoTopUpCard, loadedAutoTopUp } from '@/platform/billing/composables/__mocks__/useBillingAutoTopUpCard' import { @@ -15,6 +15,7 @@ import { canManageAutoTopUpFact } from '@/platform/billing/composables/__mocks__/useBillingCapabilities' import { useAddCreditsAutoTopUpOffer } from '@/platform/billing/composables/useAddCreditsAutoTopUpOffer' +import { useBillingAutoTopUpCard } from '@/platform/billing/composables/useBillingAutoTopUpCard' import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities' import { useBillingSdkStore } from '@/platform/billing/sdk/billingSdkStore' @@ -65,7 +66,9 @@ function offerFor({ capabilities.autoTopUpEnabled = autoTopUpEnabledFact(rollout) capabilities.canManageAutoTopUp = canManageAutoTopUpFact(true) capabilities.autoTopUpSetup = computed(() => ({ state: 'ready' })) - autoTopUpCardState.value = loadedAutoTopUp(status) + vi.mocked(useBillingAutoTopUpCard).mockReturnValue( + autoTopUpCard(loadedAutoTopUp(status)) + ) const scope = effectScope() onTestFinished(() => scope.stop()) return scope.run(useAddCreditsAutoTopUpOffer)! From 94f9c265f236fa3122b5dcb6ce8452447a851ca2 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Fri, 13 Nov 2026 18:02:47 -0500 Subject: [PATCH 2/2] chore(billing): drop two comments from the auto top-up card mock --- .../billing/composables/__mocks__/useBillingAutoTopUpCard.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/platform/billing/composables/__mocks__/useBillingAutoTopUpCard.ts b/src/platform/billing/composables/__mocks__/useBillingAutoTopUpCard.ts index ce4d64939fc..ddefd34aa03 100644 --- a/src/platform/billing/composables/__mocks__/useBillingAutoTopUpCard.ts +++ b/src/platform/billing/composables/__mocks__/useBillingAutoTopUpCard.ts @@ -38,7 +38,6 @@ export function loadedAutoTopUp( return { kind: 'loaded', settings: { ...offSettings, status } } } -/** A card serving `state`; pass it to `vi.mocked(useBillingAutoTopUpCard).mockReturnValue`. */ export function autoTopUpCard( state: AutoTopUpCardState = { kind: 'loading' } ): AutoTopUpCard { @@ -53,5 +52,4 @@ export function autoTopUpCard( const card = autoTopUpCard() -// The config's mockReset restores this loading card after each test. export const useBillingAutoTopUpCard = vi.fn(() => card)