feat: add gmail hooks wizard
This commit is contained in:
63
src/hooks/gmail.test.ts
Normal file
63
src/hooks/gmail.test.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { ClawdisConfig } from "../config/config.js";
|
||||
import {
|
||||
buildDefaultHookUrl,
|
||||
buildTopicPath,
|
||||
parseTopicPath,
|
||||
resolveGmailHookRuntimeConfig,
|
||||
} from "./gmail.js";
|
||||
|
||||
const baseConfig = {
|
||||
hooks: {
|
||||
token: "hook-token",
|
||||
gmail: {
|
||||
account: "clawdbot@gmail.com",
|
||||
topic: "projects/demo/topics/gog-gmail-watch",
|
||||
pushToken: "push-token",
|
||||
},
|
||||
},
|
||||
} satisfies ClawdisConfig;
|
||||
|
||||
describe("gmail hook config", () => {
|
||||
it("builds default hook url", () => {
|
||||
expect(buildDefaultHookUrl("/hooks")).toBe(
|
||||
"http://127.0.0.1:18789/hooks/gmail",
|
||||
);
|
||||
});
|
||||
|
||||
it("parses topic path", () => {
|
||||
const topic = buildTopicPath("proj", "topic");
|
||||
expect(parseTopicPath(topic)).toEqual({
|
||||
projectId: "proj",
|
||||
topicName: "topic",
|
||||
});
|
||||
});
|
||||
|
||||
it("resolves runtime config with defaults", () => {
|
||||
const result = resolveGmailHookRuntimeConfig(baseConfig, {});
|
||||
expect(result.ok).toBe(true);
|
||||
if (result.ok) {
|
||||
expect(result.value.account).toBe("clawdbot@gmail.com");
|
||||
expect(result.value.label).toBe("INBOX");
|
||||
expect(result.value.includeBody).toBe(true);
|
||||
expect(result.value.serve.port).toBe(8788);
|
||||
expect(result.value.hookUrl).toBe("http://127.0.0.1:18789/hooks/gmail");
|
||||
}
|
||||
});
|
||||
|
||||
it("fails without hook token", () => {
|
||||
const result = resolveGmailHookRuntimeConfig(
|
||||
{
|
||||
hooks: {
|
||||
gmail: {
|
||||
account: "clawdbot@gmail.com",
|
||||
topic: "projects/demo/topics/gog-gmail-watch",
|
||||
pushToken: "push-token",
|
||||
},
|
||||
},
|
||||
},
|
||||
{},
|
||||
);
|
||||
expect(result.ok).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user