test(lint): reduce warning debt in selected test suites
This commit is contained in:
@@ -31,6 +31,22 @@ const baseConfig: TelegramAdapterConfig = {
|
||||
describe('TelegramAdapter', () => {
|
||||
let adapter: TelegramAdapter;
|
||||
|
||||
function getOnHandler(event: string) {
|
||||
const call = mockOn.mock.calls.find((entry) => entry[0] === event);
|
||||
if (!call) {
|
||||
throw new Error(`Missing on-handler for event: ${event}`);
|
||||
}
|
||||
return call[1] as (ctx: unknown) => Promise<void>;
|
||||
}
|
||||
|
||||
function getCommandHandler(command: string) {
|
||||
const call = mockCommand.mock.calls.find((entry) => entry[0] === command);
|
||||
if (!call) {
|
||||
throw new Error(`Missing command handler: ${command}`);
|
||||
}
|
||||
return call[1] as (ctx: unknown) => Promise<void>;
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
adapter = new TelegramAdapter(baseConfig);
|
||||
@@ -153,7 +169,7 @@ describe('TelegramAdapter', () => {
|
||||
);
|
||||
expect(textHandlerCall).toBeDefined();
|
||||
|
||||
const textHandler = textHandlerCall![1];
|
||||
const textHandler = getOnHandler('message:text');
|
||||
|
||||
// Simulate a grammy context object
|
||||
const ctx = {
|
||||
@@ -179,11 +195,7 @@ describe('TelegramAdapter', () => {
|
||||
it('text handler does nothing when no message handler is registered', async () => {
|
||||
// Don't call onMessage — no handler
|
||||
await adapter.connect();
|
||||
|
||||
const textHandlerCall = mockOn.mock.calls.find(
|
||||
(call) => call[0] === 'message:text',
|
||||
);
|
||||
const textHandler = textHandlerCall![1];
|
||||
const textHandler = getOnHandler('message:text');
|
||||
|
||||
const ctx = {
|
||||
message: { message_id: 1, text: 'test' },
|
||||
@@ -209,7 +221,7 @@ describe('TelegramAdapter', () => {
|
||||
const resetCall = mockCommand.mock.calls.find((call) => call[0] === 'reset');
|
||||
expect(resetCall).toBeDefined();
|
||||
|
||||
const resetHandler = resetCall![1];
|
||||
const resetHandler = getCommandHandler('reset');
|
||||
|
||||
const ctx = {
|
||||
message: { message_id: 99 },
|
||||
@@ -237,7 +249,7 @@ describe('TelegramAdapter', () => {
|
||||
// Find the /model command handler
|
||||
const modelCall = mockCommand.mock.calls.find((call) => call[0] === 'model');
|
||||
expect(modelCall).toBeDefined();
|
||||
const modelHandler = modelCall![1];
|
||||
const modelHandler = getCommandHandler('model');
|
||||
|
||||
const ctx = {
|
||||
message: { message_id: 123, text: '/model@flynn_bot default github/gpt-5-mini' },
|
||||
@@ -298,10 +310,7 @@ describe('TelegramAdapter', () => {
|
||||
const startCall = mockStart.mock.calls[0][0];
|
||||
startCall.onStart({ id: 12345, username: 'flynn_bot' });
|
||||
|
||||
const textHandlerCall = mockOn.mock.calls.find(
|
||||
(call) => call[0] === 'message:text',
|
||||
);
|
||||
const textHandler = textHandlerCall![1];
|
||||
const textHandler = getOnHandler('message:text');
|
||||
|
||||
const ctx = {
|
||||
message: { message_id: 42, text: 'Hello everyone', reply_to_message: undefined },
|
||||
@@ -326,10 +335,7 @@ describe('TelegramAdapter', () => {
|
||||
const startCall = mockStart.mock.calls[0][0];
|
||||
startCall.onStart({ id: 12345, username: 'flynn_bot' });
|
||||
|
||||
const textHandlerCall = mockOn.mock.calls.find(
|
||||
(call) => call[0] === 'message:text',
|
||||
);
|
||||
const textHandler = textHandlerCall![1];
|
||||
const textHandler = getOnHandler('message:text');
|
||||
|
||||
const ctx = {
|
||||
message: { message_id: 42, text: '@flynn_bot What is the weather?', reply_to_message: undefined },
|
||||
@@ -355,10 +361,7 @@ describe('TelegramAdapter', () => {
|
||||
const startCall = mockStart.mock.calls[0][0];
|
||||
startCall.onStart({ id: 12345, username: 'flynn_bot' });
|
||||
|
||||
const textHandlerCall = mockOn.mock.calls.find(
|
||||
(call) => call[0] === 'message:text',
|
||||
);
|
||||
const textHandler = textHandlerCall![1];
|
||||
const textHandler = getOnHandler('message:text');
|
||||
|
||||
const ctx = {
|
||||
message: {
|
||||
@@ -392,10 +395,7 @@ describe('TelegramAdapter', () => {
|
||||
const startCall = mockStart.mock.calls[0][0];
|
||||
startCall.onStart({ id: 12345, username: 'flynn_bot' });
|
||||
|
||||
const textHandlerCall = mockOn.mock.calls.find(
|
||||
(call) => call[0] === 'message:text',
|
||||
);
|
||||
const textHandler = textHandlerCall![1];
|
||||
const textHandler = getOnHandler('message:text');
|
||||
|
||||
const ctx = {
|
||||
message: { message_id: 42, text: 'Hello everyone', reply_to_message: undefined },
|
||||
@@ -421,10 +421,7 @@ describe('TelegramAdapter', () => {
|
||||
const startCall = mockStart.mock.calls[0][0];
|
||||
startCall.onStart({ id: 12345, username: 'flynn_bot' });
|
||||
|
||||
const textHandlerCall = mockOn.mock.calls.find(
|
||||
(call) => call[0] === 'message:text',
|
||||
);
|
||||
const textHandler = textHandlerCall![1];
|
||||
const textHandler = getOnHandler('message:text');
|
||||
|
||||
const ctx = {
|
||||
message: { message_id: 42, text: 'Hello Flynn', reply_to_message: undefined },
|
||||
@@ -450,10 +447,7 @@ describe('TelegramAdapter', () => {
|
||||
const startCall = mockStart.mock.calls[0][0];
|
||||
startCall.onStart({ id: 12345, username: 'flynn_bot' });
|
||||
|
||||
const textHandlerCall = mockOn.mock.calls.find(
|
||||
(call) => call[0] === 'message:text',
|
||||
);
|
||||
const textHandler = textHandlerCall![1];
|
||||
const textHandler = getOnHandler('message:text');
|
||||
|
||||
const ctx = {
|
||||
message: { message_id: 42, text: '@flynn_bot tell me a joke', reply_to_message: undefined },
|
||||
|
||||
Reference in New Issue
Block a user