Skip to content

Commit 19b2b84

Browse files
feat: implement a /v2/ping endpoint WEB-981 (#602)
1 parent 43e7ff9 commit 19b2b84

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

openapi/paths/v2/ping.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module.exports = sendWrapper => {
2+
async function GET( req, res ) {
3+
sendWrapper( req, res, null, { status: "available" } );
4+
}
5+
6+
GET.apiDoc = {
7+
tags: ["Ping"],
8+
summary: "Check API availability",
9+
responses: {
10+
200: {
11+
description: "A simple availability response",
12+
content: {
13+
"application/json": {
14+
schema: {
15+
type: "object",
16+
properties: {
17+
status: {
18+
type: "string",
19+
example: "available"
20+
}
21+
},
22+
required: ["status"]
23+
}
24+
}
25+
}
26+
},
27+
default: {
28+
$ref: "#/components/responses/Error"
29+
}
30+
},
31+
"x-default-ttl": -1
32+
};
33+
34+
return {
35+
GET
36+
};
37+
};

test/integration/v2/ping.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { expect } = require( "chai" );
2+
const request = require( "supertest" );
3+
4+
describe( "Ping", ( ) => {
5+
describe( "index", ( ) => {
6+
it( "renders a ping response", function ( done ) {
7+
request( this.app ).get( "/v2/ping" )
8+
.expect( res => {
9+
expect( res.body.status ).to.eq( "available" );
10+
expect( res.headers["cache-control"] ).to.eq(
11+
"private, no-cache, no-store, must-revalidate"
12+
);
13+
expect( res.headers.expires ).to.eq( "-1" );
14+
expect( res.headers.pragma ).to.eq( "no-cache" );
15+
} ).expect( "Content-Type", /json/ )
16+
.expect( 200, done );
17+
} );
18+
} );
19+
} );

0 commit comments

Comments
 (0)