Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions packages/blink/src/cli/setup-slack-app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from "./lib/in-memory-cli";
import { makeTmpDir } from "./lib/terminal";
import {
appendSubpath,
setupSlackApp,
updateEnvCredentials,
verifySlackSignature,
Expand Down Expand Up @@ -111,6 +112,44 @@ describe("verifySlackSignature", () => {
});
});

describe("appendSubpath", () => {
it("should append a subpath to a simple URL", () => {
expect(appendSubpath("https://example.com", "/slack")).toBe(
"https://example.com/slack"
);
});

it("should append a subpath to a URL with an existing path", () => {
expect(appendSubpath("https://example.com/devhook/abc", "/slack")).toBe(
"https://example.com/devhook/abc/slack"
);
});

it("should handle trailing slashes on the base URL", () => {
expect(appendSubpath("https://example.com/devhook/", "/slack")).toBe(
"https://example.com/devhook/slack"
);
});

it("should handle subpath without leading slash", () => {
expect(appendSubpath("https://example.com/devhook", "slack")).toBe(
"https://example.com/devhook/slack"
);
});

it("should handle both trailing and leading slashes", () => {
expect(appendSubpath("https://example.com/devhook///", "///slack")).toBe(
"https://example.com/devhook/slack"
);
});

it("should preserve query parameters", () => {
expect(
appendSubpath("https://example.com/devhook?token=abc", "/slack")
).toBe("https://example.com/devhook/slack?token=abc");
});
});

describe("updateEnvCredentials", () => {
it("should add credentials to an empty env file", async () => {
await using tempDir = await makeTmpDir();
Expand Down
11 changes: 10 additions & 1 deletion packages/blink/src/cli/setup-slack-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ export function verifySlackSignature(
);
}

export function appendSubpath(baseUrl: string, subpath: string): string {
const url = new URL(baseUrl);
url.pathname = `${url.pathname.replace(/\/+$/, "")}/${subpath.replace(/^\/+/, "")}`;
return url.toString();
}

const makeDisposable = (value: unknown): Disposable => {
if (!(typeof value === "object" && value !== null)) {
throw new Error("Unable to make value disposable, it's not an object");
Expand Down Expand Up @@ -234,7 +240,10 @@ export async function setupSlackApp(
baseURL: host,
authToken: getAuthToken(),
});
const webhookUrl = await client.devhook.getUrl(devhookId);
const webhookUrl = appendSubpath(
await client.devhook.getUrl(devhookId),
"/slack"
);

log.info("Starting webhook listener...");

Expand Down