Next.js billing webhook test suite
Next.js App Router webhook handlers need tests that protect raw-body signing and subscription state changes.
Open the free generatorRead request.text once
A Next.js handler should read the raw request body, verify the provider signature, then parse JSON only after verification succeeds.
Replay duplicate events
Run the same signed payload twice and assert that account access, emails, and billing records are created once.
Cover unsupported events
Return a clean 200 or 204 for known-but-unhandled events only after signature verification, and alert on events your billing model expects.
FAQ
Can Next.js App Router verify Lemon Squeezy webhooks?
Yes. Use request.text() to preserve the raw body, compute HMAC SHA-256, and compare it before parsing.
Should webhook tests mock the provider API?
Handler tests usually should not call provider APIs. Use local fixtures for route behavior and separate live checkout checks for provider configuration.
Use the free sample before wiring production checkout
Download a public sample pack with fake Lemon Squeezy fixtures, signature tests, contract checks, duplicate replay tests, and CI skeletons. The Pro Kit preview shows the full paid package structure without exposing the private archive.