-
Notifications
You must be signed in to change notification settings - Fork 302
refactor(express): split pingExpress into v1 and v2 #8563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import * as t from 'io-ts'; | ||
| import { httpRoute, httpRequest } from '@api-ts/io-ts-http'; | ||
| import { BitgoExpressError } from '../../schemas/error'; | ||
|
|
||
| /** | ||
| * Ping BitGo Express (v1) | ||
| * | ||
| * 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. | ||
| * | ||
| * @operationId express.v1.pingexpress | ||
| * @tag Express | ||
| * @private | ||
| */ | ||
| export const GetV1PingExpress = httpRoute({ | ||
| path: '/api/v1/pingexpress', | ||
| method: 'GET', | ||
| request: httpRequest({}), | ||
| response: { | ||
| 200: t.type({ status: t.string }), | ||
| 404: BitgoExpressError, | ||
| }, | ||
| }); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,22 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import * as t from 'io-ts'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { httpRoute, httpRequest } from '@api-ts/io-ts-http'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { BitgoExpressError } from '../../schemas/error'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Ping BitGo Express | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * 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. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @operationId express.pingexpress | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @tag Express | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @public | ||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| export const GetV2PingExpress = httpRoute({ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| path: '/api/v2/pingexpress', | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+6
to
+15
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I'm still not sure how does this endpoint differs from
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /api/v2/ping checks if both Express and BitGo servers are reachable — if BitGo is down, it fails even though Express is fine. /api/v2/pingexpress only checks if Express itself is running — it never contacts BitGo, so it always returns 200 as long as the Express process is alive. So when pingexpress returns 200 { "status": "express server is ok!" }, that itself is the proof — the fact that the request was received and responded to means Express is alive and handling requests. |
||||||||||||||||||||||||||||||||||||||||||||||||||
| method: 'GET', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| request: httpRequest({}), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| response: { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 200: t.type({ status: t.string }), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 404: BitgoExpressError, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import * as assert from 'assert'; | ||
| import { GetV1PingExpress } from '../../../src/typedRoutes/api/v1/pingExpress'; | ||
| import { GetV2PingExpress } from '../../../src/typedRoutes/api/v2/pingExpress'; | ||
| import { assertDecode } from './common'; | ||
| import 'should'; | ||
| import 'should-http'; | ||
| import { setupAgent } from '../../lib/testutil'; | ||
|
|
||
| describe('PingExpress route tests', function () { | ||
| describe('PostV1PingExpress route definition', function () { | ||
| it('should have the correct path', function () { | ||
| assert.strictEqual(GetV1PingExpress.path, '/api/v1/pingexpress'); | ||
| }); | ||
|
|
||
| it('should have the correct HTTP method', function () { | ||
| assert.strictEqual(GetV1PingExpress.method, 'GET'); | ||
| }); | ||
|
|
||
| it('should have the correct response types', function () { | ||
| assert.ok(GetV1PingExpress.response[200]); | ||
| assert.ok(GetV1PingExpress.response[404]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('PostV2PingExpress route definition', function () { | ||
| it('should have the correct path', function () { | ||
| assert.strictEqual(GetV2PingExpress.path, '/api/v2/pingexpress'); | ||
| }); | ||
|
|
||
| it('should have the correct HTTP method', function () { | ||
| assert.strictEqual(GetV2PingExpress.method, 'GET'); | ||
| }); | ||
|
|
||
| it('should have the correct response types', function () { | ||
| assert.ok(GetV2PingExpress.response[200]); | ||
| assert.ok(GetV2PingExpress.response[404]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Supertest Integration Tests', function () { | ||
| const agent = setupAgent(); | ||
|
|
||
| const expectedStatus = 'express server is ok!'; | ||
|
|
||
| it('should resolve GET /api/v1/pingexpress with the expected payload', async function () { | ||
| const result = await agent.get('/api/v1/pingexpress'); | ||
|
|
||
| assert.strictEqual(result.status, 200); | ||
| result.body.should.have.property('status'); | ||
| assert.strictEqual(result.body.status, expectedStatus); | ||
|
|
||
| const decodedResponse = assertDecode(GetV1PingExpress.response[200], result.body); | ||
| assert.strictEqual(decodedResponse.status, expectedStatus); | ||
| }); | ||
|
|
||
| it('should resolve GET /api/v2/pingexpress with the expected payload', async function () { | ||
| const result = await agent.get('/api/v2/pingexpress'); | ||
|
|
||
| assert.strictEqual(result.status, 200); | ||
| result.body.should.have.property('status'); | ||
| assert.strictEqual(result.body.status, expectedStatus); | ||
|
|
||
| const decodedResponse = assertDecode(GetV2PingExpress.response[200], result.body); | ||
| assert.strictEqual(decodedResponse.status, expectedStatus); | ||
| }); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a minimal test that both GET
/api/v1/pingexpressand GET/api/v2/pingexpressresolve and return the expected payload