@@ -175,6 +175,7 @@ describe('Workflow Logs API Route', () => {
175175 id : 'workflowLogs.id' ,
176176 workflowId : 'workflowLogs.workflowId' ,
177177 level : 'workflowLogs.level' ,
178+ trigger : 'workflowLogs.trigger' ,
178179 createdAt : 'workflowLogs.createdAt' ,
179180 message : 'workflowLogs.message' ,
180181 executionId : 'workflowLogs.executionId' ,
@@ -470,5 +471,61 @@ describe('Workflow Logs API Route', () => {
470471 expect ( data . data ) . toHaveLength ( 2 )
471472 expect ( data . data . every ( ( log : any ) => log . executionId === 'exec-1' ) ) . toBe ( true )
472473 } )
474+
475+ it ( 'should filter logs by single trigger type' , async ( ) => {
476+ const apiLogs = mockWorkflowLogs . filter ( ( log ) => log . trigger === 'api' )
477+ setupDatabaseMock ( { logs : apiLogs } )
478+
479+ const url = new URL ( 'http://localhost:3000/api/logs?triggers=api' )
480+ const req = new Request ( url . toString ( ) )
481+
482+ const { GET } = await import ( './route' )
483+ const response = await GET ( req as any )
484+ const data = await response . json ( )
485+
486+ expect ( response . status ) . toBe ( 200 )
487+ expect ( data . data ) . toHaveLength ( 1 )
488+ expect ( data . data [ 0 ] . trigger ) . toBe ( 'api' )
489+ } )
490+
491+ it ( 'should filter logs by multiple trigger types' , async ( ) => {
492+ const manualAndApiLogs = mockWorkflowLogs . filter (
493+ ( log ) => log . trigger === 'manual' || log . trigger === 'api'
494+ )
495+ setupDatabaseMock ( { logs : manualAndApiLogs } )
496+
497+ const url = new URL ( 'http://localhost:3000/api/logs?triggers=manual,api' )
498+ const req = new Request ( url . toString ( ) )
499+
500+ const { GET } = await import ( './route' )
501+ const response = await GET ( req as any )
502+ const data = await response . json ( )
503+
504+ expect ( response . status ) . toBe ( 200 )
505+ expect ( data . data ) . toHaveLength ( 3 )
506+ expect ( data . data . every ( ( log : any ) => [ 'manual' , 'api' ] . includes ( log . trigger ) ) ) . toBe ( true )
507+ } )
508+
509+ it ( 'should combine trigger filter with other filters' , async ( ) => {
510+ const filteredLogs = mockWorkflowLogs . filter (
511+ ( log ) => log . trigger === 'manual' && log . level === 'info' && log . workflowId === 'workflow-1'
512+ )
513+ setupDatabaseMock ( { logs : filteredLogs } )
514+
515+ const url = new URL (
516+ 'http://localhost:3000/api/logs?triggers=manual&level=info&workflowIds=workflow-1'
517+ )
518+ const req = new Request ( url . toString ( ) )
519+
520+ const { GET } = await import ( './route' )
521+ const response = await GET ( req as any )
522+ const data = await response . json ( )
523+
524+ expect ( response . status ) . toBe ( 200 )
525+ expect ( data . data ) . toHaveLength ( 1 )
526+ expect ( data . data [ 0 ] . trigger ) . toBe ( 'manual' )
527+ expect ( data . data [ 0 ] . level ) . toBe ( 'info' )
528+ expect ( data . data [ 0 ] . workflowId ) . toBe ( 'workflow-1' )
529+ } )
473530 } )
474531} )
0 commit comments