This commit is contained in:
8
index.js
8
index.js
@@ -4,19 +4,23 @@ const app = express();
|
|||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
app.get("/", (req, res) => {
|
app.get("/", (req, res) => {
|
||||||
res.send("🚀 Home Route Working");
|
res.json({
|
||||||
|
status: "OK",
|
||||||
|
message: "Home Route Working"
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/health", (req, res) => {
|
app.get("/health", (req, res) => {
|
||||||
res.json({
|
res.json({
|
||||||
status: "OK",
|
status: "OK",
|
||||||
message: "Server is healthy ✅"
|
message: "Server is healthy"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = app;
|
module.exports = app;
|
||||||
|
|
||||||
// only start server if not testing
|
// only start server if not testing
|
||||||
|
// It ensures the server starts only when the file is run directly, not when it is imported for testing.
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
app.listen(3000, () => {
|
app.listen(3000, () => {
|
||||||
console.log("Server running on port 3000");
|
console.log("Server running on port 3000");
|
||||||
|
|||||||
4
test.js
4
test.js
@@ -13,9 +13,9 @@ const app = require("./index");
|
|||||||
|
|
||||||
describe("API Testing", () => {
|
describe("API Testing", () => {
|
||||||
|
|
||||||
test("GET / should return home message", async () => {
|
test("GET / should return status ok", async () => {
|
||||||
const res = await request(app).get("/");
|
const res = await request(app).get("/");
|
||||||
expect(res.text).toBe("🚀 Home Route Working");
|
expect(res.body.status).toBe("ok");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("GET /health should return status OK", async () => {
|
test("GET /health should return status OK", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user