-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.test.ts
More file actions
104 lines (87 loc) · 4.14 KB
/
bot.test.ts
File metadata and controls
104 lines (87 loc) · 4.14 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { describe, test, expect } from "bun:test";
import {
formatChannelInfo,
formatChannelRequirements,
allRequirementsPassed,
type ChannelRequirements,
} from "../src/utils";
describe("Utility Functions", () => {
test("should format channel info with title", () => {
const channelId = "-1001234567890";
const channelTitle = "Test Channel";
const formatted = formatChannelInfo(channelId, channelTitle);
expect(formatted.text).toBe("Test Channel (-1001234567890)");
expect(formatted.entities).toEqual([
{ type: "code", offset: 14, length: 14 },
]);
});
test("should format channel info without title", () => {
const channelId = "-1001234567890";
const formatted = formatChannelInfo(channelId);
expect(formatted.text).toBe("-1001234567890");
expect(formatted.entities).toEqual([{ type: "code", offset: 0, length: 14 }]);
});
test("should handle empty title", () => {
const channelId = "-1001234567890";
const channelTitle = "";
const formatted = formatChannelInfo(channelId, channelTitle);
expect(formatted.text).toBe("-1001234567890");
expect(formatted.entities).toEqual([{ type: "code", offset: 0, length: 14 }]);
});
test("should format channel requirements with all checks passed", () => {
const requirements: ChannelRequirements = {
channelExists: true,
botIsAdded: true,
botCanPost: true,
foreignAgentBlurbConfigured: true,
};
const formatted = formatChannelRequirements(requirements);
expect(formatted).toContain("✅ Настроенный канал существует");
expect(formatted).toContain("✅ 🤖 Бот добавлен в канал");
expect(formatted).toContain("✅ 🤖 Бот может публиковать сообщения в канал");
expect(formatted).toContain("✅ 🌍 Текст иностранного агента настроен");
});
test("should format channel requirements with all checks failed", () => {
const requirements: ChannelRequirements = {
channelExists: false,
botIsAdded: false,
botCanPost: false,
foreignAgentBlurbConfigured: false,
};
const formatted = formatChannelRequirements(requirements);
expect(formatted).toContain("❌ Канал не существует или бот не может получить к нему доступ");
expect(formatted).toContain("❌ 🤖 Бот не добавлен в канал");
expect(formatted).toContain("❌ 🤖 Бот не имеет разрешения публиковать сообщения");
expect(formatted).toContain("❌ 🌍 Текст иностранного агента не настроен");
});
test("should return true when all requirements are passed", () => {
const requirements: ChannelRequirements = {
channelExists: true,
botIsAdded: true,
botCanPost: true,
foreignAgentBlurbConfigured: true,
};
expect(allRequirementsPassed(requirements)).toBe(true);
});
test("should return false when foreign agent blurb is not configured", () => {
const requirements: ChannelRequirements = {
channelExists: true,
botIsAdded: true,
botCanPost: true,
foreignAgentBlurbConfigured: false,
};
expect(allRequirementsPassed(requirements)).toBe(false);
});
test("should return false when any requirement fails", () => {
const requirements: ChannelRequirements = {
channelExists: false,
botIsAdded: true,
botCanPost: true,
foreignAgentBlurbConfigured: true,
};
expect(allRequirementsPassed(requirements)).toBe(false);
});
});
// Note: Testing the resolveChannel and checkChannelRequirements functions requires mocking the Telegram API
// which is beyond the scope of basic unit tests. Integration tests would be
// needed to test the full channel resolution flow.