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
80 changes: 77 additions & 3 deletions src/composables/useCoreCommands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ vi.mock('@/scripts/app', () => {
}
}),
openClipspace: vi.fn(),
queuePrompt: vi.fn().mockResolvedValue(true),
refreshComboInNodes: vi.fn().mockResolvedValue(undefined),
canvas: mockCanvas,
rootGraph: {
Expand Down Expand Up @@ -130,7 +131,9 @@ vi.mock('@/services/litegraphService', () => ({
const mockTrackHelpResourceClicked = vi.hoisted(() => vi.fn())
vi.mock('@/platform/telemetry', () => ({
useTelemetry: vi.fn(() => ({
trackHelpResourceClicked: mockTrackHelpResourceClicked
trackHelpResourceClicked: mockTrackHelpResourceClicked,
trackRunButton: vi.fn(),
trackWorkflowExecution: vi.fn()
}))
}))

Expand Down Expand Up @@ -205,13 +208,25 @@ vi.mock('@/platform/cloud/subscription/composables/useSubscription', () => ({
}))
}))

const mockBillingState = vi.hoisted(() => ({
canAccessSubscriptionFeatures: true,
showSubscriptionDialog: vi.fn()
}))
vi.mock('@/composables/billing/useBillingContext', () => ({
useBillingContext: vi.fn(() => ({
canAccessSubscriptionFeatures: { value: true },
showSubscriptionDialog: vi.fn()
canAccessSubscriptionFeatures: {
get value() {
return mockBillingState.canAccessSubscriptionFeatures
}
},
showSubscriptionDialog: mockBillingState.showSubscriptionDialog
}))
}))

vi.mock('@/stores/queueSettingsStore', () => ({
useQueueSettingsStore: vi.fn(() => ({ batchCount: 1 }))
}))

describe('useCoreCommands', () => {
const createMockNode = (id: number, comfyClass: string): LGraphNode => {
const baseNode = createMockLGraphNode({ id })
Expand Down Expand Up @@ -302,6 +317,7 @@ describe('useCoreCommands', () => {

beforeEach(() => {
mockDistributionState.isCloud = false
mockBillingState.canAccessSubscriptionFeatures = true
vi.mocked(app.refreshComboInNodes).mockResolvedValue(undefined)
mockModelStoreRefresh.mockResolvedValue(undefined)
mockMissingModelStoreRefresh.mockResolvedValue(undefined)
Expand Down Expand Up @@ -662,6 +678,64 @@ describe('useCoreCommands', () => {
})
})

describe('Queue commands subscription gate', () => {
const findCmd = (id: string) =>
useCoreCommands().find((cmd) => cmd.id === id)!

it.for([
['Comfy.QueuePrompt', 0],
['Comfy.QueuePromptFront', -1]
] as const)(
'%s queues on Local without subscription features',
async ([id, num]) => {
mockBillingState.canAccessSubscriptionFeatures = false

await findCmd(id).function()

expect(app.queuePrompt).toHaveBeenCalledWith(num, 1, expect.anything())
expect(mockBillingState.showSubscriptionDialog).not.toHaveBeenCalled()
}
)

it('Comfy.QueueSelectedOutputNodes passes the gate on Local without subscription features', async () => {
mockBillingState.canAccessSubscriptionFeatures = false

await findCmd('Comfy.QueueSelectedOutputNodes').function()

expect(mockBillingState.showSubscriptionDialog).not.toHaveBeenCalled()
expect(mockToastAdd).toHaveBeenCalledWith(
expect.objectContaining({ severity: 'error' })
)
})

it.for([
'Comfy.QueuePrompt',
'Comfy.QueuePromptFront',
'Comfy.QueueSelectedOutputNodes'
] as const)(
'%s shows the subscription dialog on Cloud without an active subscription',
async (id) => {
mockDistributionState.isCloud = true
mockBillingState.canAccessSubscriptionFeatures = false

await findCmd(id).function()

expect(app.queuePrompt).not.toHaveBeenCalled()
expect(mockBillingState.showSubscriptionDialog).toHaveBeenCalledWith({
reason: 'subscribe_to_run'
})
}
)

it('Comfy.QueuePrompt queues on Cloud with an active subscription', async () => {
mockDistributionState.isCloud = true

await findCmd('Comfy.QueuePrompt').function()

expect(app.queuePrompt).toHaveBeenCalledWith(0, 1, expect.anything())
})
})

describe('Help commands', () => {
const findCmd = (id: string) =>
useCoreCommands().find((cmd) => cmd.id === id)!
Expand Down
6 changes: 3 additions & 3 deletions src/composables/useCoreCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ export function useCoreCommands(): ComfyCommand[] {
trigger_source?: ExecutionTriggerSource
}) => {
trackRunButton(metadata)
if (!canAccessSubscriptionFeatures.value) {
if (isCloud && !canAccessSubscriptionFeatures.value) {
showSubscriptionDialog({ reason: 'subscribe_to_run' })
return
}
Expand All @@ -529,7 +529,7 @@ export function useCoreCommands(): ComfyCommand[] {
trigger_source?: ExecutionTriggerSource
}) => {
trackRunButton(metadata)
if (!canAccessSubscriptionFeatures.value) {
if (isCloud && !canAccessSubscriptionFeatures.value) {
showSubscriptionDialog({ reason: 'subscribe_to_run' })
return
}
Expand All @@ -551,7 +551,7 @@ export function useCoreCommands(): ComfyCommand[] {
trigger_source?: ExecutionTriggerSource
}) => {
trackRunButton(metadata)
if (!canAccessSubscriptionFeatures.value) {
if (isCloud && !canAccessSubscriptionFeatures.value) {
showSubscriptionDialog({ reason: 'subscribe_to_run' })
return
}
Expand Down
Loading