Skip to content

Commit ec4b22d

Browse files
Merge pull request #996 from appwrite/feat-ping-endpoint
feat: ping endpoint
2 parents 0acceab + fc77e23 commit ec4b22d

File tree

12 files changed

+55
-0
lines changed

12 files changed

+55
-0
lines changed

mock-server/app/http.php

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

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

templates/node/src/client.ts.twig

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

243+
async ping(): Promise<string> {
244+
return this.call('GET', new URL(this.config.endpoint + '/ping'));
245+
}
246+
243247
async redirect(method: string, url: URL, headers: Headers = {}, params: Payload = {}): Promise<string> {
244248
const { uri, options } = this.prepareRequest(method, url, headers, params);
245249

templates/web/src/client.ts.twig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,10 @@ class Client {
634634
return response;
635635
}
636636

637+
async ping(): Promise<string> {
638+
return this.call('GET', new URL(this.config.endpoint + '/ping'));
639+
}
640+
637641
async call(method: string, url: URL, headers: Headers = {}, params: Payload = {}, responseType = 'json'): Promise<any> {
638642
const { uri, options } = this.prepareRequest(method, url, headers, params);
639643

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/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/WebChromiumTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class WebChromiumTest extends Base
2121
'docker run --network="mockapi" --rm -v $(pwd):/app -e BROWSER=chromium -w /app/tests/sdks/web mcr.microsoft.com/playwright:v1.15.0-focal node tests.js';
2222

2323
protected array $expectedOutput = [
24+
...Base::PING_RESPONSE,
2425
...Base::FOO_RESPONSES,
2526
...Base::BAR_RESPONSES,
2627
...Base::GENERAL_RESPONSES,

tests/WebNodeTest.php

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

2424
protected array $expectedOutput = [
25+
...Base::PING_RESPONSE,
2526
...Base::FOO_RESPONSES,
2627
...Base::BAR_RESPONSES,
2728
...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)