Skip to content

Commit 496be57

Browse files
committed
fix tests
1 parent ec980ad commit 496be57

File tree

6 files changed

+148
-131
lines changed

6 files changed

+148
-131
lines changed

apps/sim/socket/index.test.ts

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -294,44 +294,61 @@ describe('Socket Server Index Integration', () => {
294294
const { WorkflowOperationSchema } = await import('@/socket/validation/schemas')
295295

296296
const validOperation = {
297-
operation: 'add',
298-
target: 'block',
297+
operation: 'batch-add-blocks',
298+
target: 'blocks',
299299
payload: {
300-
id: 'test-block',
301-
type: 'action',
302-
name: 'Test Block',
303-
position: { x: 100, y: 200 },
300+
blocks: [
301+
{
302+
id: 'test-block',
303+
type: 'action',
304+
name: 'Test Block',
305+
position: { x: 100, y: 200 },
306+
},
307+
],
308+
edges: [],
309+
loops: {},
310+
parallels: {},
311+
subBlockValues: {},
304312
},
305313
timestamp: Date.now(),
306314
}
307315

308316
expect(() => WorkflowOperationSchema.parse(validOperation)).not.toThrow()
309317
})
310318

311-
it.concurrent('should validate block operations with autoConnectEdge', async () => {
319+
it.concurrent('should validate batch-add-blocks with edges', async () => {
312320
const { WorkflowOperationSchema } = await import('@/socket/validation/schemas')
313321

314-
const validOperationWithAutoEdge = {
315-
operation: 'add',
316-
target: 'block',
322+
const validOperationWithEdge = {
323+
operation: 'batch-add-blocks',
324+
target: 'blocks',
317325
payload: {
318-
id: 'test-block',
319-
type: 'action',
320-
name: 'Test Block',
321-
position: { x: 100, y: 200 },
322-
autoConnectEdge: {
323-
id: 'auto-edge-123',
324-
source: 'source-block',
325-
target: 'test-block',
326-
sourceHandle: 'output',
327-
targetHandle: 'target',
328-
type: 'workflowEdge',
329-
},
326+
blocks: [
327+
{
328+
id: 'test-block',
329+
type: 'action',
330+
name: 'Test Block',
331+
position: { x: 100, y: 200 },
332+
},
333+
],
334+
edges: [
335+
{
336+
id: 'auto-edge-123',
337+
source: 'source-block',
338+
target: 'test-block',
339+
sourceHandle: 'output',
340+
targetHandle: 'target',
341+
type: 'workflowEdge',
342+
},
343+
],
344+
loops: {},
345+
parallels: {},
346+
subBlockValues: {},
330347
},
331348
timestamp: Date.now(),
332349
}
333350

334-
expect(() => WorkflowOperationSchema.parse(validOperationWithAutoEdge)).not.toThrow()
351+
expect(() => WorkflowOperationSchema.parse(validOperationWithEdge)).not.toThrow()
335352
})
336353

337354
it.concurrent('should validate edge operations', async () => {

apps/sim/socket/middleware/permissions.test.ts

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ describe('checkRolePermission', () => {
2727
}
2828
})
2929

30-
it('should allow add operation', () => {
31-
const result = checkRolePermission('admin', 'add')
30+
it('should allow batch-add-blocks operation', () => {
31+
const result = checkRolePermission('admin', 'batch-add-blocks')
3232
expectPermissionAllowed(result)
3333
})
3434

35-
it('should allow remove operation', () => {
36-
const result = checkRolePermission('admin', 'remove')
35+
it('should allow batch-remove-blocks operation', () => {
36+
const result = checkRolePermission('admin', 'batch-remove-blocks')
3737
expectPermissionAllowed(result)
3838
})
3939

@@ -42,8 +42,8 @@ describe('checkRolePermission', () => {
4242
expectPermissionAllowed(result)
4343
})
4444

45-
it('should allow duplicate operation', () => {
46-
const result = checkRolePermission('admin', 'duplicate')
45+
it('should allow batch-update-positions operation', () => {
46+
const result = checkRolePermission('admin', 'batch-update-positions')
4747
expectPermissionAllowed(result)
4848
})
4949

@@ -63,13 +63,13 @@ describe('checkRolePermission', () => {
6363
}
6464
})
6565

66-
it('should allow add operation', () => {
67-
const result = checkRolePermission('write', 'add')
66+
it('should allow batch-add-blocks operation', () => {
67+
const result = checkRolePermission('write', 'batch-add-blocks')
6868
expectPermissionAllowed(result)
6969
})
7070

71-
it('should allow remove operation', () => {
72-
const result = checkRolePermission('write', 'remove')
71+
it('should allow batch-remove-blocks operation', () => {
72+
const result = checkRolePermission('write', 'batch-remove-blocks')
7373
expectPermissionAllowed(result)
7474
})
7575

@@ -85,14 +85,14 @@ describe('checkRolePermission', () => {
8585
expectPermissionAllowed(result)
8686
})
8787

88-
it('should deny add operation for read role', () => {
89-
const result = checkRolePermission('read', 'add')
88+
it('should deny batch-add-blocks operation for read role', () => {
89+
const result = checkRolePermission('read', 'batch-add-blocks')
9090
expectPermissionDenied(result, 'read')
91-
expectPermissionDenied(result, 'add')
91+
expectPermissionDenied(result, 'batch-add-blocks')
9292
})
9393

94-
it('should deny remove operation for read role', () => {
95-
const result = checkRolePermission('read', 'remove')
94+
it('should deny batch-remove-blocks operation for read role', () => {
95+
const result = checkRolePermission('read', 'batch-remove-blocks')
9696
expectPermissionDenied(result, 'read')
9797
})
9898

@@ -101,9 +101,9 @@ describe('checkRolePermission', () => {
101101
expectPermissionDenied(result, 'read')
102102
})
103103

104-
it('should deny duplicate operation for read role', () => {
105-
const result = checkRolePermission('read', 'duplicate')
106-
expectPermissionDenied(result, 'read')
104+
it('should allow batch-update-positions operation for read role', () => {
105+
const result = checkRolePermission('read', 'batch-update-positions')
106+
expectPermissionAllowed(result)
107107
})
108108

109109
it('should deny replace-state operation for read role', () => {
@@ -117,7 +117,8 @@ describe('checkRolePermission', () => {
117117
})
118118

119119
it('should deny all write operations for read role', () => {
120-
const writeOperations = SOCKET_OPERATIONS.filter((op) => op !== 'update-position')
120+
const readAllowedOps = ['update-position', 'batch-update-positions']
121+
const writeOperations = SOCKET_OPERATIONS.filter((op) => !readAllowedOps.includes(op))
121122

122123
for (const operation of writeOperations) {
123124
const result = checkRolePermission('read', operation)
@@ -138,7 +139,7 @@ describe('checkRolePermission', () => {
138139
})
139140

140141
it('should deny operations for empty role', () => {
141-
const result = checkRolePermission('', 'add')
142+
const result = checkRolePermission('', 'batch-add-blocks')
142143
expectPermissionDenied(result)
143144
})
144145
})
@@ -186,15 +187,21 @@ describe('checkRolePermission', () => {
186187

187188
it('should verify read has minimal permissions', () => {
188189
const readOps = ROLE_ALLOWED_OPERATIONS.read
189-
expect(readOps).toHaveLength(1)
190+
expect(readOps).toHaveLength(2)
190191
expect(readOps).toContain('update-position')
192+
expect(readOps).toContain('batch-update-positions')
191193
})
192194
})
193195

194196
describe('specific operations', () => {
195197
const testCases = [
196-
{ operation: 'add', adminAllowed: true, writeAllowed: true, readAllowed: false },
197-
{ operation: 'remove', adminAllowed: true, writeAllowed: true, readAllowed: false },
198+
{ operation: 'batch-add-blocks', adminAllowed: true, writeAllowed: true, readAllowed: false },
199+
{
200+
operation: 'batch-remove-blocks',
201+
adminAllowed: true,
202+
writeAllowed: true,
203+
readAllowed: false,
204+
},
198205
{ operation: 'update', adminAllowed: true, writeAllowed: true, readAllowed: false },
199206
{ operation: 'update-position', adminAllowed: true, writeAllowed: true, readAllowed: true },
200207
{ operation: 'update-name', adminAllowed: true, writeAllowed: true, readAllowed: false },
@@ -214,7 +221,12 @@ describe('checkRolePermission', () => {
214221
readAllowed: false,
215222
},
216223
{ operation: 'toggle-handles', adminAllowed: true, writeAllowed: true, readAllowed: false },
217-
{ operation: 'duplicate', adminAllowed: true, writeAllowed: true, readAllowed: false },
224+
{
225+
operation: 'batch-update-positions',
226+
adminAllowed: true,
227+
writeAllowed: true,
228+
readAllowed: true,
229+
},
218230
{ operation: 'replace-state', adminAllowed: true, writeAllowed: true, readAllowed: false },
219231
]
220232

@@ -238,13 +250,13 @@ describe('checkRolePermission', () => {
238250

239251
describe('reason messages', () => {
240252
it('should include role in denial reason', () => {
241-
const result = checkRolePermission('read', 'add')
253+
const result = checkRolePermission('read', 'batch-add-blocks')
242254
expect(result.reason).toContain("'read'")
243255
})
244256

245257
it('should include operation in denial reason', () => {
246-
const result = checkRolePermission('read', 'add')
247-
expect(result.reason).toContain("'add'")
258+
const result = checkRolePermission('read', 'batch-add-blocks')
259+
expect(result.reason).toContain("'batch-add-blocks'")
248260
})
249261

250262
it('should have descriptive denial message format', () => {

apps/sim/stores/undo-redo/store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ function isOperationApplicable(
8686
switch (operation.type) {
8787
case 'batch-remove-blocks': {
8888
const op = operation as BatchRemoveBlocksOperation
89-
return op.data.blockSnapshots.some((block) => Boolean(graph.blocksById[block.id]))
89+
return op.data.blockSnapshots.every((block) => Boolean(graph.blocksById[block.id]))
9090
}
9191
case 'batch-add-blocks': {
9292
const op = operation as BatchAddBlocksOperation
93-
return op.data.blockSnapshots.some((block) => !graph.blocksById[block.id])
93+
return op.data.blockSnapshots.every((block) => !graph.blocksById[block.id])
9494
}
9595
case 'move-block': {
9696
const op = operation as MoveBlockOperation

packages/testing/src/factories/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,22 +120,20 @@ export {
120120
} from './serialized-block.factory'
121121
// Undo/redo operation factories
122122
export {
123-
type AddBlockOperation,
124123
type AddEdgeOperation,
125124
type BaseOperation,
125+
type BatchAddBlocksOperation,
126+
type BatchRemoveBlocksOperation,
126127
createAddBlockEntry,
127128
createAddEdgeEntry,
128-
createDuplicateBlockEntry,
129129
createMoveBlockEntry,
130130
createRemoveBlockEntry,
131131
createRemoveEdgeEntry,
132132
createUpdateParentEntry,
133-
type DuplicateBlockOperation,
134133
type MoveBlockOperation,
135134
type Operation,
136135
type OperationEntry,
137136
type OperationType,
138-
type RemoveBlockOperation,
139137
type RemoveEdgeOperation,
140138
type UpdateParentOperation,
141139
} from './undo-redo.factory'

packages/testing/src/factories/permission.factory.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ export function createWorkflowAccessContext(options: {
255255
* All socket operations that can be performed.
256256
*/
257257
export const SOCKET_OPERATIONS = [
258-
'add',
259-
'remove',
258+
'batch-add-blocks',
259+
'batch-remove-blocks',
260260
'update',
261261
'update-position',
262262
'update-name',
@@ -266,7 +266,7 @@ export const SOCKET_OPERATIONS = [
266266
'update-advanced-mode',
267267
'update-trigger-mode',
268268
'toggle-handles',
269-
'duplicate',
269+
'batch-update-positions',
270270
'replace-state',
271271
] as const
272272

@@ -278,7 +278,7 @@ export type SocketOperation = (typeof SOCKET_OPERATIONS)[number]
278278
export const ROLE_ALLOWED_OPERATIONS: Record<PermissionType, SocketOperation[]> = {
279279
admin: [...SOCKET_OPERATIONS],
280280
write: [...SOCKET_OPERATIONS],
281-
read: ['update-position'],
281+
read: ['update-position', 'batch-update-positions'],
282282
}
283283

284284
/**

0 commit comments

Comments
 (0)