-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot-commands.test.ts
More file actions
83 lines (76 loc) · 3.1 KB
/
bot-commands.test.ts
File metadata and controls
83 lines (76 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// src/__tests__/bot-commands.test.ts
import { describe, it, expect } from "vitest";
import { createdMessage, launchMessage, normalizeTelegramCommandText, parseCommand } from "../bot/commands.js";
import { previewReadyMessage } from "../bot/i18n.js";
describe("parseCommand", () => {
it("parses /start", () => {
expect(parseCommand("/start")).toEqual({ tag: "start" });
});
it("parses /help", () => {
expect(parseCommand("/help")).toEqual({ tag: "help" });
});
it("parses /new with title", () => {
expect(parseCommand("/new My App")).toEqual({ tag: "new", title: "My App" });
});
it("parses /new without title", () => {
expect(parseCommand("/new")).toEqual({ tag: "new", title: "SpawnDock App" });
});
it("parses /launch with slug", () => {
expect(parseCommand("/launch my-app")).toEqual({ tag: "launch", slug: "my-app" });
});
it("rejects /launch without slug", () => {
expect(parseCommand("/launch").tag).toBe("launch-missing");
});
it("parses /getToken", () => {
expect(parseCommand("/getToken")).toEqual({ tag: "get-token" });
});
it("parses /getToken with Telegram @bot suffix", () => {
expect(parseCommand("/getToken@TMASpawnerBot")).toEqual({ tag: "get-token" });
});
it("normalizes command @ suffix and preserves args for /new", () => {
expect(normalizeTelegramCommandText("/new My App@nope")).toBe("/new My App@nope");
expect(normalizeTelegramCommandText("/new@bot Title")).toBe("/new Title");
});
it("returns unknown for random text", () => {
expect(parseCommand("hello").tag).toBe("unknown");
});
});
describe("bot messages", () => {
it("createdMessage uses English bootstrap copy", () => {
const message = createdMessage(
"demo-app",
"npx -y @spawn-dock/create --token pair_demo",
);
expect(message).toContain("Project demo-app created.");
expect(message).toContain("1. Run the bootstrap command locally:");
expect(message).toContain("npx -y @spawn-dock/create --token pair_demo");
expect(message).toContain("2. After bootstrap, run:");
expect(message).toContain("pnpm run dev");
expect(message).not.toContain("Links:");
});
it("includes TMA, preview, and telegram links in launchMessage", () => {
const message = launchMessage(
"demo-app",
"connected",
"https://example.com/tma?tgWebAppStartParam=demo-app",
"https://example.com/preview/demo-app",
"https://t.me/rustgpt_bot/tma?startapp=demo-app",
);
expect(message).toContain("TMA URL:");
expect(message).toContain("Telegram Link:");
expect(message).toContain("Preview URL:");
expect(message).toContain("Tunnel status:");
expect(message).toContain("<code>npm run agent</code>");
});
it("previewReadyMessage keeps all links", () => {
const message = previewReadyMessage(
"demo-app",
"https://example.com/preview/demo-app",
"https://t.me/rustgpt_bot/tma?startapp=demo-app",
"https://example.com/tma?tgWebAppStartParam=demo-app",
);
expect(message).toContain("Preview URL:");
expect(message).toContain("Telegram Link:");
expect(message).toContain("TMA URL:");
});
});