Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions backend/test-bot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as dotenv from 'dotenv';
import * as path from 'path';
dotenv.config({ path: path.resolve(__dirname, '.env') });

import { TelegramBotService } from './src/services/telegram-bot.service';
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

async function testBot() {
console.log('Testing /start');
const startUpdate = {
message: {
chat: { id: 123456789 },
text: '/start 44925654-523c-43ed-9a41-3ebf014bbe8a'
}
};
await TelegramBotService.handleUpdate(startUpdate);
console.log('Testing /inbox');
const inboxUpdate = {
message: {
chat: { id: 123456789 },
text: '/inbox'
}
};
await TelegramBotService.handleUpdate(inboxUpdate);
}

testBot().catch(console.error).finally(() => prisma.$disconnect());
49 changes: 49 additions & 0 deletions backend/test-queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import * as dotenv from 'dotenv';
import * as path from 'path';
dotenv.config({ path: path.resolve(__dirname, '.env') });

import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();

async function testQueries() {
console.log('Testing /start logic...');
try {
const user = await prisma.user.findUnique({
where: { id: '44925654-523c-43ed-9a41-3ebf014bbe8a' },
});
console.log('User found:', user ? 'Yes' : 'No');

await prisma.userSettings.upsert({
where: { userId: '44925654-523c-43ed-9a41-3ebf014bbe8a' },
update: { telegramChatId: '123456789', telegramEnabled: true },
create: { userId: '44925654-523c-43ed-9a41-3ebf014bbe8a', theme: 'dark', telegramChatId: '123456789', telegramEnabled: true },
});
console.log('Upsert successful');
} catch (err: any) {
console.error('Error in /start logic:', err.message);
}

console.log('Testing /inbox logic...');
try {
const settings = await prisma.userSettings.findFirst({
where: { telegramChatId: '123456789', telegramEnabled: true },
});
console.log('Settings found:', settings ? 'Yes' : 'No');

if (settings) {
const actionItems = await prisma.actionItem.findMany({
where: {
isCompleted: false,
email: { userId: settings.userId },
},
include: { email: true },
orderBy: { createdAt: 'asc' },
});
console.log(`Action items found: ${actionItems.length}`);
}
} catch (err: any) {
console.error('Error in /inbox logic:', err.message);
}
}

testQueries().finally(() => prisma.$disconnect());
Loading