Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #31

Merged
merged 3 commits into from
Mar 15, 2024
Merged
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
25 changes: 13 additions & 12 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ name: Node.js CI

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:
build:

runs-on: ubuntu-latest

strategy:
Expand All @@ -20,12 +19,14 @@ jobs:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm test
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm ci
- run: npm run build --if-present
- run: npm test
env:
MONGODB_URL_TEST: ${{ secrets.MONGODB_URL_TEST }}
174 changes: 173 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "app.js",
"scripts": {
"test": "jest",
"start": "node src/app.js",
"dev": "nodemon src/app.js"
"start": "node src/index.js",
"dev": "nodemon src/index.js"
},
"keywords": [],
"author": "",
Expand All @@ -29,6 +29,7 @@
},
"devDependencies": {
"jest": "^29.7.0",
"nodemon": "^3.1.0"
"nodemon": "^3.1.0",
"supertest": "^6.3.4"
}
}
39 changes: 39 additions & 0 deletions src/__tests__/intergration/userRouts.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const request = require("supertest");
const app = require("../../app");
const mongoose = require("mongoose");
const UserModel = require("../../models/userModel");

// describe("POST /register", () => {
// it("should get test message", async () => {
// const { body } = await request(app).get("/test");

// expect(body).toEqual([
// expect.objectContaining({
// message: "its working",
// }),
// ]);
// });
// });

const testUser = {
username: "testUser",
email: "[email protected]",
password: "Hello@123455",
};

beforeAll(async () => {
await mongoose.connect(process.env.MONGODB_URL_TEST);
});

afterAll(async () => {
await UserModel.deleteOne({ username: "testUser" });
await mongoose.connection.close();
});

describe("POST /register", () => {
test("It should create new user", async () => {
const response = await request(app).post("/api/v1/register").send(testUser);
expect(response.statusCode).toBe(201);
// expect(response.body).toEqual({ helo: "hello" });
});
});
30 changes: 1 addition & 29 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const express = require("express");
const cors = require("cors");
const morgan = require("morgan");
const dbConnect = require("./db/conn");
const mongoose = require("mongoose");
const router = require("./router/route");
const cookieParser = require("cookie-parser");
const { default: rateLimit } = require("express-rate-limit");
Expand Down Expand Up @@ -56,30 +54,4 @@ app.use((error, req, res, next) => {
});
});

// Start Server if datbase connected
async function initializeApp() {
try {
await dbConnect();
app.listen(PORT, () => {
console.log("Server Started");
});
} catch (err) {
console.log(err);
}
}

initializeApp();

// Handle MongoDB connection close on application termination
process.on("SIGINT", async () => {
console.log("Received SIGINT. Closing MongoDB connection...");

try {
await mongoose.connection.close();
console.log("MongoDB connection closed due to application termination");
process.exit(0);
} catch (error) {
console.error("Error closing MongoDB connection:", error);
process.exit(1);
}
});
module.exports = app;
Loading
Loading