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.

Refactor link redirects tests and fix test failures

Kiran K9b1c793d59e7
diff --git a/apps/web/tests/redirects/index.test.ts b/apps/web/tests/redirects/index.test.ts
index b3694ff50b..f216c29bdc 100644
--- a/apps/web/tests/redirects/index.test.ts
+++ b/apps/web/tests/redirects/index.test.ts
@@ -1,9 +1,7 @@
-import { Link } from "@prisma/client";
import { describe, expect, test } from "vitest";
import { IntegrationHarness } from "../utils/integration";
const poweredBy = "Dub.co - Link management for modern marketing teams";
-const domain = "dub.sh";
const fetchOptions: RequestInit = {
cache: "no-store",
redirect: "manual",
@@ -12,15 +10,11 @@ const fetchOptions: RequestInit = {
},
};
-type LinkWithShortLink = Link & { shortLink: string };
-
describe.sequential("Link Redirects", async () => {
const h = new IntegrationHarness();
- const { workspace, http } = await h.init();
- const { workspaceId } = workspace;
test("root", async () => {
- const response = await fetch("https://dub.sh/", fetchOptions);
+ const response = await fetch(h.baseUrl, fetchOptions);
expect(response.headers.get("location")).toBe("https://dub.co/");
expect(response.headers.get("x-powered-by")).toBe(poweredBy);
@@ -28,114 +22,55 @@ describe.sequential("Link Redirects", async () => {
});
test("regular", async () => {
- const url = "https://www.checklyhq.com/";
-
- const { data: link } = await http.post<LinkWithShortLink>({
- path: "/links",
- query: { workspaceId },
- body: {
- domain,
- url,
- },
- });
+ const response = await fetch(`${h.baseUrl}/checkly-check`, fetchOptions);
- const response = await fetch(`${h.baseUrl}/${link.key}`, fetchOptions);
-
- expect(response.headers.get("location")).toBe(url);
+ expect(response.headers.get("location")).toBe("https://www.checklyhq.com/");
expect(response.headers.get("x-powered-by")).toBe(poweredBy);
expect(response.status).toBe(302);
-
- await h.deleteLink(link.id);
});
test("with slash", async () => {
- const url = "https://www.checklyhq.com/";
+ const response = await fetch(`${h.baseUrl}/checkly/check`, fetchOptions);
- const { data: link } = await http.post<LinkWithShortLink>({
- path: "/links",
- query: { workspaceId },
- body: {
- domain,
- url,
- prefix: "check",
- },
- });
-
- const response = await fetch(`${h.baseUrl}/${link.key}`, fetchOptions);
-
- expect(response.headers.get("location")).toBe(url);
+ expect(response.headers.get("location")).toBe("https://www.checklyhq.com/");
expect(response.headers.get("x-powered-by")).toBe(poweredBy);
expect(response.status).toBe(302);
-
- await h.deleteLink(link.id);
});
test("with passthrough query", async () => {
- const url =
- "https://www.checklyhq.com/?utm_source=checkly&utm_medium=social&utm_campaign=checks";
-
- const { data: link } = await http.post<LinkWithShortLink>({
- path: "/links",
- query: { workspaceId },
- body: {
- domain,
- url,
- },
- });
-
- const response = await fetch(`${h.baseUrl}/${link.key}`, fetchOptions);
+ const response = await fetch(
+ `${h.baseUrl}/checkly-check-passthrough?utm_source=checkly`,
+ fetchOptions,
+ );
- expect(response.headers.get("location")).toBe(url);
+ expect(response.headers.get("location")).toBe(
+ "https://www.checklyhq.com/?utm_source=checkly&utm_medium=social&utm_campaign=checks",
+ );
expect(response.headers.get("x-powered-by")).toBe(poweredBy);
expect(response.status).toBe(302);
-
- await h.deleteLink(link.id);
});
test("with complex query", async () => {
- const url =
- "https://guides.apple.com/?ug=CglEVUIgR3VpZGUSDgjZMhDEo%2BGA%2BZKqpJUBEg4I2TIQw7y33%2B%2B6ifL%2BARIOCNkyEJC988jqgIrQjQESDgjZMhCB%2B7XSiPTwrfUBEg4I2TIQ5J25xZOynPDxARINCNkyENuVr4POz8aMcBIOCMI7EK36pfjQuerJ0gESDQjCOxDSuurnjM6T7mASDQjCOxD3vr%2F%2Fkq%2FLqUwSDQjCOxCg9cK%2BjeOhnS4%3D";
-
- const { data: link } = await http.post<LinkWithShortLink>({
- path: "/links",
- query: { workspaceId },
- body: {
- domain,
- url,
- },
- });
-
- const response = await fetch(`${h.baseUrl}/${link.key}`, fetchOptions);
+ const response = await fetch(
+ `${h.baseUrl}/checkly-check-query`,
+ fetchOptions,
+ );
- expect(response.headers.get("location")).toBe(url);
+ expect(response.headers.get("location")).toBe(
+ "https://guides.apple.com/?ug=CglEVUIgR3VpZGUSDgjZMhDEo%2BGA%2BZKqpJUBEg4I2TIQw7y33%2B%2B6ifL%2BARIOCNkyEJC988jqgIrQjQESDgjZMhCB%2B7XSiPTwrfUBEg4I2TIQ5J25xZOynPDxARINCNkyENuVr4POz8aMcBIOCMI7EK36pfjQuerJ0gESDQjCOxDSuurnjM6T7mASDQjCOxD3vr%2F%2Fkq%2FLqUwSDQjCOxCg9cK%2BjeOhnS4%3D",
+ );
expect(response.headers.get("x-powered-by")).toBe(poweredBy);
expect(response.status).toBe(302);
-
- await h.deleteLink(link.id);
});
test("with password", async () => {
- const url = "https://www.checklyhq.com/";
-
- const { data: link } = await http.post<LinkWithShortLink>({
- path: "/links",
- query: { workspaceId },
- body: {
- domain,
- url,
- password: "dub",
- },
- });
-
const response = await fetch(
- `${h.baseUrl}/${link.key}?pw=dub`,
+ `${h.baseUrl}/password/check?pw=dub`,
fetchOptions,
);
- expect(response.headers.get("location")).toBe(url);
+ expect(response.headers.get("location")).toBe("https://dub.co/");
expect(response.headers.get("x-powered-by")).toBe(poweredBy);
expect(response.status).toBe(302);
-
- await h.deleteLink(link.id);
});
});