@@ -101,6 +101,7 @@ const {
101101 processWebhookMock,
102102 executeMock,
103103 getWorkspaceBilledAccountUserIdMock,
104+ queueWebhookExecutionMock,
104105} = vi . hoisted ( ( ) => ( {
105106 generateRequestHashMock : vi . fn ( ) . mockResolvedValue ( 'test-hash-123' ) ,
106107 validateSlackSignatureMock : vi . fn ( ) . mockResolvedValue ( true ) ,
@@ -125,6 +126,10 @@ const {
125126 . mockImplementation ( async ( workspaceId : string | null | undefined ) =>
126127 workspaceId ? 'test-user-id' : null
127128 ) ,
129+ queueWebhookExecutionMock : vi . fn ( ) . mockImplementation ( async ( ) => {
130+ const { NextResponse } = await import ( 'next/server' )
131+ return NextResponse . json ( { message : 'Webhook processed' } )
132+ } ) ,
128133} ) )
129134
130135vi . mock ( '@trigger.dev/sdk' , ( ) => ( {
@@ -333,12 +338,7 @@ vi.mock('@/lib/webhooks/processor', () => ({
333338 } ) ,
334339 shouldSkipWebhookEvent : vi . fn ( ) . mockReturnValue ( false ) ,
335340 handlePreDeploymentVerification : vi . fn ( ) . mockReturnValue ( null ) ,
336- queueWebhookExecution : vi . fn ( ) . mockImplementation ( async ( ) => {
337- // Call processWebhookMock so tests can verify it was called
338- processWebhookMock ( )
339- const { NextResponse } = await import ( 'next/server' )
340- return NextResponse . json ( { message : 'Webhook processed' } )
341- } ) ,
341+ queueWebhookExecution : queueWebhookExecutionMock ,
342342} ) )
343343
344344vi . mock ( 'drizzle-orm/postgres-js' , ( ) => ( {
@@ -353,7 +353,7 @@ vi.mock('@/lib/core/utils/request', () => requestUtilsMock)
353353
354354process . env . DATABASE_URL = 'postgresql://test:test@localhost:5432/test'
355355
356- import { POST } from '@/app/api/webhooks/trigger/[path] /route'
356+ import { POST } from '. /route'
357357
358358describe ( 'Webhook Trigger API Route' , ( ) => {
359359 beforeEach ( ( ) => {
@@ -393,7 +393,7 @@ describe('Webhook Trigger API Route', () => {
393393
394394 const params = Promise . resolve ( { path : 'non-existent-path' } )
395395
396- const response = await POST ( req , { params } )
396+ const response = await POST ( req as any , { params } )
397397
398398 expect ( response . status ) . toBe ( 404 )
399399
@@ -402,6 +402,32 @@ describe('Webhook Trigger API Route', () => {
402402 } )
403403
404404 describe ( 'Generic Webhook Authentication' , ( ) => {
405+ it ( 'passes correlation-bearing request context into webhook queueing' , async ( ) => {
406+ testData . webhooks . push ( {
407+ id : 'generic-webhook-id' ,
408+ provider : 'generic' ,
409+ path : 'test-path' ,
410+ isActive : true ,
411+ providerConfig : { requireAuth : false } ,
412+ workflowId : 'test-workflow-id' ,
413+ } )
414+
415+ const req = createMockRequest ( 'POST' , { event : 'test' , id : 'test-123' } )
416+ const params = Promise . resolve ( { path : 'test-path' } )
417+
418+ const response = await POST ( req as any , { params } )
419+
420+ expect ( response . status ) . toBe ( 200 )
421+ expect ( queueWebhookExecutionMock ) . toHaveBeenCalledOnce ( )
422+ const call = queueWebhookExecutionMock . mock . calls [ 0 ]
423+ expect ( call [ 0 ] ) . toEqual ( expect . objectContaining ( { id : 'generic-webhook-id' } ) )
424+ expect ( call [ 1 ] ) . toEqual ( expect . objectContaining ( { id : 'test-workflow-id' } ) )
425+ expect ( call [ 2 ] ) . toEqual ( expect . objectContaining ( { event : 'test' , id : 'test-123' } ) )
426+ expect ( call [ 4 ] ) . toEqual (
427+ expect . objectContaining ( { requestId : 'mock-request-id' , path : 'test-path' } )
428+ )
429+ } )
430+
405431 it ( 'should process generic webhook without authentication' , async ( ) => {
406432 testData . webhooks . push ( {
407433 id : 'generic-webhook-id' ,
@@ -422,7 +448,7 @@ describe('Webhook Trigger API Route', () => {
422448 const req = createMockRequest ( 'POST' , { event : 'test' , id : 'test-123' } )
423449 const params = Promise . resolve ( { path : 'test-path' } )
424450
425- const response = await POST ( req , { params } )
451+ const response = await POST ( req as any , { params } )
426452
427453 expect ( response . status ) . toBe ( 200 )
428454
@@ -452,7 +478,7 @@ describe('Webhook Trigger API Route', () => {
452478 const req = createMockRequest ( 'POST' , { event : 'bearer.test' } , headers )
453479 const params = Promise . resolve ( { path : 'test-path' } )
454480
455- const response = await POST ( req , { params } )
481+ const response = await POST ( req as any , { params } )
456482
457483 expect ( response . status ) . toBe ( 200 )
458484 } )
@@ -483,7 +509,7 @@ describe('Webhook Trigger API Route', () => {
483509 const req = createMockRequest ( 'POST' , { event : 'custom.header.test' } , headers )
484510 const params = Promise . resolve ( { path : 'test-path' } )
485511
486- const response = await POST ( req , { params } )
512+ const response = await POST ( req as any , { params } )
487513
488514 expect ( response . status ) . toBe ( 200 )
489515 } )
@@ -518,7 +544,7 @@ describe('Webhook Trigger API Route', () => {
518544 const req = createMockRequest ( 'POST' , { event : 'case.test' } , headers )
519545 const params = Promise . resolve ( { path : 'test-path' } )
520546
521- const response = await POST ( req , { params } )
547+ const response = await POST ( req as any , { params } )
522548
523549 expect ( response . status ) . toBe ( 200 )
524550 }
@@ -553,7 +579,7 @@ describe('Webhook Trigger API Route', () => {
553579 const req = createMockRequest ( 'POST' , { event : 'custom.case.test' } , headers )
554580 const params = Promise . resolve ( { path : 'test-path' } )
555581
556- const response = await POST ( req , { params } )
582+ const response = await POST ( req as any , { params } )
557583
558584 expect ( response . status ) . toBe ( 200 )
559585 }
@@ -576,7 +602,7 @@ describe('Webhook Trigger API Route', () => {
576602 const req = createMockRequest ( 'POST' , { event : 'wrong.token.test' } , headers )
577603 const params = Promise . resolve ( { path : 'test-path' } )
578604
579- const response = await POST ( req , { params } )
605+ const response = await POST ( req as any , { params } )
580606
581607 expect ( response . status ) . toBe ( 401 )
582608 expect ( await response . text ( ) ) . toContain ( 'Unauthorized - Invalid authentication token' )
@@ -604,7 +630,7 @@ describe('Webhook Trigger API Route', () => {
604630 const req = createMockRequest ( 'POST' , { event : 'wrong.custom.test' } , headers )
605631 const params = Promise . resolve ( { path : 'test-path' } )
606632
607- const response = await POST ( req , { params } )
633+ const response = await POST ( req as any , { params } )
608634
609635 expect ( response . status ) . toBe ( 401 )
610636 expect ( await response . text ( ) ) . toContain ( 'Unauthorized - Invalid authentication token' )
@@ -624,7 +650,7 @@ describe('Webhook Trigger API Route', () => {
624650 const req = createMockRequest ( 'POST' , { event : 'no.auth.test' } )
625651 const params = Promise . resolve ( { path : 'test-path' } )
626652
627- const response = await POST ( req , { params } )
653+ const response = await POST ( req as any , { params } )
628654
629655 expect ( response . status ) . toBe ( 401 )
630656 expect ( await response . text ( ) ) . toContain ( 'Unauthorized - Invalid authentication token' )
@@ -652,7 +678,7 @@ describe('Webhook Trigger API Route', () => {
652678 const req = createMockRequest ( 'POST' , { event : 'exclusivity.test' } , headers )
653679 const params = Promise . resolve ( { path : 'test-path' } )
654680
655- const response = await POST ( req , { params } )
681+ const response = await POST ( req as any , { params } )
656682
657683 expect ( response . status ) . toBe ( 401 )
658684 expect ( await response . text ( ) ) . toContain ( 'Unauthorized - Invalid authentication token' )
@@ -680,7 +706,7 @@ describe('Webhook Trigger API Route', () => {
680706 const req = createMockRequest ( 'POST' , { event : 'wrong.header.name.test' } , headers )
681707 const params = Promise . resolve ( { path : 'test-path' } )
682708
683- const response = await POST ( req , { params } )
709+ const response = await POST ( req as any , { params } )
684710
685711 expect ( response . status ) . toBe ( 401 )
686712 expect ( await response . text ( ) ) . toContain ( 'Unauthorized - Invalid authentication token' )
@@ -705,7 +731,7 @@ describe('Webhook Trigger API Route', () => {
705731 const req = createMockRequest ( 'POST' , { event : 'no.token.config.test' } , headers )
706732 const params = Promise . resolve ( { path : 'test-path' } )
707733
708- const response = await POST ( req , { params } )
734+ const response = await POST ( req as any , { params } )
709735
710736 expect ( response . status ) . toBe ( 401 )
711737 expect ( await response . text ( ) ) . toContain (
0 commit comments