diff --git a/templates/dart/lib/src/client.dart.twig b/templates/dart/lib/src/client.dart.twig index 5e386223f..09986d05c 100644 --- a/templates/dart/lib/src/client.dart.twig +++ b/templates/dart/lib/src/client.dart.twig @@ -48,6 +48,9 @@ abstract class Client { /// Add headers that should be sent with all API calls. Client addHeader(String key, String value); + /// Sends a "ping" request to Appwrite to verify connectivity. + Future ping(); + /// Upload a file in chunks. Future chunkedUpload({ required String path, diff --git a/templates/dart/lib/src/client_base.dart.twig b/templates/dart/lib/src/client_base.dart.twig index b0c41ffeb..f3137281d 100644 --- a/templates/dart/lib/src/client_base.dart.twig +++ b/templates/dart/lib/src/client_base.dart.twig @@ -20,6 +20,9 @@ abstract class ClientBase implements Client { @override ClientBase addHeader(String key, String value); + @override + Future ping(); + @override Future call( HttpMethod method, { diff --git a/templates/dart/lib/src/client_browser.dart.twig b/templates/dart/lib/src/client_browser.dart.twig index 6a0f046fd..41d9860c9 100644 --- a/templates/dart/lib/src/client_browser.dart.twig +++ b/templates/dart/lib/src/client_browser.dart.twig @@ -77,6 +77,14 @@ class ClientBrowser extends ClientBase with ClientMixin { return this; } + @override + Future ping() async { + final String apiPath = '/ping'; + final response = await call(HttpMethod.get, path: apiPath, responseType: ResponseType.plain); + + return response.data; + } + @override Future webAuth(Uri url) async { final request = http.Request('GET', url); diff --git a/templates/dart/lib/src/client_io.dart.twig b/templates/dart/lib/src/client_io.dart.twig index 8a51e5979..09a3ca6a3 100644 --- a/templates/dart/lib/src/client_io.dart.twig +++ b/templates/dart/lib/src/client_io.dart.twig @@ -89,6 +89,14 @@ class ClientIO extends ClientBase with ClientMixin { return this; } + @override + Future ping() async { + final String apiPath = '/ping'; + final response = await call(HttpMethod.get, path: apiPath, responseType: ResponseType.plain); + + return response.data; + } + @override Future chunkedUpload({ required String path, diff --git a/tests/DartBetaTest.php b/tests/DartBetaTest.php index 816620260..af0165ab9 100644 --- a/tests/DartBetaTest.php +++ b/tests/DartBetaTest.php @@ -19,6 +19,7 @@ class DartBetaTest extends Base 'docker run --network="mockapi" --rm -v $(pwd):/app -w /app/tests/sdks/dart dart:beta sh -c "dart pub get && dart pub run tests/tests.dart"'; protected array $expectedOutput = [ + ...Base::PING_RESPONSE, ...Base::FOO_RESPONSES, ...Base::BAR_RESPONSES, ...Base::GENERAL_RESPONSES, diff --git a/tests/DartStableTest.php b/tests/DartStableTest.php index f55acae99..1aaafd33a 100644 --- a/tests/DartStableTest.php +++ b/tests/DartStableTest.php @@ -19,6 +19,7 @@ class DartStableTest extends Base 'docker run --network="mockapi" --rm -v $(pwd):/app -w /app/tests/sdks/dart dart:stable sh -c "dart pub get && dart pub run tests/tests.dart"'; protected array $expectedOutput = [ + ...Base::PING_RESPONSE, ...Base::FOO_RESPONSES, ...Base::BAR_RESPONSES, ...Base::GENERAL_RESPONSES, diff --git a/tests/languages/dart/tests.dart b/tests/languages/dart/tests.dart index 5682307ae..32ab2cd91 100644 --- a/tests/languages/dart/tests.dart +++ b/tests/languages/dart/tests.dart @@ -4,6 +4,7 @@ import '../lib/enums.dart'; import '../lib/src/input_file.dart'; import 'dart:io'; +import 'dart:convert'; void main() async { Client client = Client().setSelfSigned(); @@ -15,7 +16,16 @@ void main() async { client.setSelfSigned(); print('\nTest Started'); - + + // Ping pong test + client.setProject('123456'); + final ping = await client.ping(); + final pingResponse = parse(ping)!; + print(pingResponse); + + // reset project. + client.setProject('console'); + // Foo Tests Mock response; response = await foo.get(x: 'string', y: 123, z: ['string in array']); @@ -164,3 +174,11 @@ void main() async { response = await general.headers(); print(response.result); } + +String? parse(String json) { + try { + return jsonDecode(json)['result'] as String?; + } catch (_) { + return null; + } +}