Skip to content

Commit 16ea13b

Browse files
Added new /home route and tests for server routes
1 parent 5769f98 commit 16ea13b

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
},
1313
"devDependencies": {
1414
"jest": "^29.5.0",
15-
"supertest": "^6.3.3"
15+
"supertest": "^6.3.4"
1616
}
17-
}
17+
}

server.test.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
const request = require('supertest');
2-
const app = require('./src/server'); // Only the app, no server listening!
2+
const app = require('./src/server'); // Importing the app, not the server!
33

4+
// Test for root route
45
describe('GET /', () => {
56
it('responds with Hello CI/CD World!', async () => {
67
const res = await request(app).get('/');
78
expect(res.text).toBe('Hello CI/CD World!');
89
});
910
});
11+
12+
// Test for the new /home route
13+
describe('GET /home', () => {
14+
it('responds with Welcome to the CI/CD Home!', async () => {
15+
const res = await request(app).get('/home');
16+
expect(res.text).toBe('Welcome to the CI/CD Home!');
17+
});
18+
});
19+
20+
// Test for a non-existent route
1021
describe('GET /nonexistent', () => {
1122
it('responds with 404 Not Found', async () => {
1223
const res = await request(app).get('/nonexistent');
1324
expect(res.statusCode).toBe(404);
1425
});
15-
});
26+
});

src/server.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
const express = require('express');
22
const app = express();
33

4+
// New route added
5+
app.get('/home', (req, res) => {
6+
res.send('Welcome to the CI/CD Home!');
7+
});
8+
9+
// Updated existing route
410
app.get('/', (req, res) => {
511
res.send('Hello CI/CD World!');
612
});

0 commit comments

Comments
 (0)