The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
update tests
Steven Teyace8a2519244
diff --git a/apps/web/tests/tracks/track-lead.test.ts b/apps/web/tests/tracks/track-lead.test.tsindex 5448c1cf13..45ed00006f 100644--- a/apps/web/tests/tracks/track-lead.test.ts+++ b/apps/web/tests/tracks/track-lead.test.ts@@ -106,4 +106,21 @@ describe("POST /track/lead", async () => {expect(saleResponse.status).toEqual(200);});++ test("track a lead with `customerId` (backward compatibility)", async () => {+ const customer4 = randomCustomer();+ const response = await http.post<TrackLeadResponse>({+ path: "/track/lead",+ body: {+ clickId: E2E_CLICK_ID,+ customerId: customer4.externalId,+ eventName: "Signup",+ customerName: customer4.name,+ customerEmail: customer4.email,+ customerAvatar: customer4.avatar,+ },+ });++ expectValidLeadResponse(response, customer4);+ });});diff --git a/apps/web/tests/tracks/track-sale.test.ts b/apps/web/tests/tracks/track-sale.test.tsindex d9734ae5c8..9b3e5cae99 100644--- a/apps/web/tests/tracks/track-sale.test.ts+++ b/apps/web/tests/tracks/track-sale.test.ts@@ -8,35 +8,19 @@ import {import { expect, test } from "vitest";import { IntegrationHarness } from "../utils/integration";-test("POST /track/sale", async () => {- const h = new IntegrationHarness();- const { http } = await h.init();-- const sale = {- eventName: "Subscription",- amount: randomValue([400, 900, 1900]),- currency: "usd",- invoiceId: `INV_${randomId()}`,- paymentProcessor: "stripe",- };-- const response = await http.post<TrackSaleResponse>({- path: "/track/sale",- body: {- ...sale,- externalId: E2E_CUSTOMER_EXTERNAL_ID,- },- });-+const expectValidSaleResponse = (+ response: { status: number; data: TrackSaleResponse },+ sale: any,+) => {expect(response.status).toEqual(200);expect(response.data).toStrictEqual({- eventName: "Subscription",+ eventName: sale.eventName,customer: {id: E2E_CUSTOMER_ID,- name: expect.any(String),- email: expect.any(String),- avatar: expect.any(String),- externalId: E2E_CUSTOMER_EXTERNAL_ID,+ name: sale.customerName,+ email: sale.customerEmail,+ avatar: sale.customerAvatar,+ externalId: sale.externalId,},sale: {amount: sale.amount,@@ -51,38 +35,77 @@ test("POST /track/sale", async () => {metadata: null,invoiceId: sale.invoiceId,});+};- // An invoiceId that is already processed should return null customer and sale- const response2 = await http.post<TrackSaleResponse>({- path: "/track/sale",- body: {- ...sale,- externalId: E2E_CUSTOMER_EXTERNAL_ID,- invoiceId: sale.invoiceId,- },- });+describe("POST /track/sale", async () => {+ const h = new IntegrationHarness();+ const { http } = await h.init();- expect(response2.status).toEqual(200);- expect(response2.data).toStrictEqual({+ const sale = {eventName: "Subscription",- customer: null,- sale: null,+ amount: randomValue([400, 900, 1900]),+ currency: "usd",+ invoiceId: `INV_${randomId()}`,+ paymentProcessor: "stripe",+ };++ test("track a sale", async () => {+ const response = await http.post<TrackSaleResponse>({+ path: "/track/sale",+ body: {+ ...sale,+ externalId: E2E_CUSTOMER_EXTERNAL_ID,+ },+ });++ expectValidSaleResponse(response, sale);});- // An externalId that does not exist should return null customer and sale- const response3 = await http.post<TrackSaleResponse>({- path: "/track/sale",- body: {- ...sale,- invoiceId: `INV_${randomId()}`,- externalId: "external-id-that-does-not-exist",- },+ test("track a sale with an invoiceId that is already processed (should return null customer and sale) ", async () => {+ const response2 = await http.post<TrackSaleResponse>({+ path: "/track/sale",+ body: {+ ...sale,+ externalId: E2E_CUSTOMER_EXTERNAL_ID,+ invoiceId: sale.invoiceId,+ },+ });++ expect(response2.status).toEqual(200);+ expect(response2.data).toStrictEqual({+ eventName: "Subscription",+ customer: null,+ sale: null,+ });});- expect(response3.status).toEqual(200);- expect(response3.data).toStrictEqual({- eventName: "Subscription",- customer: null,- sale: null,+ test("track a sale with an externalId that does not exist (should return null customer and sale)", async () => {+ const response3 = await http.post<TrackSaleResponse>({+ path: "/track/sale",+ body: {+ ...sale,+ invoiceId: `INV_${randomId()}`,+ externalId: "external-id-that-does-not-exist",+ },+ });++ expect(response3.status).toEqual(200);+ expect(response3.data).toStrictEqual({+ eventName: "Subscription",+ customer: null,+ sale: null,+ });+ });++ test("track a sale with `customerId` (backward compatibility)", async () => {+ const response4 = await http.post<TrackSaleResponse>({+ path: "/track/sale",+ body: {+ ...sale,+ customerId: E2E_CUSTOMER_ID,+ },+ });++ expectValidSaleResponse(response4, sale);});});