Skip to content

Commit aa26509

Browse files
docs(express): split pingExpress into v1 and v2
TICKET: WCI-188
1 parent 99b1004 commit aa26509

5 files changed

Lines changed: 109 additions & 12 deletions

File tree

modules/express/src/clientRoutes.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function handlePing(
8383
return req.bitgo.ping();
8484
}
8585

86-
function handlePingExpress(req: ExpressApiRouteRequest<'express.pingExpress', 'get'>) {
86+
function handlePingExpress(req: ExpressApiRouteRequest<'express.v1.pingexpress' | 'express.pingexpress', 'get'>) {
8787
return {
8888
status: 'express server is ok!',
8989
};
@@ -1687,13 +1687,14 @@ export function setupAPIRoutes(app: express.Application, config: Config): void {
16871687
// V2 routes should be added to www/config/routesV2.js
16881688

16891689
// ping
1690-
// /api/v[12]/pingexpress is the only exception to the rule above, as it explicitly checks the health of the
1691-
// express server without running into rate limiting with the BitGo server.
1690+
// /api/v1/pingexpress and /api/v2/pingexpress are the only exceptions to the rule above, as they explicitly check
1691+
// the health of the express server without running into rate limiting with the BitGo server.
16921692
const router = createExpressRouter();
16931693
app.use(router);
16941694

16951695
router.get('express.ping', [prepareBitGo(config), typedPromiseWrapper(handlePing)]);
1696-
router.get('express.pingExpress', [typedPromiseWrapper(handlePingExpress)]);
1696+
router.get('express.v1.pingexpress', [typedPromiseWrapper(handlePingExpress)]);
1697+
router.get('express.pingexpress', [typedPromiseWrapper(handlePingExpress)]);
16971698

16981699
// auth
16991700
router.post('express.login', [prepareBitGo(config), typedPromiseWrapper(handleLogin)]);

modules/express/src/typedRoutes/api/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { apiSpec } from '@api-ts/io-ts-http';
33
import * as express from 'express';
44

55
import { GetPing } from './common/ping';
6-
import { GetPingExpress } from './common/pingExpress';
6+
import { GetV1PingExpress } from './v1/pingExpress';
7+
import { GetV2PingExpress } from './v2/pingExpress';
78
import { PostLogin } from './common/login';
89
import { PostV1Decrypt } from './v1/decrypt';
910
import { PostV2Decrypt } from './v2/decrypt';
@@ -71,8 +72,11 @@ export const ExpressPingApiSpec = apiSpec({
7172
});
7273

7374
export const ExpressPingExpressApiSpec = apiSpec({
74-
'express.pingExpress': {
75-
get: GetPingExpress,
75+
'express.v1.pingexpress': {
76+
get: GetV1PingExpress,
77+
},
78+
'express.pingexpress': {
79+
get: GetV2PingExpress,
7680
},
7781
});
7882

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as t from 'io-ts';
2+
import { httpRoute, httpRequest } from '@api-ts/io-ts-http';
3+
import { BitgoExpressError } from '../../schemas/error';
4+
5+
/**
6+
* Ping BitGo Express (v1)
7+
*
8+
* Ping bitgo express to ensure that it is still running. Unlike /ping, this does not try connecting to bitgo.com.
9+
*
10+
* @operationId express.v1.pingexpress
11+
* @tag Express
12+
* @private
13+
*/
14+
export const GetV1PingExpress = httpRoute({
15+
path: '/api/v1/pingexpress',
16+
method: 'GET',
17+
request: httpRequest({}),
18+
response: {
19+
200: t.type({ status: t.string }),
20+
404: BitgoExpressError,
21+
},
22+
});

modules/express/src/typedRoutes/api/common/pingExpress.ts renamed to modules/express/src/typedRoutes/api/v2/pingExpress.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import { httpRoute, httpRequest } from '@api-ts/io-ts-http';
33
import { BitgoExpressError } from '../../schemas/error';
44

55
/**
6-
* Ping Express
6+
* Ping BitGo Express
77
*
8-
* @operationId express.pingExpress
9-
* @tag express
8+
* Ping bitgo express to ensure that it is still running. Unlike /ping, this does not try connecting to bitgo.com.
9+
*
10+
* @operationId express.pingexpress
11+
* @tag Express
12+
* @public
1013
*/
11-
export const GetPingExpress = httpRoute({
12-
path: '/api/v[12]/pingexpress',
14+
export const GetV2PingExpress = httpRoute({
15+
path: '/api/v2/pingexpress',
1316
method: 'GET',
1417
request: httpRequest({}),
1518
response: {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import * as assert from 'assert';
2+
import { GetV1PingExpress } from '../../../src/typedRoutes/api/v1/pingExpress';
3+
import { GetV2PingExpress } from '../../../src/typedRoutes/api/v2/pingExpress';
4+
import { assertDecode } from './common';
5+
import 'should';
6+
import 'should-http';
7+
import { setupAgent } from '../../lib/testutil';
8+
9+
describe('PingExpress route tests', function () {
10+
describe('PostV1PingExpress route definition', function () {
11+
it('should have the correct path', function () {
12+
assert.strictEqual(GetV1PingExpress.path, '/api/v1/pingexpress');
13+
});
14+
15+
it('should have the correct HTTP method', function () {
16+
assert.strictEqual(GetV1PingExpress.method, 'GET');
17+
});
18+
19+
it('should have the correct response types', function () {
20+
assert.ok(GetV1PingExpress.response[200]);
21+
assert.ok(GetV1PingExpress.response[404]);
22+
});
23+
});
24+
25+
describe('PostV2PingExpress route definition', function () {
26+
it('should have the correct path', function () {
27+
assert.strictEqual(GetV2PingExpress.path, '/api/v2/pingexpress');
28+
});
29+
30+
it('should have the correct HTTP method', function () {
31+
assert.strictEqual(GetV2PingExpress.method, 'GET');
32+
});
33+
34+
it('should have the correct response types', function () {
35+
assert.ok(GetV2PingExpress.response[200]);
36+
assert.ok(GetV2PingExpress.response[404]);
37+
});
38+
});
39+
40+
describe('Supertest Integration Tests', function () {
41+
const agent = setupAgent();
42+
43+
const expectedStatus = 'express server is ok!';
44+
45+
it('should resolve GET /api/v1/pingexpress with the expected payload', async function () {
46+
const result = await agent.get('/api/v1/pingexpress');
47+
48+
assert.strictEqual(result.status, 200);
49+
result.body.should.have.property('status');
50+
assert.strictEqual(result.body.status, expectedStatus);
51+
52+
const decodedResponse = assertDecode(GetV1PingExpress.response[200], result.body);
53+
assert.strictEqual(decodedResponse.status, expectedStatus);
54+
});
55+
56+
it('should resolve GET /api/v2/pingexpress with the expected payload', async function () {
57+
const result = await agent.get('/api/v2/pingexpress');
58+
59+
assert.strictEqual(result.status, 200);
60+
result.body.should.have.property('status');
61+
assert.strictEqual(result.body.status, expectedStatus);
62+
63+
const decodedResponse = assertDecode(GetV2PingExpress.response[200], result.body);
64+
assert.strictEqual(decodedResponse.status, expectedStatus);
65+
});
66+
});
67+
});

0 commit comments

Comments
 (0)