Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Add campaigns Playwright API tests and shared apiError helper

Kiran K599f3ae7bf62
diff --git a/.agents/skills/playwright-api-tests/SKILL.md b/.agents/skills/playwright-api-tests/SKILL.md
index 63f6005cc5..d21668ff3c 100644
--- a/.agents/skills/playwright-api-tests/SKILL.md
+++ b/.agents/skills/playwright-api-tests/SKILL.md
@@ -54,10 +54,6 @@ import { expect } from "@playwright/test";
import { randomName } from "../../utils";
import { test, type ApiClient } from "../fixtures";
-test.describe.configure({
- mode: "parallel",
-});
-
async function createThing(
api: ApiClient,
overrides: Record<string, unknown> = {},
@@ -98,7 +94,7 @@ test("POST /things", async ({ api }) => {
| Rule | Detail |
| ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| Import `test` from `../fixtures` | Provides `api`, `workspace`, and `program` |
-| `test.describe.configure({ mode: "parallel" })` | At top of every API spec file |
+| Serial only when tests share state | API project is `fullyParallel: true`. Do not add `mode: "parallel"`. Use `test.describe.configure({ mode: "serial" })` only when tests in a file/describe share state (e.g. domains, seeded pagination) |
| Cleanup in `finally` | Create → assert → always delete created rows |
| Unique names/ids | Use `randomName` / `randomCustomer` / `randomPartnerEmail` from `../../utils` — never fixed colliding names |
| Assert status + body | Prefer `toStrictEqual` / `toEqual` on full shapes; use `expect.any(String)` for ids/timestamps |
diff --git a/apps/web/playwright/api/bounties/bounties.spec.ts b/apps/web/playwright/api/bounties/bounties.spec.ts
index 86c9384be5..806a847641 100644
--- a/apps/web/playwright/api/bounties/bounties.spec.ts
+++ b/apps/web/playwright/api/bounties/bounties.spec.ts
@@ -2,13 +2,9 @@ import type { BountyProps } from "@/lib/types";
import { expect } from "@playwright/test";
import { BountyStartMode, type Program } from "@prisma/client";
import { addDays, addMonths, subDays } from "date-fns";
-import { randomName } from "../../utils";
+import { apiError, randomName } from "../../utils";
import { test, type ApiClient } from "../fixtures";
-test.describe.configure({
- mode: "parallel",
-});
-
type BountyJson = Omit<
BountyProps,
"startsAt" | "endsAt" | "submissionsOpenAt" | "socialMetricsLastSyncedAt"
@@ -74,39 +70,6 @@ const expectedBountyDefaults = {
socialMetricsLastSyncedAt: null,
};
-const unprocessable = (message: string) => ({
- status: 422,
- data: {
- error: {
- code: "unprocessable_entity",
- message,
- doc_url: "https://dub.co/docs/api-reference/errors#unprocessable-entity",
- },
- },
-});
-
-const badRequest = (message: string) => ({
- status: 400,
- data: {
- error: {
- code: "bad_request",
- message,
- doc_url: "https://dub.co/docs/api-reference/errors#bad-request",
- },
- },
-});
-
-const notFound = (bountyId: string) => ({
- status: 404,
- data: {
- error: {
- code: "not_found",
- message: `Bounty ${bountyId} not found.`,
- doc_url: "https://dub.co/docs/api-reference/errors#not-found",
- },
- },
-});
-
test("POST /bounties", async ({ api, program }) => {
let id: string | undefined;
const body = bountyPayload(program);
@@ -339,7 +302,10 @@ test("DELETE /bounties/{bountyId}", async ({ api, program }) => {
expect(status).toEqual(200);
expect(data).toStrictEqual({ id: created.id });
expect(await api.get(`/api/bounties/${created.id}`)).toEqual(
- notFound(created.id),
+ apiError({
+ code: "not_found",
+ message: `Bounty ${created.id} not found.`,
+ }),
);
});
@@ -682,9 +648,11 @@ test("PATCH /bounties/{bountyId} – submissionFrequency requires endsAt on the
maxSubmissions: 4,
}),
).toEqual(
- badRequest(
- "`endsAt` or `endsAfterDays` is required when `submissionFrequency` is set.",
- ),
+ apiError({
+ code: "bad_request",
+ message:
+ "`endsAt` or `endsAfterDays` is required when `submissionFrequency` is set.",
+ }),
);
} finally {
await deleteBounty(api, id);
@@ -706,7 +674,10 @@ test("PATCH /bounties/{bountyId} – submissionsOpenAt without endsAt is rejecte
submissionsOpenAt: addDays(new Date(), 5).toISOString(),
}),
).toEqual(
- badRequest("`endsAt` is required when `submissionsOpenAt` is set."),
+ apiError({
+ code: "bad_request",
+ message: "`endsAt` is required when `submissionsOpenAt` is set.",
+ }),
);
} finally {
await deleteBounty(api, id);
@@ -726,9 +697,11 @@ test("PATCH /bounties/{bountyId} – maxSubmissions below minimum is rejected",
expect(
await api.patch(`/api/bounties/${id}`, { maxSubmissions: 1 }),
).toEqual(
- unprocessable(
- "too_small: maxSubmissions: If `maxSubmissions` is set, it must be at least 2",
- ),
+ apiError({
+ code: "unprocessable_entity",
+ message:
+ "too_small: maxSubmissions: If `maxSubmissions` is set, it must be at least 2",
+ }),
);
} finally {
await deleteBounty(api, id);
@@ -748,9 +721,10 @@ test("PATCH /bounties/{bountyId} – maxSubmissions above maximum is rejected",
expect(
await api.patch(`/api/bounties/${id}`, { maxSubmissions: 51 }),
).toEqual(
- unprocessable(
- "too_big: maxSubmissions: Too big: expected number to be <=50",
- ),
+ apiError({
+ code: "unprocessable_entity",
+ message: "too_big: maxSubmissions: Too big: expected number to be <=50",
+ }),
);
} finally {
await deleteBounty(api, id);
@@ -762,7 +736,12 @@ test("POST /bounties – invalid group IDs", async ({ api, program }) => {
await api.post("/api/bounties", {
...bountyPayload(program, { groupIds: ["invalid-group-id"] }),
}),
- ).toEqual(badRequest("Invalid group IDs detected: invalid-group-id"));
+ ).toEqual(
+ apiError({
+ code: "bad_request",
+ message: "Invalid group IDs detected: invalid-group-id",
+ }),
+ );
});
test("POST /bounties – maxSubmissions below minimum is rejected", async ({
@@ -774,9 +753,11 @@ test("POST /bounties – maxSubmissions below minimum is rejected", async ({
...bountyPayload(program, { maxSubmissions: 1 }),
}),
).toEqual(
- unprocessable(
- "too_small: maxSubmissions: If `maxSubmissions` is set, it must be at least 2",
- ),
+ apiError({
+ code: "unprocessable_entity",
+ message:
+ "too_small: maxSubmissions: If `maxSubmissions` is set, it must be at least 2",
+ }),
);
});
@@ -789,9 +770,10 @@ test("POST /bounties – maxSubmissions above maximum is rejected", async ({
...bountyPayload(program, { maxSubmissions: 51 }),
}),
).toEqual(
- unprocessable(
- "too_big: maxSubmissions: Too big: expected number to be <=50",
- ),
+ apiError({
+ code: "unprocessable_entity",
+ message: "too_big: maxSubmissions: Too big: expected number to be <=50",
+ }),
);
});
@@ -811,9 +793,10 @@ test("POST /bounties – submissionFrequency without maxSubmissions is rejected"
}),
}),
).toEqual(
- badRequest(
- "`maxSubmissions` is required when `submissionFrequency` is set.",
- ),
+ apiError({
+ code: "bad_request",
+ message: "`maxSubmissions` is required when `submissionFrequency` is set.",
+ }),
);
});
@@ -830,9 +813,11 @@ test("POST /bounties – submissionFrequency without endsAt is rejected", async
}),
}),
).toEqual(
- badRequest(
- "`endsAt` or `endsAfterDays` is required when `submissionFrequency` is set.",
- ),
+ apiError({
+ code: "bad_request",
+ message:
+ "`endsAt` or `endsAfterDays` is required when `submissionFrequency` is set.",
+ }),
);
});
@@ -851,7 +836,10 @@ test("POST /bounties – submissionsOpenAt without endsAt is rejected", async ({
}),
}),
).toEqual(
- badRequest("`endsAt` is required when `submissionsOpenAt` is set."),
+ apiError({
+ code: "bad_request",
+ message: "`endsAt` is required when `submissionsOpenAt` is set.",
+ }),
);
});
@@ -870,7 +858,12 @@ test("POST /bounties – submissionsOpenAt before startsAt is rejected", async (
submissionsOpenAt: subDays(new Date(startsAt), 1).toISOString(),
}),
}),
- ).toEqual(badRequest("`submissionsOpenAt` must be on or after `startsAt`."));
+ ).toEqual(
+ apiError({
+ code: "bad_request",
+ message: "`submissionsOpenAt` must be on or after `startsAt`.",
+ }),
+ );
});
test("POST /bounties – submissionsOpenAt after endsAt is rejected", async ({
@@ -888,7 +881,12 @@ test("POST /bounties – submissionsOpenAt after endsAt is rejected", async ({
submissionsOpenAt: addDays(new Date(endsAt), 1).toISOString(),
}),
}),
- ).toEqual(badRequest("`submissionsOpenAt` must be on or before `endsAt`."));
+ ).toEqual(
+ apiError({
+ code: "bad_request",
+ message: "`submissionsOpenAt` must be on or before `endsAt`.",
+ }),
+ );
});
test("POST /bounties – relative with startsAt is rejected", async ({
@@ -904,9 +902,10 @@ test("POST /bounties – relative with startsAt is rejected", async ({
}),
}),
).toEqual(
- badRequest(
- "`startsAt` is not supported when the `startMode` is `relative`.",
- ),
+ apiError({
+ code: "bad_request",
+ message: "`startsAt` is not supported when the `startMode` is `relative`.",
+ }),
);
});
@@ -924,7 +923,10 @@ test("POST /bounties – both endsAt and endsAfterDays is rejected", async ({
}),
}),
).toEqual(
- badRequest("Bounties cannot have both `endsAt` and `endsAfterDays`."),
+ apiError({
+ code: "bad_request",
+ message: "Bounties cannot have both `endsAt` and `endsAfterDays`.",
+ }),
);
});
@@ -932,18 +934,29 @@ const unknownBountyId = "bnty_does_not_exist";
test("GET /bounties/{bountyId} – not found", async ({ api }) => {
expect(await api.get(`/api/bounties/${unknownBountyId}`)).toEqual(
- notFound(unknownBountyId),
+ apiError({
+ code: "not_found",
+ message: `Bounty ${unknownBountyId} not found.`,
+ }),
);
});
test("PATCH /bounties/{bountyId} – not found", async ({ api }) => {
expect(
await api.patch(`/api/bounties/${unknownBountyId}`, { name: "x" }),
- ).toEqual(notFound(unknownBountyId));
+ ).toEqual(
+ apiError({
+ code: "not_found",
+ message: `Bounty ${unknownBountyId} not found.`,
+ }),
+ );
});
test("DELETE /bounties/{bountyId} – not found", async ({ api }) => {
expect(await api.delete(`/api/bounties/${unknownBountyId}`)).toEqual(
- notFound(unknownBountyId),
+ apiError({
+ code: "not_found",
+ message: `Bounty ${unknownBountyId} not found.`,
+ }),
);
});
diff --git a/apps/web/playwright/api/campaigns/campaigns.spec.ts b/apps/web/playwright/api/campaigns/campaigns.spec.ts
new file mode 100644
index 0000000000..d7214c796e
--- /dev/null
+++ b/apps/web/playwright/api/campaigns/campaigns.spec.ts
@@ -0,0 +1,463 @@
+import { DEFAULT_CAMPAIGN_BODY } from "@/lib/api/campaigns/constants";
+import { expect } from "@playwright/test";
+import type { CampaignType } from "@prisma/client";
+import { apiError, randomName } from "../../utils";
+import { test, type ApiClient } from "../fixtures";
+import {
+ campaignContent,
+ createCampaign,
+ defaultTransactionalTrigger,
+ deleteCampaign,
+ type CampaignJson,
+} from "./helpers";
+
+function defaultCampaign(type: CampaignType) {
+ return {
+ id: expect.any(String),
+ name: "Untitled",
+ subject: "",
+ preview: null,
+ from: null,
+ bodyJson: DEFAULT_CAMPAIGN_BODY,
+ type,
+ status: "draft",
+ triggerCondition:
+ type === "transactional" ? defaultTransactionalTrigger : null,
+ groups: [],
+ scheduledAt: null,
+ createdAt: expect.any(String),
+ updatedAt: expect.any(String),
+ };
+}
+
+async function createDraft(
+ api: ApiClient,
+ type: CampaignType = "transactional",
+) {
+ const { status, data } = await createCampaign(api, type);
+ expect(status).toEqual(201);
+ return data.id;
+}
+
+test("POST /campaigns – transactional", async ({ api }) => {
+ let id: string | undefined;
+
+ try {
+ const { status, data } = await api.post<{ id: string }>("/api/campaigns", {
+ type: "transactional",
+ });
+ id = data.id;
+
+ expect(status).toEqual(201);
+ expect(data).toStrictEqual({
+ id: expect.any(String),
+ });
+
+ const { status: getStatus, data: campaign } = await api.get<CampaignJson>(
+ `/api/campaigns/${id}`,
+ );
+
+ expect(getStatus).toEqual(200);
+ expect(campaign).toStrictEqual(defaultCampaign("transactional"));
+ } finally {
+ await deleteCampaign(api, id);
+ }
+});
+
+test("POST /campaigns – marketing", async ({ api }) => {
+ let id: string | undefined;
+
+ try {
+ const { status, data } = await createCampaign(api, "marketing");
+ id = data.id;
+
+ expect(status).toEqual(201);
+ expect(data).toStrictEqual({
+ id: expect.any(String),
+ });
+
+ const { data: campaign } = await api.get<CampaignJson>(
+ `/api/campaigns/${id}`,
+ );
+
+ expect(campaign).toStrictEqual(defaultCampaign("marketing"));
+ } finally {
+ await deleteCampaign(api, id);
+ }
+});
+
+test("PATCH /campaigns/:id – update transactional content", async ({
+ api,
+ program,
+}) => {
+ let id: string | undefined;
+
+ try {
+ id = await createDraft(api);
+ const triggerCondition = {
+ attribute: "totalConversions",
+ operator: "gte",
+ value: 50,
+ } as const;
+ const body = campaignContent({
+ triggerCondition,
+ groupIds: [program.defaultGroupId],
+ });
+
+ const { status, data } = await api.patch<CampaignJson>(
+ `/api/campaigns/${id}`,
+ body,
+ );
+
+ expect(status).toEqual(200);
+ expect(data).toStrictEqual({
+ ...defaultCampaign("transactional"),
+ id,
+ name: body.name,
+ subject: body.subject,
+ bodyJson: body.bodyJson,
+ triggerCondition,
+ groups: [{ id: program.defaultGroupId }],
+ });
+ } finally {
+ await deleteCampaign(api, id);
+ }
+});
+
+test("PATCH /campaigns/:id – update marketing content", async ({
+ api,
+ program,
+}) => {
+ let id: string | undefined;
+ const scheduledAt = "2026-12-01T00:00:00.000Z";
+
+ try {
+ id = await createDraft(api, "marketing");
+ const body = campaignContent({
+ groupIds: [program.defaultGroupId],
+ scheduledAt,
+ triggerCondition: {
+ attribute: "totalConversions",
+ operator: "gte",
+ value: 50,
+ },
+ });
+
+ const { status, data } = await api.patch<CampaignJson>(
+ `/api/campaigns/${id}`,
+ body,
+ );
+
+ expect(status).toEqual(200);
+ expect(data).toMatchObject({
+ id,
+ type: "marketing",
+ name: body.name,
+ subject: body.subject,
+ bodyJson: body.bodyJson,
+ triggerCondition: null,
+ groups: [{ id: program.defaultGroupId }],
+ });
+ expect(data.scheduledAt).toEqual(scheduledAt);
+ } finally {
+ await deleteCampaign(api, id);
+ }
+});
+
+test("PATCH /campaigns/:id – transactional ignores scheduledAt", async ({
+ api,
+}) => {
+ let id: string | undefined;
+
+ try {
+ id = await createDraft(api);
+
+ const { data } = await api.patch<CampaignJson>(`/api/campaigns/${id}`, {
+ scheduledAt: "2026-12-01T00:00:00.000Z",
+ });
+
+ expect(data.scheduledAt).toBeNull();
+ } finally {
+ await deleteCampaign(api, id);
+ }
+});
+
+test("GET /campaigns/:id", async ({ api }) => {
+ let id: string | undefined;
+
+ try {
+ id = await createDraft(api);
+
+ const { status, data } = await api.get<CampaignJson>(
+ `/api/campaigns/${id}`,
+ );
+
+ expect(status).toEqual(200);
+ expect(data).toStrictEqual({
+ ...defaultCampaign("transactional"),
+ id,
+ });
+ } finally {
+ await deleteCampaign(api, id);
+ }
+});
+
+test("GET /campaigns – list by search", async ({ api }) => {
+ let id: string | undefined;
+ const name = randomName("campaign");
+
+ try {
+ id = await createDraft(api);
+ await api.patch(`/api/campaigns/${id}`, { name });
+
+ const { status, data: campaigns } = await api.get<CampaignJson[]>(
+ `/api/campaigns?search=${encodeURIComponent(name)}`,
+ );
+
+ expect(status).toEqual(200);
+
+ const { data: fetched } = await api.get<CampaignJson>(
+ `/api/campaigns/${id}`,
+ );
+
+ expect(campaigns.find((campaign) => campaign.id === id)).toStrictEqual(
+ fetched,
+ );
+ } finally {
+ await deleteCampaign(api, id);
+ }
+});
+
+test("PATCH /campaigns/:id – transactional status draft → active → paused → active", async ({
+ api,
+}) => {
+ let id: string | undefined;
+
+ try {
+ id = await createDraft(api);
+
+ const published = await api.patch<CampaignJson>(`/api/campaigns/${id}`, {
+ status: "active",
+ });
+ expect(published.status).toEqual(200);
+ expect(published.data.status).toEqual("active");
+
+ const paused = await api.patch<CampaignJson>(`/api/campaigns/${id}`, {
+ status: "paused",
+ });
+ expect(paused.status).toEqual(200);
+ expect(paused.data.status).toEqual("paused");
+
+ const resumed = await api.patch<CampaignJson>(`/api/campaigns/${id}`, {
+ status: "active",
+ });
+ expect(resumed.status).toEqual(200);
+ expect(resumed.data.status).toEqual("active");
+ } finally {
+ await deleteCampaign(api, id);
+ }
+});
+
+test("PATCH /campaigns/:id – marketing status draft → scheduled → canceled", async ({
+ api,
+}) => {
+ let id: string | undefined;
+ const scheduledAt = new Date(Date.now() + 60 * 60 * 1000).toISOString();
+
+ try {
+ id = await createDraft(api, "marketing");
+
+ const scheduled = await api.patch<CampaignJson>(`/api/campaigns/${id}`, {
+ status: "scheduled",
+ scheduledAt,
+ });
+ expect(scheduled.status).toEqual(200);
+ expect(scheduled.data.status).toEqual("scheduled");
+
+ const canceled = await api.patch<CampaignJson>(`/api/campaigns/${id}`, {
+ status: "canceled",
+ });
+ expect(canceled.status).toEqual(200);
+ expect(canceled.data.status).toEqual("canceled");
+ } finally {
+ await deleteCampaign(api, id);
+ }
+});
+
+test("POST /campaigns/:id/duplicate – transactional", async ({
+ api,
+ program,
+}) => {
+ let id: string | undefined;
+ let duplicateId: string | undefined;
+ const triggerCondition = {
+ attribute: "totalConversions",
+ operator: "gte",
+ value: 50,
+ } as const;
+ const body = campaignContent({
+ triggerCondition,
+ groupIds: [program.defaultGroupId],
+ });
+
+ try {
+ id = await createDraft(api);
+ await api.patch(`/api/campaigns/${id}`, body);
+
+ const { status, data } = await api.post<{ id: string }>(
+ `/api/campaigns/${id}/duplicate`,
+ );
+ duplicateId = data.id;
+
+ expect(status).toEqual(200);
+ expect(data).toStrictEqual({
+ id: expect.any(String),
+ });
+
+ const { data: duplicated } = await api.get<CampaignJson>(
+ `/api/campaigns/${duplicateId}`,
+ );
+
+ expect(duplicated).toStrictEqual({
+ ...defaultCampaign("transactional"),
+ id: duplicateId,
+ name: `${body.name} (copy)`,
+ subject: body.subject,
+ bodyJson: body.bodyJson,
+ triggerCondition,
+ groups: [{ id: program.defaultGroupId }],
+ status: "draft",
+ });
+ } finally {
+ await deleteCampaign(api, duplicateId);
+ await deleteCampaign(api, id);
+ }
+});
+
+test("POST /campaigns/:id/duplicate – marketing", async ({ api }) => {
+ let id: string | undefined;
+ let duplicateId: string | undefined;
+ const body = campaignContent();
+
+ try {
+ id = await createDraft(api, "marketing");
+ await api.patch(`/api/campaigns/${id}`, body);
+
+ const { status, data } = await api.post<{ id: string }>(
+ `/api/campaigns/${id}/duplicate`,
+ );
+ duplicateId = data.id;
+
+ expect(status).toEqual(200);
+
+ const { data: duplicated } = await api.get<CampaignJson>(
+ `/api/campaigns/${duplicateId}`,
+ );
+
+ expect(duplicated).toMatchObject({
+ id: duplicateId,
+ type: "marketing",
+ name: `${body.name} (copy)`,
+ subject: body.subject,
+ bodyJson: body.bodyJson,
+ triggerCondition: null,
+ status: "draft",
+ });
+ } finally {
+ await deleteCampaign(api, duplicateId);
+ await deleteCampaign(api, id);
+ }
+});
+
+test("DELETE /campaigns/:id", async ({ api }) => {
+ const id = await createDraft(api);
+
+ const { status, data } = await api.delete<{ id: string }>(
+ `/api/campaigns/${id}`,
+ );
+
+ expect(status).toEqual(200);
+ expect(data).toStrictEqual({ id });
+ expect(await api.get(`/api/campaigns/${id}`)).toEqual(
+ apiError({
+ code: "not_found",
+ message: "Campaign not found.",
+ }),
+ );
+});
+
+const errorCases = [
+ {
+ name: "POST /campaigns – missing type",
+ body: {},
+ expected: apiError({
+ code: "unprocessable_entity",
+ message:
+ 'invalid_value: type: Invalid option: expected one of "marketing"|"transactional"',
+ }),
+ },
+ {
+ name: "POST /campaigns – invalid type",
+ body: { type: "invalid" },
+ expected: apiError({
+ code: "unprocessable_entity",
+ message:
+ 'invalid_value: type: Invalid option: expected one of "marketing"|"transactional"',
+ }),
+ },
+];
+
+for (const { name, body, expected } of errorCases) {
+ test(name, async ({ api }) => {
+ expect(await api.post("/api/campaigns", body)).toEqual(expected);
+ });
+}
+
+test("GET /campaigns/:id – not found", async ({ api }) => {
+ expect(await api.get("/api/campaigns/cmp_does_not_exist")).toEqual(
+ apiError({
+ code: "not_found",
+ message: "Campaign not found.",
+ }),
+ );
+});
+
+test("PATCH /campaigns/:id – marketing draft cannot become active", async ({
+ api,
+}) => {
+ let id: string | undefined;
+
+ try {
+ id = await createDraft(api, "marketing");
+ expect(
+ await api.patch(`/api/campaigns/${id}`, { status: "active" }),
+ ).toEqual(
+ apiError({
+ code: "bad_request",
+ message: "A draft campaign can't be moved to active.",
+ }),
+ );
+ } finally {
+ await deleteCampaign(api, id);
+ }
+});
+
+test("PATCH /campaigns/:id – transactional draft cannot become scheduled", async ({
+ api,
+}) => {
+ let id: string | undefined;
+
+ try {
+ id = await createDraft(api);
+ expect(
+ await api.patch(`/api/campaigns/${id}`, { status: "scheduled" }),
+ ).toEqual(
+ apiError({
+ code: "bad_request",
+ message: "A draft campaign can't be moved to scheduled.",
+ }),
+ );
+ } finally {
+ await deleteCampaign(api, id);
+ }
+});
diff --git a/apps/web/playwright/api/campaigns/helpers.ts b/apps/web/playwright/api/campaigns/helpers.ts
new file mode 100644
index 0000000000..ed2c952ef7
--- /dev/null
+++ b/apps/web/playwright/api/campaigns/helpers.ts
@@ -0,0 +1,48 @@
+import type { Campaign } from "@/lib/types";
+import type { CampaignType } from "@prisma/client";
+import { randomName } from "../../utils";
+import type { ApiClient } from "../fixtures";
+
+export type CampaignJson = Omit<
+ Campaign,
+ "scheduledAt" | "createdAt" | "updatedAt"
+> & {
+ scheduledAt: string | null;
+ createdAt: string;
+ updatedAt: string;
+};
+
+export const defaultTransactionalTrigger = {
+ attribute: "partnerJoined",
+ operator: "gte",
+ value: 0,
+} as const;
+
+export function campaignContent(overrides: Record<string, unknown> = {}) {
+ return {
+ name: randomName("campaign"),
+ subject: randomName("subject"),
+ bodyJson: {
+ type: "doc",
+ content: [
+ {
+ type: "paragraph",
+ content: [{ type: "text", text: "Test campaign body" }],
+ },
+ ],
+ },
+ ...overrides,
+ };
+}
+
+export async function createCampaign(
+ api: ApiClient,
+ type: CampaignType = "transactional",
+) {
+ return api.post<{ id: string }>("/api/campaigns", { type });
+}
+
+export async function deleteCampaign(api: ApiClient, id: string | undefined) {
+ if (!id) return;
+ await api.delete(`/api/campaigns/${id}`);
+}
diff --git a/apps/web/playwright/api/customers/customers-pagination.spec.ts b/apps/web/playwright/api/customers/customers-pagination.spec.ts
index 9792aad5a8..5aae7a8d0b 100644
--- a/apps/web/playwright/api/customers/customers-pagination.spec.ts
+++ b/apps/web/playwright/api/customers/customers-pagination.spec.ts
@@ -4,6 +4,7 @@ import type { Customer } from "@/lib/types";
import { nanoid } from "@dub/utils";
import { expect } from "@playwright/test";
import {
+ apiError,
expectNoOverlap,
expectSortedByCreatedAt,
expectSortedById,
@@ -13,61 +14,50 @@ import { test } from "../fixtures";
const PAGE_SIZE = 5;
const SEED_COUNT = 25;
-test.describe.configure({
- mode: "parallel",
-});
-
test("GET /customers – rejects both startingAfter and endingBefore", async ({
api,
}) => {
- const { status, data: error } = await api.get(
- `/api/customers?${new URLSearchParams({
- pageSize: String(PAGE_SIZE),
- startingAfter: "id",
- endingBefore: "id",
- })}`,
- );
-
- expect(status).toEqual(422);
- expect(error).toStrictEqual({
- error: {
+ expect(
+ await api.get(
+ `/api/customers?${new URLSearchParams({
+ pageSize: String(PAGE_SIZE),
+ startingAfter: "id",
+ endingBefore: "id",
+ })}`,
+ ),
+ ).toEqual(
+ apiError({
code: "unprocessable_entity",
message:
"You cannot use both startingAfter and endingBefore at the same time.",
- doc_url: "https://dub.co/docs/api-reference/errors#unprocessable-entity",
- },
- });
+ }),
+ );
});
test("GET /customers – rejects page > MAX_OFFSET_PAGE", async ({ api }) => {
- const { status, data: error } = await api.get(
- `/api/customers?${new URLSearchParams({
- page: "1001",
- pageSize: "10",
- })}`,
- );
-
- expect(status).toEqual(422);
- expect(error).toStrictEqual({
- error: {
+ expect(
+ await api.get(
+ `/api/customers?${new URLSearchParams({
+ page: "1001",
+ pageSize: "10",
+ })}`,
+ ),
+ ).toEqual(
+ apiError({
code: "unprocessable_entity",
message:
"Page is too big (cannot be more than 1000), recommend using cursor-based pagination instead.",
- doc_url: "https://dub.co/docs/api-reference/errors#unprocessable-entity",
- },
- });
+ }),
+ );
});
test("GET /customers – invalid cursor ID (startingAfter / endingBefore)", async ({
api,
}) => {
- const invalidCursorError = {
- error: {
- code: "unprocessable_entity",
- message: "Invalid cursor: the provided ID does not exist.",
- doc_url: "https://dub.co/docs/api-reference/errors#unprocessable-entity",
- },
- };
+ const invalidCursorError = apiError({
+ code: "unprocessable_entity",
+ message: "Invalid cursor: the provided ID does not exist.",
+ });
const { status: statusAfter, data: errorAfter } = await api.get(
`/api/customers?${new URLSearchParams({
@@ -76,8 +66,7 @@ test("GET /customers – invalid cursor ID (startingAfter / endingBefore)", asyn
})}`,
);
- expect(statusAfter).toEqual(422);
- expect(errorAfter).toStrictEqual(invalidCursorError);
+ expect({ status: statusAfter, data: errorAfter }).toEqual(invalidCursorError);
const { status: statusBefore, data: errorBefore } = await api.get(
`/api/customers?${new URLSearchParams({
@@ -86,8 +75,9 @@ test("GET /customers – invalid cursor ID (startingAfter / endingBefore)", asyn
})}`,
);
- expect(statusBefore).toEqual(422);
- expect(errorBefore).toStrictEqual(invalidCursorError);
+ expect({ status: statusBefore, data: errorBefore }).toEqual(
+ invalidCursorError,
+ );
});
test.describe("with seeded customers", () => {
@@ -224,15 +214,11 @@ test.describe("with seeded customers", () => {
test("GET /customers – rejects mixing page with startingAfter / endingBefore", async ({
api,
}) => {
- const mixedPaginationError = {
- error: {
- code: "unprocessable_entity",
- message:
- "You cannot use both page and startingAfter/endingBefore at the same time. Please use one pagination method.",
- doc_url:
- "https://dub.co/docs/api-reference/errors#unprocessable-entity",
- },
- };
+ const mixedPaginationError = apiError({
+ code: "unprocessable_entity",
+ message:
+ "You cannot use both page and startingAfter/endingBefore at the same time. Please use one pagination method.",
+ });
const { status: statusAfter, data: errorAfter } = await api.get(
`/api/customers?${new URLSearchParams({
@@ -242,8 +228,9 @@ test.describe("with seeded customers", () => {
})}`,
);
- expect(statusAfter).toEqual(422);
- expect(errorAfter).toStrictEqual(mixedPaginationError);
+ expect({ status: statusAfter, data: errorAfter }).toEqual(
+ mixedPaginationError,
+ );
const { status: statusBefore, data: errorBefore } = await api.get(
`/api/customers?${new URLSearchParams({
@@ -253,8 +240,9 @@ test.describe("with seeded customers", () => {
})}`,
);
- expect(statusBefore).toEqual(422);
- expect(errorBefore).toStrictEqual(mixedPaginationError);
+ expect({ status: statusBefore, data: errorBefore }).toEqual(
+ mixedPaginationError,
+ );
});
test("GET /customers – rejects cursor pagination with unsupported sort field", async ({
@@ -268,15 +256,12 @@ test.describe("with seeded customers", () => {
})}`,
);
- expect(status).toEqual(422);
- expect(error).toStrictEqual({
- error: {
+ expect({ status, data: error }).toEqual(
+ apiError({
code: "unprocessable_entity",
message:
"Cursor-based pagination only supports sorting by `createdAt`. Use offset-based pagination (page/pageSize) for other sort fields.",
- doc_url:
- "https://dub.co/docs/api-reference/errors#unprocessable-entity",
- },
- });
+ }),
+ );
});
});
diff --git a/apps/web/playwright/api/customers/customers.spec.ts b/apps/web/playwright/api/customers/customers.spec.ts
index ed492a90a8..0fdbc971cd 100644
--- a/apps/web/playwright/api/customers/customers.spec.ts
+++ b/apps/web/playwright/api/customers/customers.spec.ts
@@ -36,10 +36,6 @@ async function deleteCustomer(api: ApiClient, id: string | undefined) {
await api.delete(`/api/customers/${id}`);
}
-test.describe.configure({
- mode: "parallel",
-});
-
test("POST /customers", async ({ api }) => {
let customerId: string | undefined;
const body = randomCustomer();
diff --git a/apps/web/playwright/api/domains/domains.spec.ts b/apps/web/playwright/api/domains/domains.spec.ts
index 757b776d88..70ba8a2986 100644
--- a/apps/web/playwright/api/domains/domains.spec.ts
+++ b/apps/web/playwright/api/domains/domains.spec.ts
@@ -1,6 +1,6 @@
import type { DomainProps } from "@/lib/types";
import { expect } from "@playwright/test";
-import { randomName } from "../../utils";
+import { apiError, randomName } from "../../utils";
import { test, type ApiClient } from "../fixtures";
test.describe.configure({
@@ -283,51 +283,31 @@ test("DELETE /domains/{slug}", async ({ api }) => {
});
test("GET /domains/status – not eligible", async ({ api }) => {
- const { status, data } = await api.get(
- "/api/domains/status?domains=example.link",
- );
-
- expect(status).toEqual(403);
- expect(data).toEqual({
- error: {
+ expect(await api.get("/api/domains/status?domains=example.link")).toEqual(
+ apiError({
code: "forbidden",
message:
"GET /domains/status is not available for your workspace. Contact support for more information.",
- doc_url: "https://dub.co/docs/api-reference/errors#forbidden",
- },
- });
+ }),
+ );
});
const errorCases = [
{
name: "POST /domains – without slug",
body: {},
- expected: {
- status: 422,
- data: {
- error: {
- code: "unprocessable_entity",
- message: "invalid_type: slug: slug is required",
- doc_url:
- "https://dub.co/docs/api-reference/errors#unprocessable-entity",
- },
- },
- },
+ expected: apiError({
+ code: "unprocessable_entity",
+ message: "invalid_type: slug: slug is required",
+ }),
},
{
name: "POST /domains – invalid domain",
body: { slug: "not a domain" },
- expected: {
- status: 422,
- data: {
- error: {
- code: "unprocessable_entity",
- message: "Invalid domain",
- doc_url:
- "https://dub.co/docs/api-reference/errors#unprocessable-entity",
- },
- },
- },
+ expected: apiError({
+ code: "unprocessable_entity",
+ message: "Invalid domain",
+ }),
},
];
@@ -348,14 +328,12 @@ test("POST /domains – existing slug", async ({ api }) => {
slug,
});
- expect(status).toEqual(409);
- expect(data).toEqual({
- error: {
+ expect({ status, data }).toEqual(
+ apiError({
code: "conflict",
message: "Domain is already in use.",
- doc_url: "https://dub.co/docs/api-reference/errors#conflict",
- },
- });
+ }),
+ );
} finally {
await deleteDomain(api, slug);
}
@@ -366,14 +344,12 @@ test("GET /domains/{slug} – not found", async ({ api }) => {
const { status, data } = await api.get(`/api/domains/${slug}`);
- expect(status).toEqual(404);
- expect(data).toEqual({
- error: {
+ expect({ status, data }).toEqual(
+ apiError({
code: "not_found",
message: `Domain ${slug} not found.`,
- doc_url: "https://dub.co/docs/api-reference/errors#not-found",
- },
- });
+ }),
+ );
});
test.describe("JSON config fields", () => {
@@ -490,17 +466,12 @@ test.describe("JSON config fields", () => {
...domainBody(slug),
[field]: INVALID_JSON,
}),
- ).toEqual({
- status: 422,
- data: {
- error: {
- code: "unprocessable_entity",
- message: `Invalid ${label}`,
- doc_url:
- "https://dub.co/docs/api-reference/errors#unprocessable-entity",
- },
- },
- });
+ ).toEqual(
+ apiError({
+ code: "unprocessable_entity",
+ message: `Invalid ${label}`,
+ }),
+ );
});
test(`PATCH /domains/{slug} – invalid ${field} JSON`, async ({ api }) => {
@@ -514,17 +485,12 @@ test.describe("JSON config fields", () => {
await api.patch(`/api/domains/${slug}`, {
[field]: INVALID_JSON,
}),
- ).toEqual({
- status: 422,
- data: {
- error: {
- code: "unprocessable_entity",
- message: `Invalid ${label}`,
- doc_url:
- "https://dub.co/docs/api-reference/errors#unprocessable-entity",
- },
- },
- });
+ ).toEqual(
+ apiError({
+ code: "unprocessable_entity",
+ message: `Invalid ${label}`,
+ }),
+ );
} finally {
await deleteDomain(api, slug);
}
diff --git a/apps/web/playwright/api/folders/folders.spec.ts b/apps/web/playwright/api/folders/folders.spec.ts
index ca1dcede7f..8a5101bcc0 100644
--- a/apps/web/playwright/api/folders/folders.spec.ts
+++ b/apps/web/playwright/api/folders/folders.spec.ts
@@ -31,10 +31,6 @@ async function deleteFolder(api: ApiClient, folderId: string) {
await api.delete(`/api/folders/${folderId}`);
}
-test.describe.configure({
- mode: "parallel",
-});
-
test("POST /folders", async ({ api }) => {
let folderId: string | undefined;
const folderName = randomName("folder");
diff --git a/apps/web/playwright/api/partners/ban-partner.spec.ts b/apps/web/playwright/api/partners/ban-partner.spec.ts
index 2ee5ae7b5b..14db60401e 100644
--- a/apps/web/playwright/api/partners/ban-partner.spec.ts
+++ b/apps/web/playwright/api/partners/ban-partner.spec.ts
@@ -3,13 +3,9 @@ import { prisma } from "@/lib/prisma";
import type { EnrolledPartnerProps } from "@/lib/types";
import { nanoid } from "@dub/utils";
import { expect } from "@playwright/test";
-import { randomName, randomPartnerEmail } from "../../utils";
+import { apiError, randomName, randomPartnerEmail } from "../../utils";
import { test, type ApiClient } from "../fixtures";
-test.describe.configure({
- mode: "parallel",
-});
-
async function createPartner(
api: ApiClient,
overrides: Record<string, unknown> = {},
@@ -136,16 +132,12 @@ test("POST /partners/ban – already banned", async ({ api, program }) => {
partnerId,
reason: "spam",
}),
- ).toEqual({
- status: 400,
- data: {
- error: {
- code: "bad_request",
- message: "This partner is already banned from your program.",
- doc_url: "https://dub.co/docs/api-reference/errors#bad-request",
- },
- },
- });
+ ).toEqual(
+ apiError({
+ code: "bad_request",
+ message: "This partner is already banned from your program.",
+ }),
+ );
} finally {
await deletePartner(partnerId);
}
@@ -159,16 +151,12 @@ test("POST /partners/ban – partner not found", async ({ api, program }) => {
partnerId,
reason: "fraud",
}),
- ).toEqual({
- status: 404,
- data: {
- error: {
- code: "not_found",
- message: `Partner ${partnerId} is not enrolled in program ${program.id}.`,
- doc_url: "https://dub.co/docs/api-reference/errors#not-found",
- },
- },
- });
+ ).toEqual(
+ apiError({
+ code: "not_found",
+ message: `Partner ${partnerId} is not enrolled in program ${program.id}.`,
+ }),
+ );
});
test("POST /partners/ban – tenantId not found", async ({ api }) => {
@@ -179,44 +167,28 @@ test("POST /partners/ban – tenantId not found", async ({ api }) => {
tenantId,
reason: "fraud",
}),
- ).toEqual({
- status: 404,
- data: {
- error: {
- code: "not_found",
- message: `Partner with tenantId ${tenantId} not found in program.`,
- doc_url: "https://dub.co/docs/api-reference/errors#not-found",
- },
- },
- });
+ ).toEqual(
+ apiError({
+ code: "not_found",
+ message: `Partner with tenantId ${tenantId} not found in program.`,
+ }),
+ );
});
-const invalidReasonError = {
- status: 422,
- data: {
- error: {
- code: "unprocessable_entity",
- message:
- 'invalid_value: reason: Invalid option: expected one of "tos_violation"|"inappropriate_content"|"fake_traffic"|"fraud"|"spam"|"brand_abuse"',
- doc_url: "https://dub.co/docs/api-reference/errors#unprocessable-entity",
- },
- },
-};
+const invalidReasonError = apiError({
+ code: "unprocessable_entity",
+ message:
+ 'invalid_value: reason: Invalid option: expected one of "tos_violation"|"inappropriate_content"|"fake_traffic"|"fraud"|"spam"|"brand_abuse"',
+});
const banErrorCases = [
{
name: "POST /partners/ban – missing partnerId and tenantId",
body: { reason: "fraud" },
- expected: {
- status: 400,
- data: {
- error: {
- code: "bad_request",
- message: "Either `partnerId` or `tenantId` must be provided.",
- doc_url: "https://dub.co/docs/api-reference/errors#bad-request",
- },
- },
- },
+ expected: apiError({
+ code: "bad_request",
+ message: "Either `partnerId` or `tenantId` must be provided.",
+ }),
},
{
name: "POST /partners/ban – missing reason",
diff --git a/apps/web/playwright/api/partners/partners.spec.ts b/apps/web/playwright/api/partners/partners.spec.ts
index 1fc27831ac..d7fbc62a0b 100644
--- a/apps/web/playwright/api/partners/partners.spec.ts
+++ b/apps/web/playwright/api/partners/partners.spec.ts
@@ -6,14 +6,10 @@ import { nanoid } from "@dub/utils";
import { expect } from "@playwright/test";
import slugify from "@sindresorhus/slugify";
import * as z from "zod/v4";
-import { randomName, randomPartnerEmail } from "../../utils";
+import { apiError, randomName, randomPartnerEmail } from "../../utils";
import { test, type ApiClient } from "../fixtures";
import { TEST_WORKSPACE } from "../setup-test-workspace";
-test.describe.configure({
- mode: "parallel",
-});
-
const EnrolledPartnerSchema = EnrolledPartnerSchemaDate.extend({
createdAt: z.string(),
bannedAt: z.string().nullish(),
@@ -175,18 +171,13 @@ test("POST /partners – invalid username", async ({ api }) => {
email: randomPartnerEmail(),
username: "invalid username",
}),
- ).toEqual({
- status: 422,
- data: {
- error: {
- code: "unprocessable_entity",
- message:
- "custom: username: Invalid username. Must be a URL-friendly string.",
- doc_url:
- "https://dub.co/docs/api-reference/errors#unprocessable-entity",
- },
- },
- });
+ ).toEqual(
+ apiError({
+ code: "unprocessable_entity",
+ message:
+ "custom: username: Invalid username. Must be a URL-friendly string.",
+ }),
+ );
});
test("POST /partners – linkProps.prefix on default link", async ({
diff --git a/apps/web/playwright/api/tags/tags.spec.ts b/apps/web/playwright/api/tags/tags.spec.ts
index 7a51fe5adb..787a7b6eca 100644
--- a/apps/web/playwright/api/tags/tags.spec.ts
+++ b/apps/web/playwright/api/tags/tags.spec.ts
@@ -1,12 +1,8 @@
import { expect } from "@playwright/test";
import type { Tag } from "@prisma/client";
-import { randomName } from "../../utils";
+import { apiError, randomName } from "../../utils";
import { test } from "../fixtures";
-test.describe.configure({
- mode: "parallel",
-});
-
test("POST /tags", async ({ api }) => {
let tagId: string | undefined;
@@ -36,35 +32,21 @@ const errorCases = [
tag: "news",
color: "invalid",
},
- expected: {
- status: 422,
- data: {
- error: {
- code: "unprocessable_entity",
- message:
- "invalid_value: color: Invalid color. Must be one of: red, yellow, green, blue, purple, brown, gray, pink", // TODO: update this to use RESOURCE_COLORS
- doc_url:
- "https://dub.co/docs/api-reference/errors#unprocessable-entity",
- },
- },
- },
+ expected: apiError({
+ code: "unprocessable_entity",
+ message:
+ "invalid_value: color: Invalid color. Must be one of: red, yellow, green, blue, purple, brown, gray, pink", // TODO: update this to use RESOURCE_COLORS
+ }),
},
{
name: "POST /tags – without name",
body: {
color: "red",
},
- expected: {
- status: 422,
- data: {
- error: {
- code: "unprocessable_entity",
- message: "custom: name: Name is required.",
- doc_url:
- "https://dub.co/docs/api-reference/errors#unprocessable-entity",
- },
- },
- },
+ expected: apiError({
+ code: "unprocessable_entity",
+ message: "custom: name: Name is required.",
+ }),
},
];
@@ -92,14 +74,12 @@ test("POST /tags – existing name", async ({ api }) => {
color: "red",
});
- expect(status).toBe(409);
- expect(error).toEqual({
- error: {
+ expect({ status, data: error }).toEqual(
+ apiError({
code: "conflict",
message: "A tag with that name already exists.",
- doc_url: "https://dub.co/docs/api-reference/errors#conflict",
- },
- });
+ }),
+ );
} finally {
if (tagId) await api.delete(`/api/tags/${tagId}`);
}
diff --git a/apps/web/playwright/api/utm/utm.spec.ts b/apps/web/playwright/api/utm/utm.spec.ts
index cce166dbcf..c747172b25 100644
--- a/apps/web/playwright/api/utm/utm.spec.ts
+++ b/apps/web/playwright/api/utm/utm.spec.ts
@@ -1,6 +1,6 @@
import { expect } from "@playwright/test";
import type { UtmTemplate } from "@prisma/client";
-import { randomName } from "../../utils";
+import { apiError, randomName } from "../../utils";
import { test, type ApiClient } from "../fixtures";
type UtmTemplateResponse = Pick<
@@ -49,10 +49,6 @@ async function deleteUtmTemplate(api: ApiClient, id: string | undefined) {
await api.delete(`/api/utm/${id}`);
}
-test.describe.configure({
- mode: "parallel",
-});
-
test("POST /utm", async ({ api, workspace }) => {
let id: string | undefined;
const body = {
@@ -122,65 +118,37 @@ const errorCases = [
{
name: "POST /utm – missing name",
body: {},
- expected: {
- status: 422,
- data: {
- error: {
- code: "unprocessable_entity",
- message:
- "invalid_type: name: Invalid input: expected string, received undefined",
- doc_url:
- "https://dub.co/docs/api-reference/errors#unprocessable-entity",
- },
- },
- },
+ expected: apiError({
+ code: "unprocessable_entity",
+ message:
+ "invalid_type: name: Invalid input: expected string, received undefined",
+ }),
},
{
name: "POST /utm – empty name",
body: { name: "" },
- expected: {
- status: 422,
- data: {
- error: {
- code: "unprocessable_entity",
- message: "too_small: name: UTM name is required",
- doc_url:
- "https://dub.co/docs/api-reference/errors#unprocessable-entity",
- },
- },
- },
+ expected: apiError({
+ code: "unprocessable_entity",
+ message: "too_small: name: UTM name is required",
+ }),
},
{
name: "POST /utm – name too long",
body: { name: "a".repeat(51) },
- expected: {
- status: 422,
- data: {
- error: {
- code: "unprocessable_entity",
- message:
- "too_big: name: Too big: expected string to have <=50 characters",
- doc_url:
- "https://dub.co/docs/api-reference/errors#unprocessable-entity",
- },
- },
- },
+ expected: apiError({
+ code: "unprocessable_entity",
+ message:
+ "too_big: name: Too big: expected string to have <=50 characters",
+ }),
},
{
name: "POST /utm – utm_source too long",
body: { name: randomName("utm"), utm_source: "a".repeat(256) },
- expected: {
- status: 422,
- data: {
- error: {
- code: "unprocessable_entity",
- message:
- "too_big: utm_source: Too big: expected string to have <=255 characters",
- doc_url:
- "https://dub.co/docs/api-reference/errors#unprocessable-entity",
- },
- },
- },
+ expected: apiError({
+ code: "unprocessable_entity",
+ message:
+ "too_big: utm_source: Too big: expected string to have <=255 characters",
+ }),
},
];
@@ -204,14 +172,12 @@ test("POST /utm – existing name", async ({ api }) => {
name: templateName,
});
- expect(status).toBe(409);
- expect(error).toEqual({
- error: {
+ expect({ status, data: error }).toEqual(
+ apiError({
code: "conflict",
message: "A template with that name already exists.",
- doc_url: "https://dub.co/docs/api-reference/errors#conflict",
- },
- });
+ }),
+ );
} finally {
await deleteUtmTemplate(api, id);
}
@@ -294,16 +260,12 @@ test("PATCH /utm/{id}", async ({ api }) => {
test("PATCH /utm/{id} – not found", async ({ api }) => {
expect(
await api.patch("/api/utm/utm_missing", { name: randomName("utm") }),
- ).toEqual({
- status: 404,
- data: {
- error: {
- code: "not_found",
- message: "Template not found.",
- doc_url: "https://dub.co/docs/api-reference/errors#not-found",
- },
- },
- });
+ ).toEqual(
+ apiError({
+ code: "not_found",
+ message: "Template not found.",
+ }),
+ );
});
test("DELETE /utm/{id}", async ({ api }) => {
@@ -324,14 +286,10 @@ test("DELETE /utm/{id}", async ({ api }) => {
});
test("DELETE /utm/{id} – not found", async ({ api }) => {
- expect(await api.delete("/api/utm/utm_missing")).toEqual({
- status: 404,
- data: {
- error: {
- code: "not_found",
- message: "UTM template not found.",
- doc_url: "https://dub.co/docs/api-reference/errors#not-found",
- },
- },
- });
+ expect(await api.delete("/api/utm/utm_missing")).toEqual(
+ apiError({
+ code: "not_found",
+ message: "UTM template not found.",
+ }),
+ );
});
diff --git a/apps/web/playwright/api/workspaces/workspaces.spec.ts b/apps/web/playwright/api/workspaces/workspaces.spec.ts
index 524c4d98ab..a39cdd3355 100644
--- a/apps/web/playwright/api/workspaces/workspaces.spec.ts
+++ b/apps/web/playwright/api/workspaces/workspaces.spec.ts
@@ -2,13 +2,10 @@ import { WorkspaceSchema } from "@/lib/zod/schemas/workspaces";
import { expect } from "@playwright/test";
import type { Project } from "@prisma/client";
import * as z from "zod/v4";
+import { apiError } from "../../utils";
import { test } from "../fixtures";
import { TEST_WORKSPACE } from "../setup-test-workspace";
-test.describe.configure({
- mode: "parallel",
-});
-
test("GET /workspaces/{idOrSlug} – by id", async ({ api, workspace }) => {
const { status, data: workspaceFetched } = await api.get<Project>(
`/api/workspaces/${workspace.id}`,
@@ -48,14 +45,10 @@ test("GET /workspaces/{idOrSlug} – by slug", async ({ api, workspace }) => {
});
test("GET /workspaces/{idOrSlug} – invalid slug or id", async ({ api }) => {
- const { status, data: error } = await api.get(`/api/workspaces/xxxx`);
-
- expect(status).toEqual(404);
- expect(error).toStrictEqual({
- error: {
+ expect(await api.get(`/api/workspaces/xxxx`)).toEqual(
+ apiError({
code: "not_found",
message: "Workspace not found.",
- doc_url: "https://dub.co/docs/api-reference/errors#not-found",
- },
- });
+ }),
+ );
});
diff --git a/apps/web/playwright/utils.ts b/apps/web/playwright/utils.ts
index d7cdcae455..ae7c445c35 100644
--- a/apps/web/playwright/utils.ts
+++ b/apps/web/playwright/utils.ts
@@ -1,7 +1,27 @@
+import { ErrorCodes } from "@/lib/api/error-codes";
import { generateRandomName } from "@/lib/names";
import { nanoid } from "@dub/utils";
import { expect } from "@playwright/test";
+export function apiError({
+ code,
+ message,
+}: {
+ code: keyof typeof ErrorCodes;
+ message: string;
+}) {
+ return {
+ status: ErrorCodes[code],
+ data: {
+ error: {
+ code,
+ message,
+ doc_url: `https://dub.co/docs/api-reference/errors#${code.replace("_", "-")}`,
+ },
+ },
+ };
+}
+
export function randomName(prefix = "e2e", length = 5) {
return `${prefix}-${nanoid(length)}`;
}