11import { vi } from 'vitest'
22
3+ /**
4+ * Real `WorkflowLockedError` subclass used by tests so `instanceof` checks in
5+ * route handlers behave the same as in production. Mirrors the shape exported
6+ * by `@sim/workflow-authz`.
7+ */
8+ export class MockWorkflowLockedError extends Error {
9+ readonly status = 423
10+
11+ constructor ( message = 'Workflow is locked' ) {
12+ super ( message )
13+ this . name = 'WorkflowLockedError'
14+ }
15+ }
16+
17+ /**
18+ * Real `FolderLockedError` subclass used by tests so `instanceof` checks in
19+ * route handlers behave the same as in production. Mirrors the shape exported
20+ * by `@sim/workflow-authz`.
21+ */
22+ export class MockFolderLockedError extends Error {
23+ readonly status = 423
24+
25+ constructor ( message = 'Folder is locked' ) {
26+ super ( message )
27+ this . name = 'FolderLockedError'
28+ }
29+ }
30+
31+ const unlockedStatus = {
32+ locked : false ,
33+ directLocked : false ,
34+ inheritedLocked : false ,
35+ lockedBy : null as 'workflow' | 'folder' | null ,
36+ lockedFolderId : null as string | null ,
37+ }
38+
339/**
440 * Controllable mocks for the `@sim/workflow-authz` package.
541 *
42+ * Defaults assume permissive access (no lock, write allowed). Override with
43+ * `mockResolvedValue` per test when exercising the lock/permission paths.
44+ *
645 * @example
746 * ```ts
847 * import { workflowAuthzMockFns } from '@sim/testing'
@@ -20,6 +59,10 @@ export const workflowAuthzMockFns = {
2059 mockGetActiveWorkflowContext : vi . fn ( ) ,
2160 mockGetActiveWorkflowRecord : vi . fn ( ) ,
2261 mockAssertActiveWorkflowContext : vi . fn ( ) ,
62+ mockGetFolderLockStatus : vi . fn ( ) . mockResolvedValue ( unlockedStatus ) ,
63+ mockGetWorkflowLockStatus : vi . fn ( ) . mockResolvedValue ( unlockedStatus ) ,
64+ mockAssertWorkflowMutable : vi . fn ( ) . mockResolvedValue ( undefined ) ,
65+ mockAssertFolderMutable : vi . fn ( ) . mockResolvedValue ( undefined ) ,
2366}
2467
2568/**
@@ -36,4 +79,10 @@ export const workflowAuthzMock = {
3679 getActiveWorkflowContext : workflowAuthzMockFns . mockGetActiveWorkflowContext ,
3780 getActiveWorkflowRecord : workflowAuthzMockFns . mockGetActiveWorkflowRecord ,
3881 assertActiveWorkflowContext : workflowAuthzMockFns . mockAssertActiveWorkflowContext ,
82+ getFolderLockStatus : workflowAuthzMockFns . mockGetFolderLockStatus ,
83+ getWorkflowLockStatus : workflowAuthzMockFns . mockGetWorkflowLockStatus ,
84+ assertWorkflowMutable : workflowAuthzMockFns . mockAssertWorkflowMutable ,
85+ assertFolderMutable : workflowAuthzMockFns . mockAssertFolderMutable ,
86+ WorkflowLockedError : MockWorkflowLockedError ,
87+ FolderLockedError : MockFolderLockedError ,
3988}
0 commit comments