the-tip-top-backend/test/integration/employee.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

117 lines
3.4 KiB
JavaScript

/**
* Tests d'intégration pour les endpoints employé
*/
import request from 'supertest';
import app from '../../index.js';
describe('Employee API', () => {
describe('GET /api/employee/pending-tickets', () => {
it('should reject request without authentication', async () => {
const res = await request(app).get('/api/employee/pending-tickets');
expect(res.statusCode).toBe(401);
expect(res.body.success).toBe(false);
});
it('should reject request with invalid token', async () => {
const res = await request(app)
.get('/api/employee/pending-tickets')
.set('Authorization', 'Bearer invalid-token');
expect(res.statusCode).toBe(401);
});
});
describe('GET /api/employee/search-ticket', () => {
it('should reject request without authentication', async () => {
const res = await request(app)
.get('/api/employee/search-ticket')
.query({ code: 'TTP2025ABC' });
expect(res.statusCode).toBe(401);
});
it('should reject request without search query', async () => {
const res = await request(app)
.get('/api/employee/search-ticket')
.set('Authorization', 'Bearer invalid-token');
expect(res.statusCode).toBe(401);
});
});
describe('POST /api/employee/validate-ticket', () => {
it('should reject request without authentication', async () => {
const res = await request(app)
.post('/api/employee/validate-ticket')
.send({
ticketId: 1,
status: 'CLAIMED',
});
expect(res.statusCode).toBe(401);
});
it('should require ticketId and status', async () => {
const res = await request(app)
.post('/api/employee/validate-ticket')
.set('Authorization', 'Bearer invalid-token')
.send({});
expect(res.statusCode).toBe(401);
});
});
describe('GET /api/employee/stats', () => {
it('should reject request without authentication', async () => {
const res = await request(app).get('/api/employee/stats');
expect(res.statusCode).toBe(401);
});
});
describe('GET /api/employee/client-prizes', () => {
it('should reject request without authentication', async () => {
const res = await request(app)
.get('/api/employee/client-prizes')
.query({ email: 'client@example.com' });
expect(res.statusCode).toBe(401);
});
});
describe('GET /api/employee/history', () => {
it('should reject request without authentication', async () => {
const res = await request(app).get('/api/employee/history');
expect(res.statusCode).toBe(401);
});
});
});
describe('Employee Ticket Validation', () => {
describe('Status Transitions', () => {
it('should define valid ticket statuses', () => {
const validStatuses = ['PENDING', 'CLAIMED', 'REJECTED'];
validStatuses.forEach((status) => {
expect(['PENDING', 'CLAIMED', 'REJECTED']).toContain(status);
});
});
it('should have valid status transitions', () => {
// PENDING can go to CLAIMED or REJECTED
const transitions = {
PENDING: ['CLAIMED', 'REJECTED'],
CLAIMED: [], // Final state
REJECTED: [], // Final state
};
expect(transitions.PENDING).toContain('CLAIMED');
expect(transitions.PENDING).toContain('REJECTED');
expect(transitions.CLAIMED).toHaveLength(0);
expect(transitions.REJECTED).toHaveLength(0);
});
});
});