1- import request from ' supertest' ;
1+ import request from " supertest" ;
22import { describe , expect , it , test } from "@jest/globals" ;
33import app from "../src/index" ;
44
5- describe ( 'Authentication API' , ( ) => {
6- // The unit tests below are currently commented out because they require a database connection.
7- // They will be uncommented out once all the necessary mocks are in place.
8-
9- // describe('POST /auth/login', () => {
10- // it('should return 200 and a token for valid credentials', async () => {
11- // const response = await request(app)
12- // .post('/auth/login')
13- // .send({ username: 'validUser', password: 'validPassword' });
14-
15- // expect(response.status).toBe(200);
16- // expect(response.body).toHaveProperty('token');
17- // });
18-
19- // it('should return 401 for invalid credentials', async () => {
20- // const response = await request(app)
21- // .post('/auth/login')
22- // .send({ username: 'invalidUser', password: 'wrongPassword' });
23-
24- // expect(response.status).toBe(401);
25- // expect(response.body).toHaveProperty('error', 'Invalid credentials');
26- // });
27-
28- // it('should return 400 if username or password is missing', async () => {
29- // const response = await request(app)
30- // .post('/auth/login')
31- // .send({ username: 'validUser' });
32-
33- // expect(response.status).toBe(400);
34- // expect(response.body).toHaveProperty('error', 'Username and password are required');
35- // });
36- // });
37-
38- // describe('POST /auth/register', () => {
39- // it('should return 201 and create a new user for valid input', async () => {
40- // const response = await request(app)
41- // .post('/auth/register')
42- // .send({ username: 'newUser', password: 'newPassword' });
43-
44- // expect(response.status).toBe(201);
45- // expect(response.body).toHaveProperty('message', 'User registered successfully');
46- // });
47-
48- // it('should return 400 if username is already taken', async () => {
49- // await request(app)
50- // .post('/auth/register')
51- // .send({ username: 'existingUser', password: 'password123' });
52-
53- // const response = await request(app)
54- // .post('/auth/register')
55- // .send({ username: 'existingUser', password: 'password123' });
56-
57- // expect(response.status).toBe(400);
58- // expect(response.body).toHaveProperty('error', 'Username is already taken');
59- // });
60-
61- // it('should return 400 if username or password is missing', async () => {
62- // const response = await request(app)
63- // .post('/auth/register')
64- // .send({ username: '' });
65-
66- // expect(response.status).toBe(400);
67- // expect(response.body).toHaveProperty('error', 'Username and password are required');
68- // });
69- // });
70-
71- // describe('GET /auth/profile', () => {
72- // it('should return 200 and user profile for valid token', async () => {
73- // const loginResponse = await request(app)
74- // .post('/auth/login')
75- // .send({ username: 'validUser', password: 'validPassword' });
76-
77- // const token = loginResponse.body.token;
78-
79- // const response = await request(app)
80- // .get('/auth/profile')
81- // .set('Authorization', `Bearer ${token}`);
82-
83- // expect(response.status).toBe(200);
84- // expect(response.body).toHaveProperty('username', 'validUser');
85- // });
86-
87- // it('should return 401 if token is missing or invalid', async () => {
88- // const response = await request(app)
89- // .get('/auth/profile')
90- // .set('Authorization', 'Bearer invalidToken');
91-
92- // expect(response.status).toBe(401);
93- // expect(response.body).toHaveProperty('error', 'Unauthorized');
94- // });
95- // });
96- } ) ;
5+ describe ( "Authentication API" , ( ) => {
6+ // The unit tests below are currently commented out because they require a database connection.
7+ // They will be uncommented out once all the necessary mocks are in place.
8+ // describe('POST /auth/login', () => {
9+ // it('should return 200 and a token for valid credentials', async () => {
10+ // const response = await request(app)
11+ // .post('/auth/login')
12+ // .send({ username: 'validUser', password: 'validPassword' });
13+ // expect(response.status).toBe(200);
14+ // expect(response.body).toHaveProperty('token');
15+ // });
16+ // it('should return 401 for invalid credentials', async () => {
17+ // const response = await request(app)
18+ // .post('/auth/login')
19+ // .send({ username: 'invalidUser', password: 'wrongPassword' });
20+ // expect(response.status).toBe(401);
21+ // expect(response.body).toHaveProperty('error', 'Invalid credentials');
22+ // });
23+ // it('should return 400 if username or password is missing', async () => {
24+ // const response = await request(app)
25+ // .post('/auth/login')
26+ // .send({ username: 'validUser' });
27+ // expect(response.status).toBe(400);
28+ // expect(response.body).toHaveProperty('error', 'Username and password are required');
29+ // });
30+ // });
31+ // describe('POST /auth/register', () => {
32+ // it('should return 201 and create a new user for valid input', async () => {
33+ // const response = await request(app)
34+ // .post('/auth/register')
35+ // .send({ username: 'newUser', password: 'newPassword' });
36+ // expect(response.status).toBe(201);
37+ // expect(response.body).toHaveProperty('message', 'User registered successfully');
38+ // });
39+ // it('should return 400 if username is already taken', async () => {
40+ // await request(app)
41+ // .post('/auth/register')
42+ // .send({ username: 'existingUser', password: 'password123' });
43+ // const response = await request(app)
44+ // .post('/auth/register')
45+ // .send({ username: 'existingUser', password: 'password123' });
46+ // expect(response.status).toBe(400);
47+ // expect(response.body).toHaveProperty('error', 'Username is already taken');
48+ // });
49+ // it('should return 400 if username or password is missing', async () => {
50+ // const response = await request(app)
51+ // .post('/auth/register')
52+ // .send({ username: '' });
53+ // expect(response.status).toBe(400);
54+ // expect(response.body).toHaveProperty('error', 'Username and password are required');
55+ // });
56+ // });
57+ // describe('GET /auth/profile', () => {
58+ // it('should return 200 and user profile for valid token', async () => {
59+ // const loginResponse = await request(app)
60+ // .post('/auth/login')
61+ // .send({ username: 'validUser', password: 'validPassword' });
62+ // const token = loginResponse.body.token;
63+ // const response = await request(app)
64+ // .get('/auth/profile')
65+ // .set('Authorization', `Bearer ${token}`);
66+ // expect(response.status).toBe(200);
67+ // expect(response.body).toHaveProperty('username', 'validUser');
68+ // });
69+ // it('should return 401 if token is missing or invalid', async () => {
70+ // const response = await request(app)
71+ // .get('/auth/profile')
72+ // .set('Authorization', 'Bearer invalidToken');
73+ // expect(response.status).toBe(401);
74+ // expect(response.body).toHaveProperty('error', 'Unauthorized');
75+ // });
76+ // });
77+ } ) ;
0 commit comments