-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ft(login) user can log into the E-commerce application via email & pa…
…ssword -user login with email and password and return jwt as result of successifull login -unit test for user login endpont both successifull and unsuccessfull login event -swagger documentation for user login endpoint [Finishes #187419169]
- Loading branch information
Showing
22 changed files
with
412 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ jobs: | |
uses: codecov/[email protected] | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
slug: soleil00/eagles-ec-be | ||
slug: atlp-rwanda/eagles-ec-be | ||
|
||
- name: Trigger Render Deployment | ||
env: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/node_modules | ||
/.env | ||
/package-lock.json | ||
/package-lock.json | ||
/coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import request from 'supertest'; | ||
import { beforeAll, afterAll, beforeEach, afterEach, test } from '@jest/globals'; | ||
import app from '../src/utils/server'; | ||
import User from '../src/sequelize/models/users'; | ||
import sequelize, { connect } from '../src/config/dbConnection'; | ||
|
||
|
||
describe('Testing User route', () => { | ||
beforeAll(async () => { | ||
try { await | ||
connect(); | ||
} | ||
catch (error) { sequelize.close(); } }, 20000); | ||
|
||
afterAll(async () => { | ||
await sequelize.close(); }); | ||
beforeEach(async () => { | ||
await User.destroy({ truncate: true }); | ||
}); | ||
|
||
test('should return 201 and create a new user when registering successfully', async () => { | ||
const userData = { | ||
name: 'yvanna', | ||
username: 'testuser', | ||
email: '[email protected]', | ||
password: 'test1234', | ||
}; | ||
const response = await request(app) | ||
.post('/api/v1/users') | ||
.send(userData); | ||
expect(response.status).toBe(201); }, 20000); | ||
|
||
test('should return 409 when registering with an existing email', async () => { await User.create({ | ||
name: 'yvanna', | ||
username: 'testuser', | ||
email: '[email protected]', | ||
password: 'test1234', | ||
}); | ||
|
||
const userData = { | ||
name: 'yvanna', | ||
username: 'testuser', | ||
email: '[email protected]', | ||
password: 'test1234', | ||
}; | ||
|
||
const response = await request(app) | ||
.post('/api/v1/users') | ||
.send(userData); | ||
expect(response.status).toBe(409); }, 20000); | ||
|
||
test('should return 500 when registering with an invalid credential', async () => { | ||
const userData = { | ||
email: '[email protected]', name: "", username: 'existinguser', }; | ||
const response = await request(app) | ||
.post('/api/v1/users') | ||
.send(userData); | ||
|
||
expect(response.status).toBe(500); }, 20000); }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import bcrypt from 'bcryptjs' | ||
|
||
export const hashedPassword = async(password: string) => { | ||
const hashpass = await bcrypt.hash(password, 10) | ||
return hashpass; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { Request, Response, Router } from "express"; | ||
import userRoutes from "./userRoutes"; | ||
|
||
|
||
const appROutes = Router(); | ||
|
||
appROutes.use("/users", userRoutes); | ||
|
||
|
||
export default appROutes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
import { Router } from "express"; | ||
import { fetchAllUsers,userLogin } from "../controllers/userControllers"; | ||
import { | ||
fetchAllUsers, | ||
createUserController, | ||
userLogin } | ||
from "../controllers/userControllers"; | ||
|
||
const userRoutes = Router(); | ||
|
||
userRoutes.get("/", fetchAllUsers); | ||
userRoutes.post('/login',userLogin); | ||
userRoutes.post("/", createUserController) | ||
|
||
|
||
export default userRoutes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
src/sequelize/migrations/20240412153905-delete-isMerchant.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.