Skip to main content
InterviewHubPRO
Section Overview
Q49

Question 49 of 50

Part 3: Advanced Internals, Scale & Production Quality (Senior / Lead)

98%
Software Testing & QA (50 Qs)•Part 3: Advanced Internals, Scale & Production Quality (Senior / Lead)

Webhook and Asynchronous Callback Testing: Simulating inbound payloads and signature verification.

senior LevelCode ExampleTestingAsync & Promises

In Simple Words: Testing that your API correctly handles webhook callbacks (e.g. Stripe payment_intent.succeeded, GitHub webhooks):

  • Use helper utilities to generate the cryptographic HMAC signature header (stripe-signature):
    typescript
    const payload = JSON.stringify({ type: 'payment_intent.succeeded', id: 'pi_123' });
    const signature = generateHmacSignature(payload, WEBHOOK_SECRET);
    
    const res = await request(app)
      .post('/api/webhooks/stripe')
      .set('stripe-signature', signature)
      .send(payload);
    
    expect(res.status).toBe(200);
    
  • Test error branches: rejected signatures, replayed duplicate webhook events, and malformed JSON payloads.