Repository navigation
Add edge redirects for meeting links #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | ||||||||||||||||
| import { describe, expect, it, vi } from "vitest"; | ||||||||||||||||
|
|
||||||||||||||||
| import worker, { getVanityRedirect } from "../index.js"; | ||||||||||||||||
|
|
||||||||||||||||
| const redirects = [ | ||||||||||||||||
| ["/meet-with-will", "https://calendar.app.google/RqLuQyT3dYe5e2YdA"], | ||||||||||||||||
| ["/meet-with-khaliq", "https://calendly.com/khaliq-agent-relay/30min"], | ||||||||||||||||
| ["/virtual-office", "https://meet.google.com/ijx-gpfb-brt"], | ||||||||||||||||
| ] as const; | ||||||||||||||||
|
|
||||||||||||||||
| function buildCtx(): ExecutionContext { | ||||||||||||||||
| return { | ||||||||||||||||
| waitUntil: () => undefined, | ||||||||||||||||
| passThroughOnException: () => undefined, | ||||||||||||||||
| } as unknown as ExecutionContext; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| describe("router vanity redirects", () => { | ||||||||||||||||
| it.each(redirects)("redirects %s at the edge", async (path, destination) => { | ||||||||||||||||
| const cloudWebWorker = { fetch: vi.fn() }; | ||||||||||||||||
| const response = await worker.fetch( | ||||||||||||||||
| new Request(`https://agentrelay.com${path}?utm_source=test`), | ||||||||||||||||
| { | ||||||||||||||||
| CLOUD_APP_ORIGIN: "https://origin.test.invalid", | ||||||||||||||||
| CLOUD_WEB_WORKER: cloudWebWorker, | ||||||||||||||||
| }, | ||||||||||||||||
| buildCtx(), | ||||||||||||||||
| ); | ||||||||||||||||
|
|
||||||||||||||||
| expect(response.status).toBe(302); | ||||||||||||||||
| expect(response.headers.get("location")).toBe(destination); | ||||||||||||||||
| expect(cloudWebWorker.fetch).not.toHaveBeenCalled(); | ||||||||||||||||
| }); | ||||||||||||||||
|
Comment on lines
+19
to
+33
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the test to assert that query parameters (such as it.each(redirects)("redirects %s at the edge", async (path, destination) => {
const cloudWebWorker = { fetch: vi.fn() };
const response = await worker.fetch(
new Request("https://agentrelay.com" + path + "?utm_source=test"),
{
CLOUD_APP_ORIGIN: "https://origin.test.invalid",
CLOUD_WEB_WORKER: cloudWebWorker,
},
buildCtx(),
);
expect(response.status).toBe(302);
const expectedUrl = new URL(destination);
expectedUrl.searchParams.set("utm_source", "test");
expect(response.headers.get("location")).toBe(expectedUrl.toString());
expect(cloudWebWorker.fetch).not.toHaveBeenCalled();
}); |
||||||||||||||||
|
|
||||||||||||||||
| it.each(redirects)("accepts a trailing slash for %s", (path, destination) => { | ||||||||||||||||
| expect(getVanityRedirect("agentrelay.com", `${path}/`)).toBe(destination); | ||||||||||||||||
| }); | ||||||||||||||||
|
Comment on lines
+35
to
+37
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add test coverage for case-insensitivity to ensure that mixed-case or uppercase vanity URLs are correctly matched and redirected.
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| it("does not redirect another hostname or a nested path", () => { | ||||||||||||||||
| expect(getVanityRedirect("origin-web.agentrelay.com", "/meet-with-will")).toBeUndefined(); | ||||||||||||||||
| expect(getVanityRedirect("agentrelay.com", "/meet-with-will/details")).toBeUndefined(); | ||||||||||||||||
| }); | ||||||||||||||||
| }); | ||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2:
.toLowerCase()was added to enable case-insensitive vanity-route matching, but there doesn't appear to be a test exercising mixed-case or uppercase paths (e.g./Meet-With-Will). Adding a case-variant test case would prevent regressions if the normalization logic changes.Prompt for AI agents