@@ -98,7 +98,7 @@ describe("WebhookTaskConsumer", () => {
9898
9999 await consumer . processWebhookTask ( payload , "task-123" ) ;
100100
101- expect ( mockLogger . info ) . toHaveBeenCalledWith (
101+ expect ( mockLogger . debug ) . toHaveBeenCalledWith (
102102 "Processing webhook delivery task" ,
103103 expect . objectContaining ( {
104104 operationId : "op-123" ,
@@ -116,7 +116,7 @@ describe("WebhookTaskConsumer", () => {
116116 oAuthClientId : undefined ,
117117 } ) ;
118118
119- expect ( mockLogger . info ) . toHaveBeenCalledWith (
119+ expect ( mockLogger . debug ) . toHaveBeenCalledWith (
120120 "No webhook subscribers found" ,
121121 expect . objectContaining ( {
122122 operationId : "op-123" ,
@@ -171,55 +171,110 @@ describe("WebhookTaskConsumer", () => {
171171 } ) ;
172172
173173 describe ( "processWebhookTask - Event Type Routing" , ( ) => {
174- const testCases = [
175- {
176- trigger : WebhookTriggerEvents . BOOKING_CREATED ,
177- requiredField : "bookingUid" ,
178- } ,
179- {
180- trigger : WebhookTriggerEvents . FORM_SUBMITTED ,
181- requiredField : "formId" ,
182- } ,
183- {
184- trigger : WebhookTriggerEvents . RECORDING_READY ,
185- requiredField : "recordingId" ,
186- } ,
187- {
188- trigger : WebhookTriggerEvents . OOO_CREATED ,
189- requiredField : "oooEntryId" ,
190- } ,
191- ] ;
174+ it ( "should process BOOKING_CREATED event type (scaffold)" , async ( ) => {
175+ const payload : WebhookTaskPayload = {
176+ operationId : "op-test" ,
177+ triggerEvent : WebhookTriggerEvents . BOOKING_CREATED ,
178+ bookingUid : "test-booking-uid" ,
179+ timestamp : new Date ( ) . toISOString ( ) ,
180+ } ;
192181
193- testCases . forEach ( ( { trigger, requiredField } ) => {
194- it ( `should process ${ trigger } event type (scaffold)` , async ( ) => {
195- const payload : WebhookTaskPayload = {
196- operationId : "op-test" ,
197- triggerEvent : trigger ,
198- [ requiredField ] : "test-id" ,
199- timestamp : new Date ( ) . toISOString ( ) ,
200- } ;
201-
202- // Mock subscriber so we reach data fetching
203- vi . mocked ( mockWebhookRepository . getSubscribers ) . mockResolvedValueOnce ( [
204- {
205- id : "sub-1" ,
206- subscriberUrl : "https://example.com/webhook" ,
207- payloadTemplate : null ,
208- appId : null ,
209- secret : null ,
210- time : null ,
211- timeUnit : null ,
212- eventTriggers : [ trigger ] ,
213- version : WebhookVersion . V_2021_10_20 ,
214- } ,
215- ] ) ;
216-
217- // Should not throw - scaffold implementation logs debug messages
218- await expect ( consumer . processWebhookTask ( payload , "task-test" ) ) . resolves . not . toThrow ( ) ;
219-
220- // Verify subscriber fetch was called
221- expect ( mockWebhookRepository . getSubscribers ) . toHaveBeenCalled ( ) ;
222- } ) ;
182+ vi . mocked ( mockWebhookRepository . getSubscribers ) . mockResolvedValueOnce ( [
183+ {
184+ id : "sub-1" ,
185+ subscriberUrl : "https://example.com/webhook" ,
186+ payloadTemplate : null ,
187+ appId : null ,
188+ secret : null ,
189+ time : null ,
190+ timeUnit : null ,
191+ eventTriggers : [ WebhookTriggerEvents . BOOKING_CREATED ] ,
192+ version : WebhookVersion . V_2021_10_20 ,
193+ } ,
194+ ] ) ;
195+
196+ await expect ( consumer . processWebhookTask ( payload , "task-test" ) ) . resolves . not . toThrow ( ) ;
197+ expect ( mockWebhookRepository . getSubscribers ) . toHaveBeenCalled ( ) ;
198+ } ) ;
199+
200+ it ( "should process FORM_SUBMITTED event type (scaffold)" , async ( ) => {
201+ const payload : WebhookTaskPayload = {
202+ operationId : "op-test" ,
203+ triggerEvent : WebhookTriggerEvents . FORM_SUBMITTED ,
204+ formId : "test-form-id" ,
205+ timestamp : new Date ( ) . toISOString ( ) ,
206+ } ;
207+
208+ vi . mocked ( mockWebhookRepository . getSubscribers ) . mockResolvedValueOnce ( [
209+ {
210+ id : "sub-1" ,
211+ subscriberUrl : "https://example.com/webhook" ,
212+ payloadTemplate : null ,
213+ appId : null ,
214+ secret : null ,
215+ time : null ,
216+ timeUnit : null ,
217+ eventTriggers : [ WebhookTriggerEvents . FORM_SUBMITTED ] ,
218+ version : WebhookVersion . V_2021_10_20 ,
219+ } ,
220+ ] ) ;
221+
222+ await expect ( consumer . processWebhookTask ( payload , "task-test" ) ) . resolves . not . toThrow ( ) ;
223+ expect ( mockWebhookRepository . getSubscribers ) . toHaveBeenCalled ( ) ;
224+ } ) ;
225+
226+ it ( "should process RECORDING_READY event type (scaffold)" , async ( ) => {
227+ const payload : WebhookTaskPayload = {
228+ operationId : "op-test" ,
229+ triggerEvent : WebhookTriggerEvents . RECORDING_READY ,
230+ recordingId : "test-recording-id" ,
231+ bookingUid : "test-booking-uid" ,
232+ timestamp : new Date ( ) . toISOString ( ) ,
233+ } ;
234+
235+ vi . mocked ( mockWebhookRepository . getSubscribers ) . mockResolvedValueOnce ( [
236+ {
237+ id : "sub-1" ,
238+ subscriberUrl : "https://example.com/webhook" ,
239+ payloadTemplate : null ,
240+ appId : null ,
241+ secret : null ,
242+ time : null ,
243+ timeUnit : null ,
244+ eventTriggers : [ WebhookTriggerEvents . RECORDING_READY ] ,
245+ version : WebhookVersion . V_2021_10_20 ,
246+ } ,
247+ ] ) ;
248+
249+ await expect ( consumer . processWebhookTask ( payload , "task-test" ) ) . resolves . not . toThrow ( ) ;
250+ expect ( mockWebhookRepository . getSubscribers ) . toHaveBeenCalled ( ) ;
251+ } ) ;
252+
253+ it ( "should process OOO_CREATED event type (scaffold)" , async ( ) => {
254+ const payload : WebhookTaskPayload = {
255+ userId : 456 ,
256+ operationId : "op-test" ,
257+ triggerEvent : WebhookTriggerEvents . OOO_CREATED ,
258+ oooEntryId : 123 ,
259+ timestamp : new Date ( ) . toISOString ( ) ,
260+ } ;
261+
262+ vi . mocked ( mockWebhookRepository . getSubscribers ) . mockResolvedValueOnce ( [
263+ {
264+ id : "sub-1" ,
265+ subscriberUrl : "https://example.com/webhook" ,
266+ payloadTemplate : null ,
267+ appId : null ,
268+ secret : null ,
269+ time : null ,
270+ timeUnit : null ,
271+ eventTriggers : [ WebhookTriggerEvents . OOO_CREATED ] ,
272+ version : WebhookVersion . V_2021_10_20 ,
273+ } ,
274+ ] ) ;
275+
276+ await expect ( consumer . processWebhookTask ( payload , "task-test" ) ) . resolves . not . toThrow ( ) ;
277+ expect ( mockWebhookRepository . getSubscribers ) . toHaveBeenCalled ( ) ;
223278 } ) ;
224279 } ) ;
225280
@@ -251,7 +306,7 @@ describe("WebhookTaskConsumer", () => {
251306 const payload : WebhookTaskPayload = {
252307 operationId : "op-missing" ,
253308 triggerEvent : WebhookTriggerEvents . BOOKING_CREATED ,
254- // Missing bookingUid
309+ bookingUid : "booking-123" ,
255310 timestamp : new Date ( ) . toISOString ( ) ,
256311 } ;
257312
@@ -284,40 +339,4 @@ describe("WebhookTaskConsumer", () => {
284339 ) ;
285340 } ) ;
286341 } ) ;
287-
288- describe ( "Future Implementation Tests" , ( ) => {
289- it ( "TODO [When WebhookTaskConsumer.fetchBookingData() is implemented]: Test full booking data fetching" , ( ) => {
290- // When: BookingRepository is injected into WebhookTaskConsumer
291- // When: fetchBookingData() implementation is complete
292- // Test: Fetch booking, eventType, user, attendees from database
293- // Test: Verify correct data structure returned
294- expect ( true ) . toBe ( true ) ; // Placeholder
295- } ) ;
296-
297- it ( "TODO [When PayloadBuilders are integrated into sendWebhooksToSubscribers()]: Test payload building" , ( ) => {
298- // When: BookingPayloadBuilder is integrated (for booking events)
299- // When: FormPayloadBuilder is integrated (for form events)
300- // When: RecordingPayloadBuilder is integrated (for recording events)
301- // When: OOOPayloadBuilder is integrated (for OOO events)
302- // Test: Build versioned payloads, apply payload templates
303- expect ( true ) . toBe ( true ) ; // Placeholder
304- } ) ;
305-
306- it ( "TODO [When sendWebhooksToSubscribers() makes HTTP calls]: Test HTTP delivery" , ( ) => {
307- // When: HTTP client is integrated (or existing sendPayload is used)
308- // When: sendWebhooksToSubscribers() sends to subscriber.subscriberUrl
309- // Test: Mock HTTP calls, verify correct payload sent
310- // Test: Handle retries, timeouts, errors
311- expect ( true ) . toBe ( true ) ; // Placeholder
312- } ) ;
313-
314- it ( "TODO [When all services are wired]: Integration test for full Producer→Consumer flow" , ( ) => {
315- // When: All webhook services use Producer/Consumer pattern
316- // Test: Full flow - Producer → Tasker → Consumer → HTTP delivery
317- // Test: Verify webhook received by mock HTTP server
318- // Test: Retry logic with task processor
319- // Test: E2E with real database and task queue
320- expect ( true ) . toBe ( true ) ; // Placeholder
321- } ) ;
322- } ) ;
323342} ) ;
0 commit comments