Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions server/.env

This file was deleted.

5 changes: 5 additions & 0 deletions server/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DATABASE=
PORT=
BRAINTREE_MERCHANT_ID=
BRAINTREE_PUBLIC_KEY=
BRAINTREE_PRIVATE_KEY=
10 changes: 6 additions & 4 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ app.use("/api/order", orderRouter);
app.use("/api/customize", customizeRouter);

// Run Server
const PORT = process.env.PORT || 8000;
app.listen(PORT, () => {
console.log("Server is running on ", PORT);
});
// const PORT = process.env.PORT || 8000;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the server will start now?? As you commented this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i did the last code commented i can remove if you want

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we comment that our app will not run. Did you run all the code you changed? I was curious is that tested on your side.

// app.listen(PORT, () => {
// console.log("Server is running on ", PORT);
// });

module.exports = app;
1 change: 1 addition & 0 deletions server/controller/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Auth {
async postSignup(req, res) {
let { name, email, password, cPassword } = req.body;
let error = {};

if (!name || !email || !password || !cPassword) {
error = {
...error,
Expand Down
6 changes: 4 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A E-commerce website.",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "jest",
"start:dev": "nodemon app.js"
},
"repository": {
Expand All @@ -25,11 +25,13 @@
"dotenv": "^8.2.0",
"express": "^4.17.1",
"i": "^0.3.6",
"jest": "^30.0.4",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.9.27",
"morgan": "^1.10.0",
"multer": "^1.4.2",
"nodemon": "^2.0.4",
"npm": "^6.14.8"
"npm": "^6.14.8",
"supertest": "^7.1.3"
}
}
61 changes: 61 additions & 0 deletions server/tests/auth.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const request = require("supertest")
const app = require("../app")
const userModel = require("../models/users");

describe('test Authentication', () => {
it('register user successfully ', async () => {
const res = await request(app)
.post('/api/signup')
.send (
{
"name" : "testing",
"email" : "[email protected]",
"password" : "testingAZA",
"cPassword" : "testingAZA",
}
)
expect(res.statusCode).toBe(200);
});


it('login user successfully ', async () => {
const user = await userModel.create({
name: "loginTest",
email: "[email protected]",
password: "testing",
userRole: 0
});
const res = await request(app)
.post('/api/signin')
.send({
email: user.email,
password: "testing"
});
expect(res.statusCode).toBe(200);
expect(res.body).toHaveProperty('token');
});


it('isadmin', async () => {
const user = await userModel.create({
name: "adminUser",
email: "[email protected]",
password: "123456344",
userRole: 1
});
const res = await request(app)
.post('/api/isadmin')
.send({ loggedInUserId: user._id });

expect(res.statusCode).toBe(200);
expect(res.body).toHaveProperty('role');
expect(res.body.role).toBe(1);
}, 10000);







});