Skip to content

Commit f688087

Browse files
committed
feat: ping endpoint
1 parent 4e9f23e commit f688087

File tree

7 files changed

+37
-0
lines changed

7 files changed

+37
-0
lines changed

mock-server/app/http.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@
6868
});
6969

7070
// Mock Routes
71+
App::get('/v1/ping')
72+
->desc('Get version')
73+
->groups(['api'])
74+
->label('scope', 'public')
75+
->label('sdk.response.code', Response::STATUS_CODE_OK)
76+
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
77+
->inject('response')
78+
->param('projectId', '', new Text(256), 'Project ID')
79+
->action(function () {
80+
if (empty($projectId)) {
81+
throw new Exception(Exception::GENERAL_MOCK, 'Missing project ID');
82+
}
83+
84+
if ($projectId !== '123456') {
85+
throw new Exception(Exception::GENERAL_MOCK, 'Invalid project ID');
86+
}
87+
});
88+
7189
App::get('/v1/mock/tests/foo')
7290
->desc('Get Foo')
7391
->groups(['mock'])

templates/node/src/client.ts.twig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ class Client {
240240
return response;
241241
}
242242

243+
async ping(): Promise<{ pingCount: number, pingedAt: Date }> {
244+
return this.call('GET', new URL('/ping', this.config.endpoint), {}, {
245+
'projectId': this.config.projectId,
246+
}, 'json');
247+
}
248+
243249
async redirect(method: string, url: URL, headers: Headers = {}, params: Payload = {}): Promise<string> {
244250
const { uri, options } = this.prepareRequest(method, url, headers, params);
245251

tests/Base.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
abstract class Base extends TestCase
1818
{
19+
protected const PING_RESPONSE = [
20+
'GET:/v1/mock/tests/ping:passed',
21+
];
22+
1923
protected const FOO_RESPONSES = [
2024
'GET:/v1/mock/tests/foo:passed',
2125
'POST:/v1/mock/tests/foo:passed',

tests/Node16Test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Node16Test extends Base
2020
'docker run --network="mockapi" --rm -v $(pwd):/app -w /app node:16-alpine node tests/sdks/node/test.js';
2121

2222
protected array $expectedOutput = [
23+
...Base::PING_RESPONSE,
2324
...Base::FOO_RESPONSES,
2425
...Base::BAR_RESPONSES,
2526
...Base::GENERAL_RESPONSES,

tests/Node18Test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Node18Test extends Base
2020
'docker run --network="mockapi" --rm -v $(pwd):/app -w /app node:18-alpine node tests/sdks/node/test.js';
2121

2222
protected array $expectedOutput = [
23+
...Base::PING_RESPONSE,
2324
...Base::FOO_RESPONSES,
2425
...Base::BAR_RESPONSES,
2526
...Base::GENERAL_RESPONSES,

tests/Node20Test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Node20Test extends Base
2020
'docker run --network="mockapi" --rm -v $(pwd):/app -w /app node:20-alpine node tests/sdks/node/test.js';
2121

2222
protected array $expectedOutput = [
23+
...Base::PING_RESPONSE,
2324
...Base::FOO_RESPONSES,
2425
...Base::BAR_RESPONSES,
2526
...Base::GENERAL_RESPONSES,

tests/languages/node/test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ async function start() {
1818
// Init SDK
1919
const client = new Client()
2020
.addHeader("Origin", "http://localhost")
21+
.setProject('123456')
2122
.setSelfSigned(true);
2223

2324
const foo = new Foo(client);
@@ -28,6 +29,11 @@ async function start() {
2829

2930
console.log('\nTest Started');
3031

32+
// Ping
33+
34+
response = await client.ping();
35+
console.log(response.result);
36+
3137
// Foo
3238

3339
response = await foo.get('string', 123, ['string in array']);

0 commit comments

Comments
 (0)