Skip to content

Commit

Permalink
bug-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bertrandshema committed May 17, 2024
1 parent 284b448 commit 7ecb118
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion src/__test__/userController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import { afterAllHook, beforeAllHook } from './testSetup';
import jwt from 'jsonwebtoken';
import dbConnection from '../database';
import UserModel from '../database/models/userModel';
<<<<<<< Updated upstream
=======
// import { use } from 'passport';

import dotenv from 'dotenv';
dotenv.config();

>>>>>>> Stashed changes
const userRepository = dbConnection.getRepository(UserModel);

beforeAll(beforeAllHook);
Expand Down Expand Up @@ -144,7 +152,8 @@ describe('User Registration Tests', () => {
expect(response.status).toBe(404);
expect(response.body.message).toBe('User not found');
});
});




describe('User Login Tests', () => {
Expand Down Expand Up @@ -180,6 +189,7 @@ describe('User Login Tests', () => {
}
});

<<<<<<< Updated upstream
it('should verify the 2FA code for a vendor user', async () => {
const userData = {
firstName: 'Test',
Expand Down Expand Up @@ -221,6 +231,8 @@ describe('User Login Tests', () => {
}
});

=======
>>>>>>> Stashed changes

it('should log in a buyer with valid credentials', async () => {
const formData = {
Expand Down Expand Up @@ -318,8 +330,62 @@ describe('User Login Tests', () => {
expect(loginResponse.body.message).toBe('User Not Found');
});
});
});

describe('Password Recover Tests', () => {
/*it('should return 404 if user is not found', async () => {
const response = await request(app)
.post('/api/v1/recover')
.send({ email: 'nonexistent@example.com' });
expect(response.status).toBe(404);
expect(response.body).toEqual({ message: 'User not found' });
});
it('should generate a password reset token and send an email', async () => {
const response = await request(app)
.post('/api/v1/recover')
.send({ email: 'test@gmail.com' });
expect(response.status).toBe(200);
expect(response.body.message).toEqual('Password reset token generated successfully');
expect(response.body.recoverToken).toBeDefined();
});
it('should update password successfully', async () => {
const userData = {
firstName: 'Test',
lastName: 'User',
email: 'test@gmail.com',
password: 'TestPassword123',
userType: 'buyer',
};
await request(app).post('/api/v1/register').send(userData);
// Generate a valid recover token for testing
const email = 'test@example.com';
const recoverToken = jwt.sign({ email }, process.env.JWT_SECRET as jwt.Secret, { expiresIn: '1h' });
const response = await request(app)
.post(`/api/v1/recover/confirm/${recoverToken}`)
.send({ password: 'new-password' });
expect(response.status).toBe(200);
expect(response.body).toEqual({ message: 'Password updated successfully' });
});
it('should return 400 for an invalid token', async () => {
const recoverToken = 'invalid-recover-token';
const response = await request(app)
.post(`/api/v1/recover/confirm/${recoverToken}`)
.send({ password: 'new-password' });
expect(response.status).toBe(400);
expect(response.body).toEqual({ message: 'Token is required' });
});*/

it('should generate a password reset token and send an email', async () => {
const userData = {
Expand Down

0 comments on commit 7ecb118

Please sign in to comment.