Skip to content

Commit

Permalink
Added check parameter for API details (#417)
Browse files Browse the repository at this point in the history
* Added check parameter for API details
* Added check no details test
  • Loading branch information
petruki authored May 26, 2023
1 parent b9056ff commit 78d755d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
"jsonwebtoken": "^9.0.0",
"moment": "^2.29.4",
"mongodb": "^5.5.0",
"mongoose": "^7.1.1",
"mongoose": "^7.2.1",
"pino": "^8.14.1",
"pino-pretty": "^10.0.0",
"swagger-ui-express": "^4.6.3",
"switcher-client": "^3.1.6",
"switcher-client": "^3.1.7",
"validator": "^13.9.0"
},
"devDependencies": {
Expand All @@ -62,7 +62,7 @@
"jest-sonar-reporter": "^2.0.0",
"node-notifier": "^10.0.1",
"nodemon": "^2.0.22",
"sinon": "^15.0.4",
"sinon": "^15.1.0",
"supertest": "^6.3.3"
},
"repository": {
Expand Down
18 changes: 12 additions & 6 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,14 @@ app.get('/swagger.json', resourcesAuth(), (_req, res) => {
res.status(200).send(swaggerDocument);
});

app.get('/check', defaultLimiter, (_req, res) => {
res.status(200).send({
status: 'UP',
attributes: {
app.get('/check', defaultLimiter, (req, res) => {
const showDetails = req.query.details === '1';
const response = {
status: 'UP'
};

if (showDetails) {
response.attributes = {
version: swaggerDocument.info.version,
release_time: process.env.RELEASE_TIME,
env: process.env.ENV,
Expand All @@ -96,8 +100,10 @@ app.get('/check', defaultLimiter, (_req, res) => {
max_rpm: process.env.MAX_REQUEST_PER_MINUTE,
regex_max_timeout: process.env.REGEX_MAX_TIMEOUT,
regex_max_blacklist: process.env.REGEX_MAX_BLACLIST
}
});
};
}

res.status(200).send(response);
});

app.get('*', (_req, res) => {
Expand Down
13 changes: 11 additions & 2 deletions tests/admin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,15 +468,24 @@ describe('Testing Admin insertion', () => {
expect(response.body.error).toEqual('Operation not found');
});

test('ADMIN_SUITE - Should get API UP', async () => {
test('ADMIN_SUITE - Should get API UP with details', async () => {
const response = await request(app)
.get('/check')
.get('/check?details=1')
.send().expect(200);

expect(response.body.status).toEqual('UP');
expect(response.body.attributes.version).toEqual(swaggerDocument.info.version);
});

test('ADMIN_SUITE - Should get API UP with NO details', async () => {
const response = await request(app)
.get('/check')
.send().expect(200);

expect(response.body.status).toEqual('UP');
expect(response.body.attributes).toBe(undefined);
});

test('ADMIN_SUITE - Should return OpenAPI Swagger API document', async () => {
const response = await request(app)
.get('/swagger.json')
Expand Down

0 comments on commit 78d755d

Please sign in to comment.