Skip to content

Commit b98cc0e

Browse files
committed
Create status controller
1 parent 6a0a9fc commit b98cc0e

File tree

6 files changed

+51
-0
lines changed

6 files changed

+51
-0
lines changed

src/apps/mooc_backend/config/dependency-injection/application.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ services:
66
Apps.mooc.controllers.CreateCourseController:
77
class: ../../controllers/CreateCourseController
88
arguments: ["@Mooc.courses.CreateCourse"]
9+
10+
Apps.mooc.controllers.StatusController:
11+
class: ../../controllers/StatusController
12+
arguments: []
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Request, Response } from 'express';
2+
import httpStatus from 'http-status';
3+
4+
export default class StatusController {
5+
async create(req: Request, res: Response) {
6+
res.status(httpStatus.OK).send();
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Express } from 'express';
2+
import { createUserRoute } from './create-course.route';
3+
import { statusRoute } from './status.route';
4+
5+
export function registerRoutes(app: Express) {
6+
createUserRoute(app);
7+
statusRoute(app);
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Express } from 'express';
2+
import container from '../config/dependency-injection';
3+
import StatusController from '../controllers/StatusController';
4+
5+
export const statusRoute = (app: Express) => {
6+
const controller: StatusController = container.get('Apps.mooc.controllers.StatusController');
7+
app.get('/status', (req, res) => controller.create(req, res));
8+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Feature: Api status
2+
In order to know the server is up and running
3+
As a health check
4+
I want to check the api status
5+
6+
Scenario: Check the api status
7+
Given I send a GET request to "/status"
8+
Then the response code should be 200
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Given, Then } from 'cucumber';
2+
import request from 'supertest';
3+
import app from '../../../../src/apps/mooc_backend/app';
4+
5+
let statusRoute: string;
6+
7+
Given('I send a GET request to {string}', (route: string) => {
8+
statusRoute = route;
9+
});
10+
11+
Then('the response code should be {int}', async (code: number) => {
12+
await request(app)
13+
.get(statusRoute)
14+
.expect(code);
15+
});

0 commit comments

Comments
 (0)