Files
telegram-management-system/marketing-agent/tests/setup.js
你的用户名 237c7802e5
Some checks failed
Deploy / deploy (push) Has been cancelled
Initial commit: Telegram Management System
Full-stack web application for Telegram management
- Frontend: Vue 3 + Vben Admin
- Backend: NestJS
- Features: User management, group broadcast, statistics

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 15:37:50 +08:00

56 lines
1.2 KiB
JavaScript

// Global test setup
import { jest } from '@jest/globals';
// Set test environment
process.env.NODE_ENV = 'test';
process.env.JWT_SECRET = 'test-jwt-secret';
process.env.MONGODB_URI = 'mongodb://localhost:27017/test';
process.env.REDIS_URL = 'redis://localhost:6379';
// Mock console methods to reduce noise
global.console = {
...console,
log: jest.fn(),
debug: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
};
// Set test timeout
jest.setTimeout(30000);
// Clean up after tests
afterAll(async () => {
// Close database connections
const mongoose = await import('mongoose');
await mongoose.connection.close();
// Close Redis connections
// Add any other cleanup needed
});
// Global test utilities
global.testUtils = {
generateToken: (userId) => {
const jwt = require('jsonwebtoken');
return jwt.sign({ userId }, process.env.JWT_SECRET, { expiresIn: '1h' });
},
createMockRequest: (options = {}) => ({
headers: {},
params: {},
query: {},
body: {},
...options
}),
createMockResponse: () => {
const res = {};
res.status = jest.fn(() => res);
res.json = jest.fn(() => res);
res.send = jest.fn(() => res);
res.set = jest.fn(() => res);
return res;
}
};