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.

fix the tests

Kiran K7e76c1458f6e
diff --git a/apps/web/app/api/domains/[domain]/primary/route.ts b/apps/web/app/api/domains/[domain]/primary/route.ts
index 0b10c1c8a5..5c53d188bc 100644
--- a/apps/web/app/api/domains/[domain]/primary/route.ts
+++ b/apps/web/app/api/domains/[domain]/primary/route.ts
@@ -1,12 +1,12 @@
+import { getDomain } from "@/lib/api/domains/get-domain";
import { withWorkspace } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
-import { DomainSchema } from "@/lib/zod/schemas/domains";
import { NextResponse } from "next/server";
// POST /api/domains/[domain]/primary – set a domain as primary
export const POST = withWorkspace(
async ({ headers, workspace, domain }) => {
- const responses = await Promise.all([
+ await Promise.all([
prisma.domain.update({
where: {
slug: domain,
@@ -30,7 +30,12 @@ export const POST = withWorkspace(
}),
]);
- return NextResponse.json(DomainSchema.parse(responses[0]), { headers });
+ const domainRecord = await getDomain({
+ slug: domain,
+ workspaceId: workspace.id,
+ });
+
+ return NextResponse.json(domainRecord, { headers });
},
{
domainChecks: true,
diff --git a/apps/web/app/api/domains/route.ts b/apps/web/app/api/domains/route.ts
index 7dbf05a5dc..0c46d25c50 100644
--- a/apps/web/app/api/domains/route.ts
+++ b/apps/web/app/api/domains/route.ts
@@ -33,7 +33,14 @@ export const GET = withWorkspace(async ({ workspace }) => {
},
});
- const result = domains.map((domain) => transformDomain(domain));
+ const result = domains.map((domain) => {
+ const domainRecord = transformDomain(domain);
+
+ return {
+ ...domainRecord,
+ url: domainRecord.target,
+ };
+ });
return NextResponse.json(result);
});
diff --git a/apps/web/lib/api/domains/transform-domain.ts b/apps/web/lib/api/domains/transform-domain.ts
index bc642725e2..352846ceb6 100644
--- a/apps/web/lib/api/domains/transform-domain.ts
+++ b/apps/web/lib/api/domains/transform-domain.ts
@@ -1,3 +1,4 @@
+import { DomainSchema } from "@/lib/zod/schemas/domains";
import { Domain, Link } from "@prisma/client";
type Input = Domain & {
@@ -8,7 +9,7 @@ export const transformDomain = (domain: Input) => {
const { id, slug, verified, primary, archived, placeholder } = domain;
const { url, rewrite, clicks, expiredUrl, noindex } = domain.links[0];
- return {
+ return DomainSchema.parse({
id,
slug,
verified,
@@ -18,10 +19,9 @@ export const transformDomain = (domain: Input) => {
placeholder,
expiredUrl,
target: url || null,
- url: url || null, // Deprecated
type: rewrite ? "rewrite" : "redirect",
clicks,
createdAt: domain.createdAt,
updatedAt: domain.updatedAt,
- };
+ });
};
diff --git a/apps/web/tests/domains/index.test.ts b/apps/web/tests/domains/index.test.ts
index 2bc901c15a..cfbdae4fdb 100644
--- a/apps/web/tests/domains/index.test.ts
+++ b/apps/web/tests/domains/index.test.ts
@@ -24,7 +24,6 @@ const expectedDomain = {
placeholder: domainRecord.placeholder,
expiredUrl: domainRecord.expiredUrl,
target: domainRecord.target,
- url: domainRecord.target,
type: domainRecord.type,
clicks: 0,
createdAt: expect.any(String),
@@ -77,10 +76,7 @@ describe.sequential("/domains/**", async () => {
});
expect(status).toEqual(200);
- expect(domain).toStrictEqual({
- ...expectedDomain,
- url: domainRecord.target,
- });
+ expect(domain).toStrictEqual(expectedDomain);
});
test("GET /domains", async () => {
@@ -90,7 +86,10 @@ describe.sequential("/domains/**", async () => {
});
expect(status).toEqual(200);
- expect(domains).toContainEqual(expectedDomain);
+ expect(domains).toContainEqual({
+ ...expectedDomain,
+ url: domainRecord.target,
+ });
});
test("POST /domains/{slug}/primary", { retry: 3 }, async () => {
@@ -126,7 +125,6 @@ describe.sequential("/domains/**", async () => {
expect(domain).toStrictEqual({
...expectedDomain,
...toUpdate,
- url: toUpdate.target,
});
});
});