:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { parseCouponCampaign } from './utils'
describe('parseCouponCampaign', () => {
const testCases: [string, string | null][] = [
// Standard coupon URLs
['/coupons/lenny', 'lenny'],
['/coupons/my-campaign', 'my-campaign'],
['/coupons/campaign_123', 'campaign_123'],
// Onboarding coupon URLs
['/onboarding/coupons/lenny', 'lenny'],
['/onboarding/coupons/my-campaign', 'my-campaign'],
// With project prefix
['/project/67/coupons/lenny', 'lenny'],
['/project/67/onboarding/coupons/lenny', 'lenny'],
// With query params
['/coupons/lenny?next=/home', 'lenny'],
['/onboarding/coupons/lenny?foo=bar', 'lenny'],
// With a hash
['/coupons/lenny#terms', 'lenny'],
// Coupon path only inside the query string or hash
['/home?ref=/coupons/lenny', null],
['/home#/coupons/lenny', null],
// With trailing slash
['/coupons/lenny/', 'lenny'],
// Non-matching paths
['/other/path', null],
['/coupon/lenny', null],
['/coupons/', null],
['/coupons', null],
['', null],
]
testCases.forEach(([path, expected]) => {
it(`parseCouponCampaign("${path}") returns ${expected === null ? 'null' : `"${expected}"`}`, () => {
expect(parseCouponCampaign(path)).toBe(expected)
})
})
})