the-tip-top-backend/test/integration/admin.test.js
soufiane 614abeb196 test: add comprehensive unit and integration tests
Backend Tests Added:
- Unit tests for helpers.js (tokens, validation, pagination)
- Unit tests for middleware (auth, errorHandler, validate)
- Integration tests for auth endpoints
- Integration tests for game endpoints
- Integration tests for admin endpoints
- Integration tests for employee endpoints
- Integration tests for draw endpoints
- Integration tests for newsletter/contact endpoints

Also added:
- cross-env for Windows compatibility
- Test scripts update

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 11:23:43 +01:00

161 lines
4.6 KiB
JavaScript

/**
* Tests d'intégration pour les endpoints admin
*/
import request from 'supertest';
import app from '../../index.js';
describe('Admin API', () => {
describe('GET /api/admin/statistics', () => {
it('should reject request without authentication', async () => {
const res = await request(app).get('/api/admin/statistics');
expect(res.statusCode).toBe(401);
expect(res.body.success).toBe(false);
});
it('should reject request with non-admin token', async () => {
const res = await request(app)
.get('/api/admin/statistics')
.set('Authorization', 'Bearer invalid-token');
expect(res.statusCode).toBe(401);
});
});
describe('Prize Management', () => {
describe('GET /api/admin/prizes', () => {
it('should reject request without authentication', async () => {
const res = await request(app).get('/api/admin/prizes');
expect(res.statusCode).toBe(401);
expect(res.body.success).toBe(false);
});
});
describe('POST /api/admin/prizes', () => {
it('should reject request without authentication', async () => {
const res = await request(app)
.post('/api/admin/prizes')
.send({
name: 'Test Prize',
type: 'INFUSEUR',
value: 10,
probability: 0.1,
stock: 100,
});
expect(res.statusCode).toBe(401);
});
});
describe('PUT /api/admin/prizes/:id', () => {
it('should reject request without authentication', async () => {
const res = await request(app)
.put('/api/admin/prizes/1')
.send({ name: 'Updated Prize' });
expect(res.statusCode).toBe(401);
});
});
describe('DELETE /api/admin/prizes/:id', () => {
it('should reject request without authentication', async () => {
const res = await request(app).delete('/api/admin/prizes/1');
expect(res.statusCode).toBe(401);
});
});
});
describe('User Management', () => {
describe('GET /api/admin/users', () => {
it('should reject request without authentication', async () => {
const res = await request(app).get('/api/admin/users');
expect(res.statusCode).toBe(401);
});
});
describe('GET /api/admin/users/:id', () => {
it('should reject request without authentication', async () => {
const res = await request(app).get('/api/admin/users/1');
expect(res.statusCode).toBe(401);
});
});
describe('POST /api/admin/employees', () => {
it('should reject request without authentication', async () => {
const res = await request(app)
.post('/api/admin/employees')
.send({
email: 'employee@example.com',
firstName: 'John',
lastName: 'Doe',
password: 'Password123!',
});
expect(res.statusCode).toBe(401);
});
});
describe('PUT /api/admin/users/:id', () => {
it('should reject request without authentication', async () => {
const res = await request(app)
.put('/api/admin/users/1')
.send({ role: 'EMPLOYEE' });
expect(res.statusCode).toBe(401);
});
});
describe('DELETE /api/admin/users/:id', () => {
it('should reject request without authentication', async () => {
const res = await request(app).delete('/api/admin/users/1');
expect(res.statusCode).toBe(401);
});
});
});
describe('Ticket Management', () => {
describe('GET /api/admin/tickets', () => {
it('should reject request without authentication', async () => {
const res = await request(app).get('/api/admin/tickets');
expect(res.statusCode).toBe(401);
});
});
describe('POST /api/admin/generate-tickets', () => {
it('should reject request without authentication', async () => {
const res = await request(app)
.post('/api/admin/generate-tickets')
.send({ count: 100 });
expect(res.statusCode).toBe(401);
});
});
});
describe('Marketing', () => {
describe('GET /api/admin/marketing/stats', () => {
it('should reject request without authentication', async () => {
const res = await request(app).get('/api/admin/marketing/stats');
expect(res.statusCode).toBe(401);
});
});
describe('POST /api/admin/marketing/export', () => {
it('should reject request without authentication', async () => {
const res = await request(app)
.post('/api/admin/marketing/export')
.send({ segment: 'winners' });
expect(res.statusCode).toBe(401);
});
});
});
});