@@ -42,6 +42,7 @@ vi.mock('@sim/db', () => ({
4242vi . mock ( 'drizzle-orm' , ( ) => ( {
4343 eq : vi . fn ( ( ...args ) => ( { type : 'eq' , args } ) ) ,
4444 and : vi . fn ( ( ...args ) => ( { type : 'and' , args } ) ) ,
45+ inArray : vi . fn ( ( ...args ) => ( { type : 'inArray' , args } ) ) ,
4546 sql : vi . fn ( ( strings , ...values ) => ( { type : 'sql' , strings, values } ) ) ,
4647} ) )
4748
@@ -684,15 +685,24 @@ describe('Schedule Deploy Utilities', () => {
684685 } )
685686
686687 describe ( 'createSchedulesForDeploy' , ( ) => {
688+ const createMockTx = ( existingSchedules : Array < { id : string ; blockId : string } > = [ ] ) => {
689+ const mockFrom = vi . fn ( ) . mockReturnValue ( {
690+ where : vi . fn ( ) . mockResolvedValue ( existingSchedules ) ,
691+ } )
692+ const mockSelect = vi . fn ( ) . mockReturnValue ( { from : mockFrom } )
693+ return {
694+ insert : mockInsert ,
695+ delete : mockDelete ,
696+ select : mockSelect ,
697+ }
698+ }
699+
687700 it ( 'should return success with no schedule blocks' , async ( ) => {
688701 const blocks : Record < string , BlockState > = {
689702 'block-1' : { id : 'block-1' , type : 'agent' , subBlocks : { } } as BlockState ,
690703 }
691704
692- const mockTx = {
693- insert : mockInsert ,
694- delete : mockDelete ,
695- }
705+ const mockTx = createMockTx ( )
696706
697707 const result = await createSchedulesForDeploy ( 'workflow-1' , blocks , mockTx as any )
698708
@@ -713,10 +723,7 @@ describe('Schedule Deploy Utilities', () => {
713723 } as BlockState ,
714724 }
715725
716- const mockTx = {
717- insert : mockInsert ,
718- delete : mockDelete ,
719- }
726+ const mockTx = createMockTx ( )
720727
721728 const result = await createSchedulesForDeploy ( 'workflow-1' , blocks , mockTx as any )
722729
@@ -740,10 +747,7 @@ describe('Schedule Deploy Utilities', () => {
740747 } as BlockState ,
741748 }
742749
743- const mockTx = {
744- insert : mockInsert ,
745- delete : mockDelete ,
746- }
750+ const mockTx = createMockTx ( )
747751
748752 const result = await createSchedulesForDeploy ( 'workflow-1' , blocks , mockTx as any )
749753
@@ -765,10 +769,7 @@ describe('Schedule Deploy Utilities', () => {
765769 } as BlockState ,
766770 }
767771
768- const mockTx = {
769- insert : mockInsert ,
770- delete : mockDelete ,
771- }
772+ const mockTx = createMockTx ( )
772773
773774 await createSchedulesForDeploy ( 'workflow-1' , blocks , mockTx as any )
774775
0 commit comments