Skip to content

Commit a752aab

Browse files
committed
fix(workflows): align cancellation adapter test
1 parent d078c06 commit a752aab

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

  • apps/sim/app/api/v2/workflows/[workflowId]/runs/[runId]

apps/sim/app/api/v2/workflows/[workflowId]/runs/[runId]/route.test.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
1414

1515
const mocks = vi.hoisted(() => ({
1616
cancel: vi.fn(),
17-
capture: vi.fn(),
1817
readRun: vi.fn(),
1918
authorizeReadRun: vi.fn(),
2019
}))
2120

2221
vi.mock('@/lib/api/server/routes/v2-api-key-auth', () => v2ApiKeyAuthModuleMock)
2322
vi.mock('@/lib/core/rate-limiter', () => v2RateLimiterModuleMock)
2423

25-
vi.mock('@/lib/posthog/server', () => ({ captureServerEvent: mocks.capture }))
26-
2724
vi.mock('@/lib/workflows/application/read-workflow-run', () => ({
2825
readWorkflowRun: {
2926
operation: { id: 'workflows.runs.read' },
@@ -370,7 +367,6 @@ describe('v2 run detail and cancel adapters', () => {
370367
'v2:workflows.runs.cancel:api-key:key-1',
371368
expect.anything()
372369
)
373-
expect(mocks.capture).not.toHaveBeenCalled()
374370
})
375371

376372
it('keeps cancellation request-rate admission separate from run control', async () => {
@@ -399,13 +395,17 @@ describe('v2 run detail and cancel adapters', () => {
399395
code: 'FORBIDDEN',
400396
message: 'Insufficient workspace permissions',
401397
})
402-
expect(mocks.capture).not.toHaveBeenCalled()
403398
})
404399

405-
it('projects cancellation analytics only after a successful personal-key result', async () => {
400+
it('passes a personal-key principal to the cancellation use case', async () => {
401+
const personalPrincipal = {
402+
kind: 'personal_api_key' as const,
403+
userId: 'key-user',
404+
keyId: 'personal-key',
405+
}
406406
v2RouteMocks.authenticate.mockResolvedValueOnce({
407407
...auth,
408-
principal: { kind: 'personal_api_key', userId: 'key-user', keyId: 'personal-key' },
408+
principal: personalPrincipal,
409409
rateLimitSubjectIds: ['api-key:personal-key', 'user:key-user'],
410410
keyType: 'personal',
411411
})
@@ -415,12 +415,10 @@ describe('v2 run detail and cancel adapters', () => {
415415
})
416416

417417
expect(response.status).toBe(200)
418-
expect(mocks.capture).toHaveBeenCalledOnce()
419-
expect(mocks.capture).toHaveBeenCalledWith(
420-
'key-user',
421-
'workflow_execution_cancelled',
422-
{ workflow_id: 'workflow-1', workspace_id: 'workspace-1' },
423-
{ groups: { workspace: 'workspace-1' } }
424-
)
418+
expect(mocks.cancel).toHaveBeenCalledWith({
419+
principal: personalPrincipal,
420+
input: { workflowId: 'workflow-1', runId: 'run-1' },
421+
request: expect.anything(),
422+
})
425423
})
426424
})

0 commit comments

Comments
 (0)