Skip to content

Commit d53b635

Browse files
Merge pull request #8563 from BitGo/WCI-188
refactor(express): split pingExpress into v1 and v2
2 parents f273031 + d7e2757 commit d53b635

6 files changed

Lines changed: 123 additions & 26 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
};
@@ -1689,14 +1689,15 @@ export function setupAPIRoutes(app: express.Application, config: Config): void {
16891689
// V2 routes should be added to www/config/routesV2.js
16901690

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

16971697
router.get('express.v1.ping', [prepareBitGo(config), typedPromiseWrapper(handlePing)]);
16981698
router.get('express.ping', [prepareBitGo(config), typedPromiseWrapper(handlePing)]);
1699-
router.get('express.pingExpress', [typedPromiseWrapper(handlePingExpress)]);
1699+
router.get('express.v1.pingexpress', [typedPromiseWrapper(handlePingExpress)]);
1700+
router.get('express.pingexpress', [typedPromiseWrapper(handlePingExpress)]);
17001701

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

modules/express/src/typedRoutes/api/common/pingExpress.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import * as express from 'express';
44

55
import { GetV1Ping } from './v1/ping';
66
import { GetV2Ping } from './v2/ping';
7-
import { GetPingExpress } from './common/pingExpress';
7+
import { GetV1PingExpress } from './v1/pingExpress';
8+
import { GetV2PingExpress } from './v2/pingExpress';
89
import { PostLogin } from './common/login';
910
import { PostV1Decrypt } from './v1/decrypt';
1011
import { PostV2Decrypt } from './v2/decrypt';
@@ -76,8 +77,11 @@ export const ExpressPingApiSpec = apiSpec({
7677
});
7778

7879
export const ExpressPingExpressApiSpec = apiSpec({
79-
'express.pingExpress': {
80-
get: GetPingExpress,
80+
'express.v1.pingexpress': {
81+
get: GetV1PingExpress,
82+
},
83+
'express.pingexpress': {
84+
get: GetV2PingExpress,
8185
},
8286
});
8387

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+
* Use this endpoint to check whether your local BitGo Express server is up and reachable. It returns immediately without contacting bitgo.com, so it succeeds even when BitGo's servers are unavailable. Use [Ping](/reference/expressping) instead if you also need to confirm connectivity to BitGo.
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+
});
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
7+
*
8+
* Use this endpoint to check whether your local BitGo Express server is up and reachable. It returns immediately without contacting bitgo.com, so it succeeds even when BitGo's servers are unavailable. Use [Ping](/reference/expressping) instead if you also need to confirm connectivity to BitGo.
9+
*
10+
* @operationId express.pingexpress
11+
* @tag Express
12+
* @public
13+
*/
14+
export const GetV2PingExpress = httpRoute({
15+
path: '/api/v2/pingexpress',
16+
method: 'GET',
17+
request: httpRequest({}),
18+
response: {
19+
200: t.type({ status: t.string }),
20+
404: BitgoExpressError,
21+
},
22+
});
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)