Skip to content

Commit

Permalink
Merge branch 'main' into e2e-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-tey authored Apr 24, 2024
2 parents eac33ea + 21d919e commit 89dbfd9
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Run tests
working-directory: apps/web
env:
E2E_API_BASE_URL: ${{ github.event.deployment_status.environment_url }}/api
E2E_BASE_URL: ${{ github.event.deployment_status.environment_url }}
E2E_TOKEN: ${{ secrets.E2E_TOKEN }}
E2E_USER_ID: ${{ secrets.E2E_USER_ID }}
E2E_WORKSPACE_ID: ${{ secrets.E2E_WORKSPACE_ID }}
Expand Down
6 changes: 1 addition & 5 deletions apps/web/tests/metatags/retrieve-metatags.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { MetaTag } from "@/lib/types";
import { expect, test } from "vitest";
import { HttpClient } from "../utils/http";
import { IntegrationHarness } from "../utils/integration";

test("GET /metatags", async (ctx) => {
const h = new IntegrationHarness(ctx);

const http = new HttpClient({
baseUrl: h.baseUrl,
});
const { http } = await h.init();

const { status, data: metatags } = await http.get<MetaTag>({
path: `/metatags`,
Expand Down
76 changes: 76 additions & 0 deletions apps/web/tests/redirects/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { describe, expect, test } from "vitest";
import { IntegrationHarness } from "../utils/integration";

const poweredBy = "Dub.co - Link management for modern marketing teams";
const fetchOptions: RequestInit = {
cache: "no-store",
redirect: "manual",
headers: {
"dub-no-track": "true",
},
};

describe.sequential("Link Redirects", async () => {
const h = new IntegrationHarness();

test("root", async () => {
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);
expect(response.status).toBe(301);
});

test("regular", async () => {
const response = await fetch(`${h.baseUrl}/checkly-check`, fetchOptions);

expect(response.headers.get("location")).toBe("https://www.checklyhq.com/");
expect(response.headers.get("x-powered-by")).toBe(poweredBy);
expect(response.status).toBe(302);
});

test("with slash", async () => {
const response = await fetch(`${h.baseUrl}/checkly/check`, fetchOptions);

expect(response.headers.get("location")).toBe("https://www.checklyhq.com/");
expect(response.headers.get("x-powered-by")).toBe(poweredBy);
expect(response.status).toBe(302);
});

test("with passthrough query", async () => {
const response = await fetch(
`${h.baseUrl}/checkly-check-passthrough?utm_source=checkly`,
fetchOptions,
);

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);
});

test("with complex query", async () => {
const response = await fetch(
`${h.baseUrl}/checkly-check-query`,
fetchOptions,
);

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);
});

test("with password", async () => {
const response = await fetch(
`${h.baseUrl}/password/check?pw=dub`,
fetchOptions,
);

expect(response.headers.get("location")).toBe("https://dub.co/");
expect(response.headers.get("x-powered-by")).toBe(poweredBy);
expect(response.status).toBe(302);
});
});
2 changes: 1 addition & 1 deletion apps/web/tests/utils/env.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from "zod";

export const integrationTestEnv = z.object({
E2E_API_BASE_URL: z.string().url().min(1),
E2E_BASE_URL: z.string().url().min(1),
E2E_TOKEN: z.string().min(1),
E2E_USER_ID: z.string().min(1),
E2E_WORKSPACE_ID: z.string().min(1),
Expand Down
4 changes: 2 additions & 2 deletions apps/web/tests/utils/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export class IntegrationHarness {
this.env = integrationTestEnv.parse(process.env);

this.ctx = ctx;
this.baseUrl = this.env.E2E_API_BASE_URL;
this.baseUrl = this.env.E2E_BASE_URL;
this.http = new HttpClient({
baseUrl: this.baseUrl,
baseUrl: `${this.baseUrl}/api`,
headers: {
Authorization: `Bearer ${this.env.E2E_TOKEN}`,
},
Expand Down

0 comments on commit 89dbfd9

Please sign in to comment.