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>
91 lines
2.7 KiB
JavaScript
91 lines
2.7 KiB
JavaScript
/**
|
|
* Tests d'intégration pour les endpoints du jeu
|
|
*/
|
|
import request from 'supertest';
|
|
import app from '../../index.js';
|
|
|
|
describe('Game API', () => {
|
|
describe('POST /api/game/play', () => {
|
|
it('should reject request without authentication', async () => {
|
|
const res = await request(app)
|
|
.post('/api/game/play')
|
|
.send({ ticketCode: 'TTP2025ABC' });
|
|
|
|
expect(res.statusCode).toBe(401);
|
|
expect(res.body.success).toBe(false);
|
|
});
|
|
|
|
it('should reject request with invalid token', async () => {
|
|
const res = await request(app)
|
|
.post('/api/game/play')
|
|
.set('Authorization', 'Bearer invalid-token')
|
|
.send({ ticketCode: 'TTP2025ABC' });
|
|
|
|
expect(res.statusCode).toBe(401);
|
|
expect(res.body.success).toBe(false);
|
|
});
|
|
|
|
it('should reject request without ticket code', async () => {
|
|
const res = await request(app)
|
|
.post('/api/game/play')
|
|
.set('Authorization', 'Bearer invalid-token')
|
|
.send({});
|
|
|
|
expect(res.statusCode).toBe(401);
|
|
});
|
|
});
|
|
|
|
describe('GET /api/game/my-tickets', () => {
|
|
it('should reject request without authentication', async () => {
|
|
const res = await request(app).get('/api/game/my-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/game/my-tickets')
|
|
.set('Authorization', 'Bearer invalid-token');
|
|
|
|
expect(res.statusCode).toBe(401);
|
|
expect(res.body.success).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('GET /api/game/my-tickets/:id', () => {
|
|
it('should reject request without authentication', async () => {
|
|
const res = await request(app).get('/api/game/my-tickets/1');
|
|
|
|
expect(res.statusCode).toBe(401);
|
|
expect(res.body.success).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('GET /api/game/ticket/:code', () => {
|
|
it('should reject request without authentication', async () => {
|
|
const res = await request(app).get('/api/game/ticket/TTP2025ABC');
|
|
|
|
expect(res.statusCode).toBe(401);
|
|
expect(res.body.success).toBe(false);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Game Validation', () => {
|
|
describe('Ticket Code Format', () => {
|
|
it('should have valid ticket code format TTP + year + 3 chars', () => {
|
|
const validCodes = ['TTP2025ABC', 'TTP2025XYZ', 'TTP2025123'];
|
|
const invalidCodes = ['INVALID', 'TT2025ABC', 'TTP25ABC', ''];
|
|
|
|
validCodes.forEach((code) => {
|
|
expect(code).toMatch(/^TTP\d{4}[A-Z0-9]{3}$/);
|
|
});
|
|
|
|
invalidCodes.forEach((code) => {
|
|
expect(code).not.toMatch(/^TTP\d{4}[A-Z0-9]{3}$/);
|
|
});
|
|
});
|
|
});
|
|
});
|