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 tests

Steven Tey3227dbb2bd37
diff --git a/apps/web/tests/partners/upsert-partner-link.test.ts b/apps/web/tests/partners/upsert-partner-link.test.ts
index cc46cc46bc..82030d66d3 100644
--- a/apps/web/tests/partners/upsert-partner-link.test.ts
+++ b/apps/web/tests/partners/upsert-partner-link.test.ts
@@ -1,4 +1,5 @@
import { Link } from "@dub/prisma/client";
+import { nanoid } from "@dub/utils";
import { randomId } from "tests/utils/helpers";
import { afterAll, describe, expect, test } from "vitest";
import { IntegrationHarness } from "../utils/integration";
@@ -15,13 +16,15 @@ describe.sequential("PUT /partners/links/upsert", async () => {
await h.deleteLink(createdLink.id);
});
+ const randomUrl = `${E2E_PROGRAM.url}/${nanoid()}`;
+
test("New link", async () => {
const { data, status } = await http.put<Link>({
path: "/partners/links/upsert",
body: {
programId: E2E_PROGRAM.id,
partnerId: E2E_PARTNER.id,
- url: E2E_PROGRAM.url,
+ url: randomUrl,
},
});
@@ -30,19 +33,20 @@ describe.sequential("PUT /partners/links/upsert", async () => {
expect(status).toEqual(200);
expect(createdLink).toStrictEqual({
...partnerLink,
- url: E2E_PROGRAM.url,
+ url: randomUrl,
});
});
test("Existing link", async () => {
- const newKey = randomId();
+ const key = randomId();
const { data: updatedLink, status } = await http.put<Link>({
path: "/partners/links/upsert",
body: {
programId: E2E_PROGRAM.id,
partnerId: E2E_PARTNER.id,
- key: newKey,
+ url: randomUrl,
+ key,
},
});
@@ -50,9 +54,9 @@ describe.sequential("PUT /partners/links/upsert", async () => {
expect(updatedLink).toStrictEqual({
...createdLink,
updatedAt: expect.any(String),
- key: newKey,
- shortLink: `https://${E2E_PROGRAM.domain}/${newKey}`,
- qrCode: `https://api.dub.co/qr?url=https://${E2E_PROGRAM.domain}/${newKey}?qr=1`,
+ key,
+ shortLink: `https://${E2E_PROGRAM.domain}/${key}`,
+ qrCode: `https://api.dub.co/qr?url=https://${E2E_PROGRAM.domain}/${key}?qr=1`,
});
});
});
diff --git a/apps/web/ui/partners/add-partner-link-modal.tsx b/apps/web/ui/partners/add-partner-link-modal.tsx
index 767d4889a1..bde55b1895 100644
--- a/apps/web/ui/partners/add-partner-link-modal.tsx
+++ b/apps/web/ui/partners/add-partner-link-modal.tsx
@@ -46,6 +46,7 @@ const AddPartnerLinkModal = ({
key: "",
},
});
+ const isExactMode = program?.urlValidationMode === "exact";
const key = watch("key");
const destinationDomain = getDomainWithoutWWW(program?.url || "");
@@ -69,10 +70,12 @@ const AddPartnerLinkModal = ({
partnerId: partner.id,
programId: program.id,
domain: program.domain,
- url: linkConstructor({
- domain: destinationDomain,
- key: formData.url,
- }),
+ url: isExactMode
+ ? program.url
+ : linkConstructor({
+ domain: destinationDomain,
+ key: formData.url,
+ }),
trackConversion: true,
folderId: program.defaultFolderId,
}),
@@ -164,52 +167,54 @@ const AddPartnerLinkModal = ({
)}
</div>
- <div className="flex flex-col gap-2">
- <div className="flex items-center gap-2">
- <label
- htmlFor="url"
- className="block text-sm font-medium text-neutral-700"
- >
- Destination URL
- </label>
+ {!isExactMode && (
+ <div className="flex flex-col gap-2">
+ <div className="flex items-center gap-2">
+ <label
+ htmlFor="url"
+ className="block text-sm font-medium text-neutral-700"
+ >
+ Destination URL
+ </label>
- <InfoTooltip
- content={
- <SimpleTooltipContent
- title="The URL your users will get redirected to when they visit your short link."
- cta="Learn more."
- href="https://dub.co/help/article/how-to-create-link"
- />
- }
- />
- </div>
+ <InfoTooltip
+ content={
+ <SimpleTooltipContent
+ title="The URL your users will get redirected to when they visit your short link."
+ cta="Learn more."
+ href="https://dub.co/help/article/how-to-create-link"
+ />
+ }
+ />
+ </div>
- <div className="flex">
- <span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-3 text-neutral-500 sm:text-sm">
- {destinationDomain}
- </span>
+ <div className="flex">
+ <span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-3 text-neutral-500 sm:text-sm">
+ {destinationDomain}
+ </span>
- <input
- {...register("url", { required: false })}
- type="text"
- id="url"
- placeholder="(optional)"
- className="block w-full rounded-r-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
- onPaste={(e: React.ClipboardEvent<HTMLInputElement>) => {
- e.preventDefault();
+ <input
+ {...register("url", { required: false })}
+ type="text"
+ id="url"
+ placeholder="(optional)"
+ className="block w-full rounded-r-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
+ onPaste={(e: React.ClipboardEvent<HTMLInputElement>) => {
+ e.preventDefault();
- const text = e.clipboardData.getData("text/plain");
+ const text = e.clipboardData.getData("text/plain");
- try {
- const url = new URL(text);
- e.currentTarget.value = url.pathname.slice(1);
- } catch (err) {
- e.currentTarget.value = text;
- }
- }}
- />
+ try {
+ const url = new URL(text);
+ e.currentTarget.value = url.pathname.slice(1);
+ } catch (err) {
+ e.currentTarget.value = text;
+ }
+ }}
+ />
+ </div>
</div>
- </div>
+ )}
</div>
</div>