Skip to content

Commit

Permalink
feat(web): ping endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
loks0n committed Oct 7, 2024
1 parent f688087 commit bf4ba7c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
6 changes: 2 additions & 4 deletions templates/node/src/client.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,8 @@ class Client {
return response;
}

async ping(): Promise<{ pingCount: number, pingedAt: Date }> {
return this.call('GET', new URL('/ping', this.config.endpoint), {}, {
'projectId': this.config.projectId,
}, 'json');
async ping(): Promise<string> {
return this.call('GET', new URL('/ping', this.config.endpoint), {}, {}, 'json');
}

async redirect(method: string, url: URL, headers: Headers = {}, params: Payload = {}): Promise<string> {
Expand Down
4 changes: 4 additions & 0 deletions templates/web/src/client.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,10 @@ class Client {
return response;
}

async ping(): Promise<string> {
return this.call('GET', new URL('/ping', this.config.endpoint), {}, {}, 'json');
}

async call(method: string, url: URL, headers: Headers = {}, params: Payload = {}, responseType = 'json'): Promise<any> {
const { uri, options } = this.prepareRequest(method, url, headers, params);

Expand Down
1 change: 1 addition & 0 deletions tests/WebChromiumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class WebChromiumTest extends Base
'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';

protected array $expectedOutput = [
...Base::PING_RESPONSE,
...Base::FOO_RESPONSES,
...Base::BAR_RESPONSES,
...Base::GENERAL_RESPONSES,
Expand Down
1 change: 1 addition & 0 deletions tests/WebNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class WebNodeTest extends Base
'docker run --network="mockapi" --rm -v $(pwd):/app -w /app/tests/sdks/web node:18-alpine node node.js';

protected array $expectedOutput = [
...Base::PING_RESPONSE,
...Base::FOO_RESPONSES,
...Base::BAR_RESPONSES,
...Base::GENERAL_RESPONSES,
Expand Down
7 changes: 7 additions & 0 deletions tests/languages/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
document.getElementById("start").addEventListener("click", async () => {
let response;
let responseRealtime = 'Realtime failed!';

// Init SDK
const { Client, Foo, Bar, General, Query, Permission, Role, ID, MockType } = Appwrite;
const client = new Client();
Expand All @@ -27,6 +28,12 @@
const bar = new Bar(client);
const general = new General(client);

// Ping
client.setProject('123456');
response = await client.ping();
console.log(response.result);

// Realtime setup
client.setProject('console');
client.setEndpointRealtime('ws://demo.appwrite.io/v1');

Expand Down
6 changes: 6 additions & 0 deletions tests/languages/web/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ async function start() {

console.log('\nTest Started');
const client = new Client();
client.setProject('123456');
const foo = new Foo(client);
const bar = new Bar(client);
const general = new General(client);

// Ping
response = await client.ping();
console.log(response.result);

// Foo
response = await foo.get('string', 123, ['string in array']);
console.log(response.result);
Expand Down

0 comments on commit bf4ba7c

Please sign in to comment.