Skip to content

Commit

Permalink
feat: add api root endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
junjie-w committed Nov 15, 2024
1 parent 32b7e65 commit df117d0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ const app = express();
app.use(jsonParser);
app.use(express.urlencoded({ extended: true }));

app.get('/', (_req, res) => {
res.json({
message: 'Welcome to Echo Service! Send your requests to /echo endpoint',
availableEndpoints: {
echo: '/echo',
health: '/health'
},
documentation: SERVICE_INFO.SOURCE_CODE
});
});

app.get('/health', (_req, res) => {
const healthResponse: HealthCheckResponse = {
status: 'healthy',
Expand Down
19 changes: 19 additions & 0 deletions src/tests/integration/app.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import request from 'supertest';

import app from '../../app.js';
import { SERVICE_INFO } from '../../config/constants.js';
import * as responseUtils from '../../utils/response.js';

const mockHostname = jest.fn().mockReturnValue('test-host');
Expand All @@ -22,6 +23,24 @@ describe('Echo Service Integration Tests', () => {
process.env.NODE_ENV = originalEnv;
});

describe('GET /', () => {
it('should return 200 and welcome message with available endpoints', async () => {
const response = await request(app)
.get('/')
.expect('Content-Type', /json/)
.expect(200);

expect(response.body).toEqual({
message: 'Welcome to Echo Service! Send your requests to /echo endpoint',
availableEndpoints: {
echo: '/echo',
health: '/health'
},
documentation: SERVICE_INFO.SOURCE_CODE
});
});
});

describe('GET /health', () => {
it('should return 200 and health status', async () => {
const response = await request(app)
Expand Down

0 comments on commit df117d0

Please sign in to comment.