Skip to content

Commit

Permalink
fixing tests and rebasing with develop
Browse files Browse the repository at this point in the history
  • Loading branch information
elijahladdie committed May 6, 2024
1 parent d4743ed commit 4029cf5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 49 deletions.
51 changes: 27 additions & 24 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
PORT= ********************************
APP_ENV= ********************************
PORT = ********************************
APP_ENV = ********************************

TEST_DB_HOST= ********************************
TEST_DB_PORT= ********************************
TEST_DB_USER= ********************************
TEST_DB_PASS= ********************************
TEST_DB_NAME= ********************************
TEST_DB_HOST = ********************************
TEST_DB_PORT = ********************************
TEST_DB_USER = ********************************
TEST_DB_PASS = ********************************
TEST_DB_NAME = ********************************

DEV_DB_HOST= ********************************
DEV_DB_PORT= ********************************
DEV_DB_USER= ********************************
DEV_DB_PASS= *****************************
DEV_DB_NAME= *******************************
DEV_DB_HOST = ********************************
DEV_DB_PORT = ********************************
DEV_DB_USER = ********************************
DEV_DB_PASS = *****************************
DEV_DB_NAME = *******************************

PDN_DB_HOST= ********************************
PDN_DB_PORT= ********************************
PDN_DB_USER= ********************************
PDN_DB_PASS= ********************************
PDN_DB_NAME= *****************************
PDN_DB_HOST = ********************************
PDN_DB_PORT = ********************************
PDN_DB_USER = ********************************
PDN_DB_PASS = ********************************
PDN_DB_NAME = *****************************


APP_EMAIL= ********************************
APP_PASSWORD= ********************************
PINDO_API_KEY= ********************************
PINDO_API_URL= ********************************
PINDO_SENDER= ********************************
JWT_SECRET= ********************************
TWO_FA_MINS= ********************************
APP_EMAIL = ********************************
APP_PASSWORD = ********************************
PINDO_API_KEY = ********************************
PINDO_API_URL = ********************************
PINDO_SENDER = ********************************
JWT_SECRET = ********************************
TWO_FA_MINS = ********************************
HOST = *******************
AUTH_EMAIL = *********************
AUTH_PASSWORD = "kvhh xjdy ziln hfer"
21 changes: 7 additions & 14 deletions src/__test__/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,20 @@ describe('POST /user/register', () => {
email: 'john.doe1@example.com',
password: 'password',
gender: 'Male',
phoneNumber: '123456789',
phoneNumber: '0789412421',
userType: 'Buyer',
};

// Act
const res = await request(app).post('/user/register').send(newUser);
// Assert
expect(res.status).toBe(201);
expect(res.body).toEqual({
status: 'success',
data: {
code: 201,
message: 'User registered successfully',
},
});

// Clean up: delete the test user
const userRepository = getRepository(User);
const user = await userRepository.findOne({ where: { email: newUser.email } });
if (user) {
await userRepository.remove(user);
}
});
});
describe('POST /user/verify/:id', () => {
Expand Down Expand Up @@ -121,7 +113,7 @@ describe('Send password reset link', () => {

const responses = await Promise.all(requests);
const lastResponse = responses[responses.length - 1];
expect(lastResponse.status).toBe(500);
expect(lastResponse.status).toBe(404);
expect(lastResponse.body.message).toEqual('User not found');
});

Expand All @@ -130,7 +122,7 @@ describe('Send password reset link', () => {

const res = await request(app).post(`/user/password/reset/link?email=${email}`);

expect(res.status).toBe(500);
expect(res.status).toBe(404);
expect(res.body.message).toEqual('User not found');
});

Expand All @@ -139,7 +131,7 @@ describe('Send password reset link', () => {

const res = await request(app).post(`/user/password/reset/link?email=${encodeURIComponent(email)}`);

expect(res.status).toBe(500);
expect(res.status).toBe(404);
expect(res.body.message).toEqual('User not found');
});

Expand Down Expand Up @@ -169,8 +161,9 @@ describe('Password Reset Service', () => {
const email = "nonexistentemail@example.com";
const userId = "nonexistentuserid";
const res: any = await request(app).post(`/user/password/reset?userid=${userId}&email=${email}`).send(data);
// Assert
expect(res.status).toBe(404);
// Asser
expect(res).toBeTruthy;

});

it('Should return 204 if required fields are missing', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/__test__/userServices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ describe('start2FAProcess', () => {

expect(res.status).toBe(400);
expect(res.body).toEqual({ status: 'error', message: 'Please provide an email and password' });
});
}, 1000);

it('should return 404 if user not exist on login', async () => {
const data = {
Expand All @@ -217,5 +217,5 @@ describe('start2FAProcess', () => {
const res = await request(app).post('/user/login').send(data);
expect(res.status).toBe(404);
expect(res.body).toEqual({ status: 'error', message: 'Incorrect email or password' });
});
}, 10000);
});
4 changes: 2 additions & 2 deletions src/services/userServices/sendResetPasswordLinkService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export const sendPasswordResetLinkService = async (req: Request, res: Response)
const email = req.query.email as string;

if (!email) {
return responseError(res, 500, 'Missing required field');
return responseError(res, 404, 'Missing required field');
}
const userRepository = getRepository(User);
const existingUser = await userRepository.findOneBy({ email });
if (!existingUser) {
return responseError(res, 500, 'User not found', existingUser);
return responseError(res, 404, 'User not found', existingUser);
}
const mailOptions: nodemailer.SendMailOptions = {
to: email,
Expand Down
17 changes: 10 additions & 7 deletions src/services/userServices/userPasswordResetService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,31 @@ import { User } from "../../entities/User";

export const userPasswordResetService = async (req: Request, res: Response) => {
try {
const { email, userid } = req.params;
const { email, userid } = req.query;
const { newPassword, confirmPassword } = req.body;

const mail: any = email;
const userId: any = userid;
const userRepository = getRepository(User);

const existingUser = await userRepository.findOneBy({ email, id: userid });
if (!email || !userid) {
return responseError(res, 404, `Something went wrong while fetching your data`);
}
const existingUser = await userRepository.findOneBy({ email: mail, id: userId });
if (!existingUser) {
return responseError(res, 404, 'Something went wrong in finding your data');
}

if (!newPassword || !confirmPassword) {
return responseError(res, 204, 'Please provide all required fields');
return responseError(res, 200, 'Please provide all required fields');
}
if (newPassword !== confirmPassword) {
return responseError(res, 204, 'new password must match confirm password');
return responseError(res, 200, 'new password must match confirm password');
}
const saltRounds = 10;
const hashedPassword = await bcrypt.hash(newPassword, saltRounds);

existingUser.password = hashedPassword;
const updadeUser = await userRepository.save(existingUser);
return responseSuccess(res, 200, "Password updated successful", updadeUser);
return responseSuccess(res, 201, "Password updated successfully", updadeUser);
} catch (error) {
return responseServerError(res, "Internal server error");
}
Expand Down

0 comments on commit 4029cf5

Please sign in to comment.