Some checks failed
Deploy / deploy (push) Has been cancelled
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>
Testing Guide
This directory contains all tests for the Telegram Marketing Agent System.
Test Structure
tests/
├── unit/ # Unit tests for individual components
│ ├── services/ # Service-specific unit tests
│ ├── utils/ # Utility function tests
│ └── middleware/ # Middleware tests
├── integration/ # Integration tests
│ ├── api/ # API endpoint tests
│ ├── services/ # Service integration tests
│ └── workflows/ # End-to-end workflow tests
├── e2e/ # End-to-end tests
│ ├── campaigns/ # Campaign workflow tests
│ └── users/ # User management tests
├── fixtures/ # Test data and mocks
├── helpers/ # Test utilities
└── config/ # Test configuration
Running Tests
All Tests
npm test
Unit Tests Only
npm run test:unit
Integration Tests Only
npm run test:integration
End-to-End Tests
npm run test:e2e
Watch Mode
npm run test:watch
Coverage Report
npm run test:coverage
Test Framework
We use the following testing stack:
- Jest: Main testing framework
- Supertest: API endpoint testing
- MongoDB Memory Server: In-memory MongoDB for tests
- Redis Mock: Redis mocking for tests
- Sinon: Mocking and stubbing
- Faker: Test data generation
Writing Tests
Unit Test Example
describe('CampaignService', () => {
describe('createCampaign', () => {
it('should create a new campaign', async () => {
const campaignData = {
name: 'Test Campaign',
type: 'message'
};
const result = await campaignService.createCampaign(campaignData);
expect(result).toHaveProperty('id');
expect(result.name).toBe(campaignData.name);
});
});
});
Integration Test Example
describe('POST /api/v1/campaigns', () => {
it('should create a campaign', async () => {
const response = await request(app)
.post('/api/v1/campaigns')
.set('Authorization', `Bearer ${token}`)
.send({
name: 'Test Campaign',
type: 'message'
});
expect(response.status).toBe(201);
expect(response.body.success).toBe(true);
});
});
Test Coverage Goals
- Unit Tests: >80% coverage
- Integration Tests: All critical paths
- E2E Tests: Main user workflows
CI/CD Integration
Tests are automatically run on:
- Pull requests
- Commits to main branch
- Before deployment
Best Practices
- Isolation: Each test should be independent
- Cleanup: Always clean up test data
- Mocking: Mock external dependencies
- Descriptive: Use clear test descriptions
- Fast: Keep tests fast and focused
- Deterministic: Tests should always produce same results