Skip to content

Commit 6c578bc

Browse files
committed
Refactor test imports and mocks to new bot directory
All test files under bot/__tests__ have been moved to the root __tests__ directory and updated to import modules from the new bot/ subdirectory. All relative import and jest.doMock paths now reference bot/ to match the new structure. This improves project organization and clarifies module boundaries.
1 parent ca7054c commit 6c578bc

25 files changed

+283
-276
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI Pipeline
1+
name: CI/CD Pipeline
22

33
on:
44
push:
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ test("requiring bot index does not crash when Telegraf is mocked", () => {
2424

2525
jest.doMock("telegraf", () => ({ Telegraf: MockTelegraf }));
2626
// mock the same module id that index.js requires
27-
jest.doMock("../../bot/config/config", () => ({
27+
jest.doMock("../bot/config/config", () => ({
2828
TELEGRAM_BOT_TOKEN: "x",
2929
PORT: 3000,
3030
}));
3131
// avoid starting an express server or scheduling jobs
32-
jest.doMock("../../bot/server", () => ({ startServer: jest.fn() }));
33-
jest.doMock("../../bot/utils/scheduleMessage", () => ({
32+
jest.doMock("../bot/server", () => ({ startServer: jest.fn() }));
33+
jest.doMock("../bot/utils/scheduleMessage", () => ({
3434
scheduleAdminMessage: jest.fn(),
3535
}));
36-
jest.doMock("../../bot/commands/registerCommands", () => jest.fn());
36+
jest.doMock("../bot/commands/registerCommands", () => jest.fn());
3737

3838
// require the bot module directly to avoid executing the top-level launcher in index.js
39-
const mod = require("../../bot");
39+
const mod = require("../bot");
4040
expect(mod.bot).toBeDefined();
4141
});
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ describe("addIDCommand (isolated)", () => {
1212
const mockSendReaction = jest.fn();
1313
const mockIsAdminTalking = jest.fn();
1414

15-
jest.doMock("../../config/config", () => ({
15+
jest.doMock("../../bot/config/config", () => ({
1616
ADMIN_GROUP_ID: "-100123",
1717
blockedUsers: new Set(),
1818
userMessageCounts: new Map(),
1919
}));
20-
jest.doMock("../../utils/groupValidator", () => ({
20+
jest.doMock("../../bot/utils/groupValidator", () => ({
2121
groupValidator: () => false,
2222
}));
23-
jest.doMock("../../utils/sendReaction", () => ({
23+
jest.doMock("../../bot/utils/sendReaction", () => ({
2424
sendReaction: mockSendReaction,
2525
}));
26-
jest.doMock("../../utils/adminChecker", () => ({
26+
jest.doMock("../../bot/utils/adminChecker", () => ({
2727
isAdminTalking: mockIsAdminTalking,
2828
}));
29-
jest.doMock("../../services/azure", () => ({
29+
jest.doMock("../../bot/services/azure", () => ({
3030
createWorkItem: mockCreateWorkItem,
3131
}));
3232

33-
const { addIDCommand } = require("../../commands/addID");
33+
const { addIDCommand } = require("../../bot/commands/addID");
3434

3535
const ctx = { chat: { id: 1 }, message: {}, reply: jest.fn() };
3636
await addIDCommand(ctx);
@@ -45,25 +45,25 @@ describe("addIDCommand (isolated)", () => {
4545
const mockSendReaction = jest.fn();
4646
const mockIsAdminTalking = jest.fn().mockResolvedValue(false);
4747

48-
jest.doMock("../../config/config", () => ({
48+
jest.doMock("../../bot/config/config", () => ({
4949
ADMIN_GROUP_ID: "-100123",
5050
blockedUsers: new Set(),
5151
userMessageCounts: new Map(),
5252
}));
53-
jest.doMock("../../utils/groupValidator", () => ({
53+
jest.doMock("../../bot/utils/groupValidator", () => ({
5454
groupValidator: () => true,
5555
}));
56-
jest.doMock("../../utils/sendReaction", () => ({
56+
jest.doMock("../../bot/utils/sendReaction", () => ({
5757
sendReaction: mockSendReaction,
5858
}));
59-
jest.doMock("../../utils/adminChecker", () => ({
59+
jest.doMock("../../bot/utils/adminChecker", () => ({
6060
isAdminTalking: mockIsAdminTalking,
6161
}));
62-
jest.doMock("../../services/azure", () => ({
62+
jest.doMock("../../bot/services/azure", () => ({
6363
createWorkItem: mockCreateWorkItem,
6464
}));
6565

66-
const { addIDCommand } = require("../../commands/addID");
66+
const { addIDCommand } = require("../../bot/commands/addID");
6767
const ctx = { chat: { id: 1 }, message: {}, reply: jest.fn() };
6868

6969
await addIDCommand(ctx);
@@ -79,25 +79,25 @@ describe("addIDCommand (isolated)", () => {
7979
const mockSendReaction = jest.fn();
8080
const mockIsAdminTalking = jest.fn().mockResolvedValue(true);
8181

82-
jest.doMock("../../config/config", () => ({
82+
jest.doMock("../../bot/config/config", () => ({
8383
ADMIN_GROUP_ID: "-100123",
8484
blockedUsers: new Set(),
8585
userMessageCounts: new Map(),
8686
}));
87-
jest.doMock("../../utils/groupValidator", () => ({
87+
jest.doMock("../../bot/utils/groupValidator", () => ({
8888
groupValidator: () => true,
8989
}));
90-
jest.doMock("../../utils/sendReaction", () => ({
90+
jest.doMock("../../bot/utils/sendReaction", () => ({
9191
sendReaction: mockSendReaction,
9292
}));
93-
jest.doMock("../../utils/adminChecker", () => ({
93+
jest.doMock("../../bot/utils/adminChecker", () => ({
9494
isAdminTalking: mockIsAdminTalking,
9595
}));
96-
jest.doMock("../../services/azure", () => ({
96+
jest.doMock("../../bot/services/azure", () => ({
9797
createWorkItem: mockCreateWorkItem,
9898
}));
9999

100-
const { addIDCommand } = require("../../commands/addID");
100+
const { addIDCommand } = require("../../bot/commands/addID");
101101
const ctx = { chat: { id: 1 }, message: {}, reply: jest.fn() };
102102

103103
await addIDCommand(ctx);
@@ -113,25 +113,25 @@ describe("addIDCommand (isolated)", () => {
113113
const mockSendReaction = jest.fn();
114114
const mockIsAdminTalking = jest.fn().mockResolvedValue(true);
115115

116-
jest.doMock("../../config/config", () => ({
116+
jest.doMock("../../bot/config/config", () => ({
117117
ADMIN_GROUP_ID: "-100123",
118118
blockedUsers: new Set(),
119119
userMessageCounts: new Map(),
120120
}));
121-
jest.doMock("../../utils/groupValidator", () => ({
121+
jest.doMock("../../bot/utils/groupValidator", () => ({
122122
groupValidator: () => true,
123123
}));
124-
jest.doMock("../../utils/sendReaction", () => ({
124+
jest.doMock("../../bot/utils/sendReaction", () => ({
125125
sendReaction: mockSendReaction,
126126
}));
127-
jest.doMock("../../utils/adminChecker", () => ({
127+
jest.doMock("../../bot/utils/adminChecker", () => ({
128128
isAdminTalking: mockIsAdminTalking,
129129
}));
130-
jest.doMock("../../services/azure", () => ({
130+
jest.doMock("../../bot/services/azure", () => ({
131131
createWorkItem: mockCreateWorkItem,
132132
}));
133133

134-
const { addIDCommand } = require("../../commands/addID");
134+
const { addIDCommand } = require("../../bot/commands/addID");
135135
const repliedUser = { id: 555, username: "test" };
136136
const ctx = {
137137
chat: { id: 1 },
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ describe("aloha Command", () => {
55
});
66

77
test("returns early when groupValidator is false", async () => {
8-
jest.doMock("../../utils/groupValidator", () => ({
8+
jest.doMock("../../bot/utils/groupValidator", () => ({
99
groupValidator: () => false,
1010
}));
11-
const { alohaCommand } = require("../../commands/aloha");
11+
const { alohaCommand } = require("../../bot/commands/aloha");
1212

1313
const ctx = { message: { from: { username: "x" } }, reply: jest.fn() };
1414
await alohaCommand(ctx);
1515
expect(ctx.reply).not.toHaveBeenCalled();
1616
});
1717

1818
test("replies with username when present", async () => {
19-
jest.doMock("../../utils/groupValidator", () => ({
19+
jest.doMock("../../bot/utils/groupValidator", () => ({
2020
groupValidator: () => true,
2121
}));
22-
const { alohaCommand } = require("../../commands/aloha");
22+
const { alohaCommand } = require("../../bot/commands/aloha");
2323

2424
const ctx = {
2525
message: { from: { username: "alice", first_name: "Alice" } },
@@ -32,10 +32,10 @@ describe("aloha Command", () => {
3232
});
3333

3434
test("replies with first_name when username is empty", async () => {
35-
jest.doMock("../../utils/groupValidator", () => ({
35+
jest.doMock("../../bot/utils/groupValidator", () => ({
3636
groupValidator: () => true,
3737
}));
38-
const { alohaCommand } = require("../../commands/aloha");
38+
const { alohaCommand } = require("../../bot/commands/aloha");
3939

4040
const ctx = {
4141
message: { from: { username: "", first_name: "Bob" } },

0 commit comments

Comments
 (0)