From b75a1482f6cd0ac6bdf1134b7ab334b58d018428 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 21 Jun 2023 09:19:50 +0000 Subject: [PATCH 1/2] added test --- README.md | 4 +- .../account/create-anonymous-session.md | 2 +- docs/examples/account/create-email-session.md | 2 +- docs/examples/account/create-j-w-t.md | 2 +- .../account/create-magic-u-r-l-session.md | 2 +- .../examples/account/create-o-auth2session.md | 2 +- docs/examples/account/create-phone-session.md | 2 +- .../account/create-phone-verification.md | 2 +- docs/examples/account/create-recovery.md | 2 +- docs/examples/account/create-verification.md | 2 +- docs/examples/account/create.md | 2 +- docs/examples/account/delete-session.md | 2 +- docs/examples/account/delete-sessions.md | 2 +- docs/examples/account/get-prefs.md | 2 +- docs/examples/account/get-session.md | 2 +- docs/examples/account/get.md | 2 +- docs/examples/account/list-logs.md | 2 +- docs/examples/account/list-sessions.md | 2 +- docs/examples/account/update-email.md | 2 +- .../account/update-magic-u-r-l-session.md | 2 +- docs/examples/account/update-name.md | 2 +- docs/examples/account/update-password.md | 2 +- docs/examples/account/update-phone-session.md | 2 +- .../account/update-phone-verification.md | 2 +- docs/examples/account/update-phone.md | 2 +- docs/examples/account/update-prefs.md | 2 +- docs/examples/account/update-recovery.md | 2 +- docs/examples/account/update-session.md | 2 +- docs/examples/account/update-status.md | 2 +- docs/examples/account/update-verification.md | 2 +- docs/examples/avatars/get-browser.md | 2 +- docs/examples/avatars/get-credit-card.md | 2 +- docs/examples/avatars/get-favicon.md | 2 +- docs/examples/avatars/get-flag.md | 2 +- docs/examples/avatars/get-image.md | 2 +- docs/examples/avatars/get-initials.md | 2 +- docs/examples/avatars/get-q-r.md | 2 +- docs/examples/databases/create-document.md | 2 +- docs/examples/databases/delete-document.md | 2 +- docs/examples/databases/get-document.md | 2 +- docs/examples/databases/list-documents.md | 2 +- docs/examples/databases/update-document.md | 2 +- docs/examples/functions/create-execution.md | 2 +- docs/examples/functions/get-execution.md | 2 +- docs/examples/functions/list-executions.md | 2 +- docs/examples/graphql/mutation.md | 2 +- docs/examples/graphql/query.md | 2 +- docs/examples/locale/get.md | 2 +- docs/examples/locale/list-continents.md | 2 +- docs/examples/locale/list-countries-e-u.md | 2 +- docs/examples/locale/list-countries-phones.md | 2 +- docs/examples/locale/list-countries.md | 2 +- docs/examples/locale/list-currencies.md | 2 +- docs/examples/locale/list-languages.md | 2 +- docs/examples/storage/create-file.md | 2 +- docs/examples/storage/delete-file.md | 2 +- docs/examples/storage/get-file-download.md | 2 +- docs/examples/storage/get-file-preview.md | 2 +- docs/examples/storage/get-file-view.md | 2 +- docs/examples/storage/get-file.md | 2 +- docs/examples/storage/list-files.md | 2 +- docs/examples/storage/update-file.md | 2 +- docs/examples/teams/create-membership.md | 2 +- docs/examples/teams/create.md | 2 +- docs/examples/teams/delete-membership.md | 2 +- docs/examples/teams/delete.md | 2 +- docs/examples/teams/get-membership.md | 2 +- docs/examples/teams/get-prefs.md | 2 +- docs/examples/teams/get.md | 2 +- docs/examples/teams/list-memberships.md | 2 +- docs/examples/teams/list.md | 2 +- .../examples/teams/update-membership-roles.md | 2 +- .../teams/update-membership-status.md | 2 +- docs/examples/teams/update-name.md | 2 +- docs/examples/teams/update-prefs.md | 2 +- lib/appwrite.dart | 5 + lib/id.dart | 19 +- lib/models.dart | 1 + lib/permission.dart | 45 +- lib/query.dart | 70 +- lib/role.dart | 23 + lib/services/account.dart | 32 +- lib/services/avatars.dart | 12 +- lib/services/databases.dart | 10 +- lib/services/functions.dart | 8 +- lib/services/graphql.dart | 7 +- lib/services/locale.dart | 12 +- lib/services/storage.dart | 11 +- lib/services/teams.dart | 18 +- lib/src/client.dart | 30 +- lib/src/client_browser.dart | 2 +- lib/src/client_io.dart | 2 +- lib/src/enums.dart | 2 + lib/src/exception.dart | 13 +- lib/src/input_file.dart | 5 +- lib/src/realtime.dart | 5 +- lib/src/realtime_message.dart | 19 + lib/src/realtime_subscription.dart | 5 + lib/src/response.dart | 3 + lib/src/upload_progress.dart | 17 + pubspec.yaml | 21 +- test/id_test.dart | 16 + test/permission_test.dart | 34 + test/query_test.dart | 192 +++++ test/role_test.dart | 52 ++ test/services/account_test.dart | 809 ++++++++++++++++++ test/services/avatars_test.dart | 155 ++++ test/services/databases_test.dart | 165 ++++ test/services/functions_test.dart | 133 +++ test/services/graphql_test.dart | 84 ++ test/services/locale_test.dart | 182 ++++ test/services/storage_test.dart | 224 +++++ test/services/teams_test.dart | 341 ++++++++ test/src/cookie_manager_test.dart | 99 +++ test/src/enums_test.dart | 12 + test/src/exception_test.dart | 17 + test/src/input_file_test.dart | 47 + test/src/interceptor_test.dart | 39 + test/src/models/algo_argon2_test.dart | 24 + test/src/models/algo_bcrypt_test.dart | 18 + test/src/models/algo_md5_test.dart | 18 + test/src/models/algo_phpass_test.dart | 18 + .../src/models/algo_scrypt_modified_test.dart | 24 + test/src/models/algo_scrypt_test.dart | 26 + test/src/models/algo_sha_test.dart | 18 + test/src/models/continent_list_test.dart | 20 + test/src/models/continent_test.dart | 20 + test/src/models/country_list_test.dart | 20 + test/src/models/country_test.dart | 20 + test/src/models/currency_list_test.dart | 20 + test/src/models/currency_test.dart | 30 + test/src/models/document_list_test.dart | 20 + test/src/models/document_test.dart | 29 + test/src/models/execution_list_test.dart | 20 + test/src/models/execution_test.dart | 40 + test/src/models/file_list_test.dart | 20 + test/src/models/file_test.dart | 38 + test/src/models/jwt_test.dart | 18 + test/src/models/language_list_test.dart | 20 + test/src/models/language_test.dart | 22 + test/src/models/locale_test.dart | 30 + test/src/models/log_list_test.dart | 20 + test/src/models/log_test.dart | 58 ++ test/src/models/membership_list_test.dart | 20 + test/src/models/membership_test.dart | 40 + test/src/models/phone_list_test.dart | 20 + test/src/models/phone_test.dart | 22 + test/src/models/preferences_test.dart | 17 + test/src/models/session_list_test.dart | 20 + test/src/models/session_test.dart | 66 ++ test/src/models/team_list_test.dart | 20 + test/src/models/team_test.dart | 28 + test/src/models/token_test.dart | 26 + test/src/models/user_test.dart | 40 + .../src/realtime_response_connected_test.dart | 68 ++ test/src/realtime_response_test.dart | 69 ++ test/src/realtime_subscription_test.dart | 21 + test/src/response_test.dart | 18 + test/src/upload_progress_test.dart | 90 ++ 159 files changed, 4131 insertions(+), 215 deletions(-) create mode 100644 test/id_test.dart create mode 100644 test/permission_test.dart create mode 100644 test/query_test.dart create mode 100644 test/role_test.dart create mode 100644 test/services/account_test.dart create mode 100644 test/services/avatars_test.dart create mode 100644 test/services/databases_test.dart create mode 100644 test/services/functions_test.dart create mode 100644 test/services/graphql_test.dart create mode 100644 test/services/locale_test.dart create mode 100644 test/services/storage_test.dart create mode 100644 test/services/teams_test.dart create mode 100644 test/src/cookie_manager_test.dart create mode 100644 test/src/enums_test.dart create mode 100644 test/src/exception_test.dart create mode 100644 test/src/input_file_test.dart create mode 100644 test/src/interceptor_test.dart create mode 100644 test/src/models/algo_argon2_test.dart create mode 100644 test/src/models/algo_bcrypt_test.dart create mode 100644 test/src/models/algo_md5_test.dart create mode 100644 test/src/models/algo_phpass_test.dart create mode 100644 test/src/models/algo_scrypt_modified_test.dart create mode 100644 test/src/models/algo_scrypt_test.dart create mode 100644 test/src/models/algo_sha_test.dart create mode 100644 test/src/models/continent_list_test.dart create mode 100644 test/src/models/continent_test.dart create mode 100644 test/src/models/country_list_test.dart create mode 100644 test/src/models/country_test.dart create mode 100644 test/src/models/currency_list_test.dart create mode 100644 test/src/models/currency_test.dart create mode 100644 test/src/models/document_list_test.dart create mode 100644 test/src/models/document_test.dart create mode 100644 test/src/models/execution_list_test.dart create mode 100644 test/src/models/execution_test.dart create mode 100644 test/src/models/file_list_test.dart create mode 100644 test/src/models/file_test.dart create mode 100644 test/src/models/jwt_test.dart create mode 100644 test/src/models/language_list_test.dart create mode 100644 test/src/models/language_test.dart create mode 100644 test/src/models/locale_test.dart create mode 100644 test/src/models/log_list_test.dart create mode 100644 test/src/models/log_test.dart create mode 100644 test/src/models/membership_list_test.dart create mode 100644 test/src/models/membership_test.dart create mode 100644 test/src/models/phone_list_test.dart create mode 100644 test/src/models/phone_test.dart create mode 100644 test/src/models/preferences_test.dart create mode 100644 test/src/models/session_list_test.dart create mode 100644 test/src/models/session_test.dart create mode 100644 test/src/models/team_list_test.dart create mode 100644 test/src/models/team_test.dart create mode 100644 test/src/models/token_test.dart create mode 100644 test/src/models/user_test.dart create mode 100644 test/src/realtime_response_connected_test.dart create mode 100644 test/src/realtime_response_test.dart create mode 100644 test/src/realtime_subscription_test.dart create mode 100644 test/src/response_test.dart create mode 100644 test/src/upload_progress_test.dart diff --git a/README.md b/README.md index 79045b6..b4dbfc8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![pub package](https://img.shields.io/pub/v/appwrite?style=flat-square)](https://pub.dartlang.org/packages/appwrite) ![License](https://img.shields.io/github/license/appwrite/sdk-for-flutter.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.3.0-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.3.x-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) @@ -21,7 +21,7 @@ Add this to your package's `pubspec.yaml` file: ```yml dependencies: - appwrite: ^9.0.0 + appwrite: ^9.0.1 ``` You can install packages from the command line: diff --git a/docs/examples/account/create-anonymous-session.md b/docs/examples/account/create-anonymous-session.md index 01b4374..2f3e7a6 100644 --- a/docs/examples/account/create-anonymous-session.md +++ b/docs/examples/account/create-anonymous-session.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.createAnonymousSession(); diff --git a/docs/examples/account/create-email-session.md b/docs/examples/account/create-email-session.md index 6cbb227..52b6b91 100644 --- a/docs/examples/account/create-email-session.md +++ b/docs/examples/account/create-email-session.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.createEmailSession( diff --git a/docs/examples/account/create-j-w-t.md b/docs/examples/account/create-j-w-t.md index f88c7ad..c4a61f7 100644 --- a/docs/examples/account/create-j-w-t.md +++ b/docs/examples/account/create-j-w-t.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.createJWT(); diff --git a/docs/examples/account/create-magic-u-r-l-session.md b/docs/examples/account/create-magic-u-r-l-session.md index 4d36b45..d1b89bf 100644 --- a/docs/examples/account/create-magic-u-r-l-session.md +++ b/docs/examples/account/create-magic-u-r-l-session.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.createMagicURLSession( diff --git a/docs/examples/account/create-o-auth2session.md b/docs/examples/account/create-o-auth2session.md index a100378..e985a92 100644 --- a/docs/examples/account/create-o-auth2session.md +++ b/docs/examples/account/create-o-auth2session.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.createOAuth2Session( diff --git a/docs/examples/account/create-phone-session.md b/docs/examples/account/create-phone-session.md index f71c3d0..fcb705c 100644 --- a/docs/examples/account/create-phone-session.md +++ b/docs/examples/account/create-phone-session.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.createPhoneSession( diff --git a/docs/examples/account/create-phone-verification.md b/docs/examples/account/create-phone-verification.md index ee16f76..76e724d 100644 --- a/docs/examples/account/create-phone-verification.md +++ b/docs/examples/account/create-phone-verification.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.createPhoneVerification(); diff --git a/docs/examples/account/create-recovery.md b/docs/examples/account/create-recovery.md index 2a5df1a..361a9f0 100644 --- a/docs/examples/account/create-recovery.md +++ b/docs/examples/account/create-recovery.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.createRecovery( diff --git a/docs/examples/account/create-verification.md b/docs/examples/account/create-verification.md index 18fa98a..d66c3b1 100644 --- a/docs/examples/account/create-verification.md +++ b/docs/examples/account/create-verification.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.createVerification( diff --git a/docs/examples/account/create.md b/docs/examples/account/create.md index bd5ba35..1ff2ae9 100644 --- a/docs/examples/account/create.md +++ b/docs/examples/account/create.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.create( diff --git a/docs/examples/account/delete-session.md b/docs/examples/account/delete-session.md index c116ef1..9146561 100644 --- a/docs/examples/account/delete-session.md +++ b/docs/examples/account/delete-session.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.deleteSession( diff --git a/docs/examples/account/delete-sessions.md b/docs/examples/account/delete-sessions.md index 0d84b9d..4963de4 100644 --- a/docs/examples/account/delete-sessions.md +++ b/docs/examples/account/delete-sessions.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.deleteSessions(); diff --git a/docs/examples/account/get-prefs.md b/docs/examples/account/get-prefs.md index 2d6efd5..81eb802 100644 --- a/docs/examples/account/get-prefs.md +++ b/docs/examples/account/get-prefs.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.getPrefs(); diff --git a/docs/examples/account/get-session.md b/docs/examples/account/get-session.md index 4d93a81..9e0f66c 100644 --- a/docs/examples/account/get-session.md +++ b/docs/examples/account/get-session.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.getSession( diff --git a/docs/examples/account/get.md b/docs/examples/account/get.md index 733d884..21192de 100644 --- a/docs/examples/account/get.md +++ b/docs/examples/account/get.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.get(); diff --git a/docs/examples/account/list-logs.md b/docs/examples/account/list-logs.md index 965378c..9f7088a 100644 --- a/docs/examples/account/list-logs.md +++ b/docs/examples/account/list-logs.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.listLogs( diff --git a/docs/examples/account/list-sessions.md b/docs/examples/account/list-sessions.md index ac370b0..6f2d5dc 100644 --- a/docs/examples/account/list-sessions.md +++ b/docs/examples/account/list-sessions.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.listSessions(); diff --git a/docs/examples/account/update-email.md b/docs/examples/account/update-email.md index 30dff9b..1fb9a3f 100644 --- a/docs/examples/account/update-email.md +++ b/docs/examples/account/update-email.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.updateEmail( diff --git a/docs/examples/account/update-magic-u-r-l-session.md b/docs/examples/account/update-magic-u-r-l-session.md index 9688110..3c7ef8f 100644 --- a/docs/examples/account/update-magic-u-r-l-session.md +++ b/docs/examples/account/update-magic-u-r-l-session.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.updateMagicURLSession( diff --git a/docs/examples/account/update-name.md b/docs/examples/account/update-name.md index 01ff7a0..ae5d623 100644 --- a/docs/examples/account/update-name.md +++ b/docs/examples/account/update-name.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.updateName( diff --git a/docs/examples/account/update-password.md b/docs/examples/account/update-password.md index d70a2c2..b5e86de 100644 --- a/docs/examples/account/update-password.md +++ b/docs/examples/account/update-password.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.updatePassword( diff --git a/docs/examples/account/update-phone-session.md b/docs/examples/account/update-phone-session.md index 2125266..1f97926 100644 --- a/docs/examples/account/update-phone-session.md +++ b/docs/examples/account/update-phone-session.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.updatePhoneSession( diff --git a/docs/examples/account/update-phone-verification.md b/docs/examples/account/update-phone-verification.md index 9ad71fe..86d9b0f 100644 --- a/docs/examples/account/update-phone-verification.md +++ b/docs/examples/account/update-phone-verification.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.updatePhoneVerification( diff --git a/docs/examples/account/update-phone.md b/docs/examples/account/update-phone.md index a3b1ccc..edfe478 100644 --- a/docs/examples/account/update-phone.md +++ b/docs/examples/account/update-phone.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.updatePhone( diff --git a/docs/examples/account/update-prefs.md b/docs/examples/account/update-prefs.md index bb7b8f8..9769708 100644 --- a/docs/examples/account/update-prefs.md +++ b/docs/examples/account/update-prefs.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.updatePrefs( diff --git a/docs/examples/account/update-recovery.md b/docs/examples/account/update-recovery.md index df9f144..f499b18 100644 --- a/docs/examples/account/update-recovery.md +++ b/docs/examples/account/update-recovery.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.updateRecovery( diff --git a/docs/examples/account/update-session.md b/docs/examples/account/update-session.md index 37fd58c..fb1afcc 100644 --- a/docs/examples/account/update-session.md +++ b/docs/examples/account/update-session.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.updateSession( diff --git a/docs/examples/account/update-status.md b/docs/examples/account/update-status.md index fb3790e..8e73464 100644 --- a/docs/examples/account/update-status.md +++ b/docs/examples/account/update-status.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.updateStatus(); diff --git a/docs/examples/account/update-verification.md b/docs/examples/account/update-verification.md index 2bfbaed..fba8ed6 100644 --- a/docs/examples/account/update-verification.md +++ b/docs/examples/account/update-verification.md @@ -5,7 +5,7 @@ void main() { // Init SDK Account account = Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = account.updateVerification( diff --git a/docs/examples/avatars/get-browser.md b/docs/examples/avatars/get-browser.md index f908d11..70af566 100644 --- a/docs/examples/avatars/get-browser.md +++ b/docs/examples/avatars/get-browser.md @@ -5,7 +5,7 @@ void main() { // Init SDK Avatars avatars = Avatars(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; // downloading file diff --git a/docs/examples/avatars/get-credit-card.md b/docs/examples/avatars/get-credit-card.md index 0c6ff01..6a29dc8 100644 --- a/docs/examples/avatars/get-credit-card.md +++ b/docs/examples/avatars/get-credit-card.md @@ -5,7 +5,7 @@ void main() { // Init SDK Avatars avatars = Avatars(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; // downloading file diff --git a/docs/examples/avatars/get-favicon.md b/docs/examples/avatars/get-favicon.md index 6df7c2d..2da0f2e 100644 --- a/docs/examples/avatars/get-favicon.md +++ b/docs/examples/avatars/get-favicon.md @@ -5,7 +5,7 @@ void main() { // Init SDK Avatars avatars = Avatars(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; // downloading file diff --git a/docs/examples/avatars/get-flag.md b/docs/examples/avatars/get-flag.md index fa5b60d..1336788 100644 --- a/docs/examples/avatars/get-flag.md +++ b/docs/examples/avatars/get-flag.md @@ -5,7 +5,7 @@ void main() { // Init SDK Avatars avatars = Avatars(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; // downloading file diff --git a/docs/examples/avatars/get-image.md b/docs/examples/avatars/get-image.md index 219d160..debbf1e 100644 --- a/docs/examples/avatars/get-image.md +++ b/docs/examples/avatars/get-image.md @@ -5,7 +5,7 @@ void main() { // Init SDK Avatars avatars = Avatars(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; // downloading file diff --git a/docs/examples/avatars/get-initials.md b/docs/examples/avatars/get-initials.md index cd1b1f7..b0f49c6 100644 --- a/docs/examples/avatars/get-initials.md +++ b/docs/examples/avatars/get-initials.md @@ -5,7 +5,7 @@ void main() { // Init SDK Avatars avatars = Avatars(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; // downloading file diff --git a/docs/examples/avatars/get-q-r.md b/docs/examples/avatars/get-q-r.md index df6ebd3..8df7293 100644 --- a/docs/examples/avatars/get-q-r.md +++ b/docs/examples/avatars/get-q-r.md @@ -5,7 +5,7 @@ void main() { // Init SDK Avatars avatars = Avatars(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; // downloading file diff --git a/docs/examples/databases/create-document.md b/docs/examples/databases/create-document.md index 730dd21..6a03173 100644 --- a/docs/examples/databases/create-document.md +++ b/docs/examples/databases/create-document.md @@ -5,7 +5,7 @@ void main() { // Init SDK Databases databases = Databases(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = databases.createDocument( diff --git a/docs/examples/databases/delete-document.md b/docs/examples/databases/delete-document.md index 8dc6246..a377b02 100644 --- a/docs/examples/databases/delete-document.md +++ b/docs/examples/databases/delete-document.md @@ -5,7 +5,7 @@ void main() { // Init SDK Databases databases = Databases(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = databases.deleteDocument( diff --git a/docs/examples/databases/get-document.md b/docs/examples/databases/get-document.md index 71c88d6..b2cf89a 100644 --- a/docs/examples/databases/get-document.md +++ b/docs/examples/databases/get-document.md @@ -5,7 +5,7 @@ void main() { // Init SDK Databases databases = Databases(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = databases.getDocument( diff --git a/docs/examples/databases/list-documents.md b/docs/examples/databases/list-documents.md index 816a17d..4cd69e3 100644 --- a/docs/examples/databases/list-documents.md +++ b/docs/examples/databases/list-documents.md @@ -5,7 +5,7 @@ void main() { // Init SDK Databases databases = Databases(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = databases.listDocuments( diff --git a/docs/examples/databases/update-document.md b/docs/examples/databases/update-document.md index 29abff6..595099b 100644 --- a/docs/examples/databases/update-document.md +++ b/docs/examples/databases/update-document.md @@ -5,7 +5,7 @@ void main() { // Init SDK Databases databases = Databases(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = databases.updateDocument( diff --git a/docs/examples/functions/create-execution.md b/docs/examples/functions/create-execution.md index 70b617f..b188c32 100644 --- a/docs/examples/functions/create-execution.md +++ b/docs/examples/functions/create-execution.md @@ -5,7 +5,7 @@ void main() { // Init SDK Functions functions = Functions(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = functions.createExecution( diff --git a/docs/examples/functions/get-execution.md b/docs/examples/functions/get-execution.md index a10f793..f30b4b4 100644 --- a/docs/examples/functions/get-execution.md +++ b/docs/examples/functions/get-execution.md @@ -5,7 +5,7 @@ void main() { // Init SDK Functions functions = Functions(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = functions.getExecution( diff --git a/docs/examples/functions/list-executions.md b/docs/examples/functions/list-executions.md index 3f59aa3..1840f50 100644 --- a/docs/examples/functions/list-executions.md +++ b/docs/examples/functions/list-executions.md @@ -5,7 +5,7 @@ void main() { // Init SDK Functions functions = Functions(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = functions.listExecutions( diff --git a/docs/examples/graphql/mutation.md b/docs/examples/graphql/mutation.md index 0eba90f..c0bffce 100644 --- a/docs/examples/graphql/mutation.md +++ b/docs/examples/graphql/mutation.md @@ -5,7 +5,7 @@ void main() { // Init SDK Graphql graphql = Graphql(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = graphql.mutation( diff --git a/docs/examples/graphql/query.md b/docs/examples/graphql/query.md index d4a3d6e..455cb0b 100644 --- a/docs/examples/graphql/query.md +++ b/docs/examples/graphql/query.md @@ -5,7 +5,7 @@ void main() { // Init SDK Graphql graphql = Graphql(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = graphql.query( diff --git a/docs/examples/locale/get.md b/docs/examples/locale/get.md index 21b1a6c..9e9fa96 100644 --- a/docs/examples/locale/get.md +++ b/docs/examples/locale/get.md @@ -5,7 +5,7 @@ void main() { // Init SDK Locale locale = Locale(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = locale.get(); diff --git a/docs/examples/locale/list-continents.md b/docs/examples/locale/list-continents.md index be47ec2..0ab2a4a 100644 --- a/docs/examples/locale/list-continents.md +++ b/docs/examples/locale/list-continents.md @@ -5,7 +5,7 @@ void main() { // Init SDK Locale locale = Locale(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = locale.listContinents(); diff --git a/docs/examples/locale/list-countries-e-u.md b/docs/examples/locale/list-countries-e-u.md index 9f2a9ab..caa32e8 100644 --- a/docs/examples/locale/list-countries-e-u.md +++ b/docs/examples/locale/list-countries-e-u.md @@ -5,7 +5,7 @@ void main() { // Init SDK Locale locale = Locale(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = locale.listCountriesEU(); diff --git a/docs/examples/locale/list-countries-phones.md b/docs/examples/locale/list-countries-phones.md index 93d84ea..b122eee 100644 --- a/docs/examples/locale/list-countries-phones.md +++ b/docs/examples/locale/list-countries-phones.md @@ -5,7 +5,7 @@ void main() { // Init SDK Locale locale = Locale(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = locale.listCountriesPhones(); diff --git a/docs/examples/locale/list-countries.md b/docs/examples/locale/list-countries.md index 6eb8d42..e6a367d 100644 --- a/docs/examples/locale/list-countries.md +++ b/docs/examples/locale/list-countries.md @@ -5,7 +5,7 @@ void main() { // Init SDK Locale locale = Locale(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = locale.listCountries(); diff --git a/docs/examples/locale/list-currencies.md b/docs/examples/locale/list-currencies.md index eb8be0f..fcd1e82 100644 --- a/docs/examples/locale/list-currencies.md +++ b/docs/examples/locale/list-currencies.md @@ -5,7 +5,7 @@ void main() { // Init SDK Locale locale = Locale(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = locale.listCurrencies(); diff --git a/docs/examples/locale/list-languages.md b/docs/examples/locale/list-languages.md index 287f69b..1fb68aa 100644 --- a/docs/examples/locale/list-languages.md +++ b/docs/examples/locale/list-languages.md @@ -5,7 +5,7 @@ void main() { // Init SDK Locale locale = Locale(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = locale.listLanguages(); diff --git a/docs/examples/storage/create-file.md b/docs/examples/storage/create-file.md index 5c591ff..0f5e44f 100644 --- a/docs/examples/storage/create-file.md +++ b/docs/examples/storage/create-file.md @@ -6,7 +6,7 @@ void main() { // Init SDK Storage storage = Storage(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = storage.createFile( diff --git a/docs/examples/storage/delete-file.md b/docs/examples/storage/delete-file.md index ee193d9..230b73a 100644 --- a/docs/examples/storage/delete-file.md +++ b/docs/examples/storage/delete-file.md @@ -5,7 +5,7 @@ void main() { // Init SDK Storage storage = Storage(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = storage.deleteFile( diff --git a/docs/examples/storage/get-file-download.md b/docs/examples/storage/get-file-download.md index ea3f2ab..883b7d6 100644 --- a/docs/examples/storage/get-file-download.md +++ b/docs/examples/storage/get-file-download.md @@ -5,7 +5,7 @@ void main() { // Init SDK Storage storage = Storage(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; // downloading file diff --git a/docs/examples/storage/get-file-preview.md b/docs/examples/storage/get-file-preview.md index 1a0fca2..f42138b 100644 --- a/docs/examples/storage/get-file-preview.md +++ b/docs/examples/storage/get-file-preview.md @@ -5,7 +5,7 @@ void main() { // Init SDK Storage storage = Storage(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; // downloading file diff --git a/docs/examples/storage/get-file-view.md b/docs/examples/storage/get-file-view.md index 4605133..4f7c4d9 100644 --- a/docs/examples/storage/get-file-view.md +++ b/docs/examples/storage/get-file-view.md @@ -5,7 +5,7 @@ void main() { // Init SDK Storage storage = Storage(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; // downloading file diff --git a/docs/examples/storage/get-file.md b/docs/examples/storage/get-file.md index 26e5db0..681aca4 100644 --- a/docs/examples/storage/get-file.md +++ b/docs/examples/storage/get-file.md @@ -5,7 +5,7 @@ void main() { // Init SDK Storage storage = Storage(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = storage.getFile( diff --git a/docs/examples/storage/list-files.md b/docs/examples/storage/list-files.md index b1d095a..e574f7b 100644 --- a/docs/examples/storage/list-files.md +++ b/docs/examples/storage/list-files.md @@ -5,7 +5,7 @@ void main() { // Init SDK Storage storage = Storage(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = storage.listFiles( diff --git a/docs/examples/storage/update-file.md b/docs/examples/storage/update-file.md index 7105652..1170f05 100644 --- a/docs/examples/storage/update-file.md +++ b/docs/examples/storage/update-file.md @@ -5,7 +5,7 @@ void main() { // Init SDK Storage storage = Storage(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = storage.updateFile( diff --git a/docs/examples/teams/create-membership.md b/docs/examples/teams/create-membership.md index 6be423c..ac58c50 100644 --- a/docs/examples/teams/create-membership.md +++ b/docs/examples/teams/create-membership.md @@ -5,7 +5,7 @@ void main() { // Init SDK Teams teams = Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = teams.createMembership( diff --git a/docs/examples/teams/create.md b/docs/examples/teams/create.md index 5333ce3..bd62ce3 100644 --- a/docs/examples/teams/create.md +++ b/docs/examples/teams/create.md @@ -5,7 +5,7 @@ void main() { // Init SDK Teams teams = Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = teams.create( diff --git a/docs/examples/teams/delete-membership.md b/docs/examples/teams/delete-membership.md index 8192b85..0febe42 100644 --- a/docs/examples/teams/delete-membership.md +++ b/docs/examples/teams/delete-membership.md @@ -5,7 +5,7 @@ void main() { // Init SDK Teams teams = Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = teams.deleteMembership( diff --git a/docs/examples/teams/delete.md b/docs/examples/teams/delete.md index e55c62b..b45d971 100644 --- a/docs/examples/teams/delete.md +++ b/docs/examples/teams/delete.md @@ -5,7 +5,7 @@ void main() { // Init SDK Teams teams = Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = teams.delete( diff --git a/docs/examples/teams/get-membership.md b/docs/examples/teams/get-membership.md index 6abecfe..28d95a2 100644 --- a/docs/examples/teams/get-membership.md +++ b/docs/examples/teams/get-membership.md @@ -5,7 +5,7 @@ void main() { // Init SDK Teams teams = Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = teams.getMembership( diff --git a/docs/examples/teams/get-prefs.md b/docs/examples/teams/get-prefs.md index e242b17..e9ae94e 100644 --- a/docs/examples/teams/get-prefs.md +++ b/docs/examples/teams/get-prefs.md @@ -5,7 +5,7 @@ void main() { // Init SDK Teams teams = Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = teams.getPrefs( diff --git a/docs/examples/teams/get.md b/docs/examples/teams/get.md index 25eb245..0ec7027 100644 --- a/docs/examples/teams/get.md +++ b/docs/examples/teams/get.md @@ -5,7 +5,7 @@ void main() { // Init SDK Teams teams = Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = teams.get( diff --git a/docs/examples/teams/list-memberships.md b/docs/examples/teams/list-memberships.md index 67a6c15..cbbc525 100644 --- a/docs/examples/teams/list-memberships.md +++ b/docs/examples/teams/list-memberships.md @@ -5,7 +5,7 @@ void main() { // Init SDK Teams teams = Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = teams.listMemberships( diff --git a/docs/examples/teams/list.md b/docs/examples/teams/list.md index 8657f80..80aa301 100644 --- a/docs/examples/teams/list.md +++ b/docs/examples/teams/list.md @@ -5,7 +5,7 @@ void main() { // Init SDK Teams teams = Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = teams.list( diff --git a/docs/examples/teams/update-membership-roles.md b/docs/examples/teams/update-membership-roles.md index 7615752..6e96c01 100644 --- a/docs/examples/teams/update-membership-roles.md +++ b/docs/examples/teams/update-membership-roles.md @@ -5,7 +5,7 @@ void main() { // Init SDK Teams teams = Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = teams.updateMembershipRoles( diff --git a/docs/examples/teams/update-membership-status.md b/docs/examples/teams/update-membership-status.md index 7cda544..ed31f54 100644 --- a/docs/examples/teams/update-membership-status.md +++ b/docs/examples/teams/update-membership-status.md @@ -5,7 +5,7 @@ void main() { // Init SDK Teams teams = Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = teams.updateMembershipStatus( diff --git a/docs/examples/teams/update-name.md b/docs/examples/teams/update-name.md index d657002..5c794bd 100644 --- a/docs/examples/teams/update-name.md +++ b/docs/examples/teams/update-name.md @@ -5,7 +5,7 @@ void main() { // Init SDK Teams teams = Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = teams.updateName( diff --git a/docs/examples/teams/update-prefs.md b/docs/examples/teams/update-prefs.md index aab3322..c29cbb9 100644 --- a/docs/examples/teams/update-prefs.md +++ b/docs/examples/teams/update-prefs.md @@ -5,7 +5,7 @@ void main() { // Init SDK Teams teams = Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; Future result = teams.updatePrefs( diff --git a/lib/appwrite.dart b/lib/appwrite.dart index 1063831..c48f00f 100644 --- a/lib/appwrite.dart +++ b/lib/appwrite.dart @@ -1,3 +1,8 @@ +/// Appwrite Flutter SDK +/// +/// This SDK is compatible with Appwrite server version 1.3.x. +/// For older versions, please check +/// [previous releases](https://github.com/appwrite/sdk-for-flutter/releases). library appwrite; import 'dart:async'; diff --git a/lib/id.dart b/lib/id.dart index e32f001..1cfcee4 100644 --- a/lib/id.dart +++ b/lib/id.dart @@ -1,13 +1,16 @@ part of appwrite; +/// Helper class to generate ID strings for resources. class ID { - ID._(); - - static String unique() { - return 'unique()'; - } + ID._(); - static String custom(String id) { - return id; - } + /// Have Appwrite generate a unique ID for you. + static String unique() { + return 'unique()'; + } + + /// Uses [id] as the ID for the resource. + static String custom(String id) { + return id; + } } \ No newline at end of file diff --git a/lib/models.dart b/lib/models.dart index 898ea35..c8b0619 100644 --- a/lib/models.dart +++ b/lib/models.dart @@ -1,3 +1,4 @@ +/// Appwrite Models library appwrite.models; part 'src/models/model.dart'; diff --git a/lib/permission.dart b/lib/permission.dart index 5bc0cfd..370ac9e 100644 --- a/lib/permission.dart +++ b/lib/permission.dart @@ -1,21 +1,34 @@ part of appwrite; +/// Helper class to generate permission strings for resources. class Permission { - Permission._(); + Permission._(); - static String read(String role) { - return 'read("$role")'; - } - static String write(String role) { - return 'write("$role")'; - } - static String create(String role) { - return 'create("$role")'; - } - static String update(String role) { - return 'update("$role")'; - } - static String delete(String role) { - return 'delete("$role")'; - } + /// Read permission for provided [role] + static String read(String role) { + return 'read("$role")'; + } + + /// Write permission for provided [role] + /// + /// This is an alias of update, delete, and possibly create. + /// Don't use write in combination with update, delete, or create. + static String write(String role) { + return 'write("$role")'; + } + + /// Create permission for provided [role] + static String create(String role) { + return 'create("$role")'; + } + + /// Update permission for provided [role] + static String update(String role) { + return 'update("$role")'; + } + + /// Delete permission for provided [role] + static String delete(String role) { + return 'delete("$role")'; + } } diff --git a/lib/query.dart b/lib/query.dart index 7110e87..31a44c2 100644 --- a/lib/query.dart +++ b/lib/query.dart @@ -1,61 +1,117 @@ part of appwrite; +/// Helper class to generate query strings. class Query { - Query._(); - + Query._(); + + /// Filter resources where [attribute] is equal to [value]. + /// + /// [value] can be a single value or a list. If a list is used + /// the query will return resources where [attribute] is equal + /// to any of the values in the list. static String equal(String attribute, dynamic value) => _addQuery(attribute, 'equal', value); + /// Filter resources where [attribute] is not equal to [value]. + /// + /// [value] can be a single value or a list. If a list is used + /// the query will return resources where [attribute] is equal + /// to any of the values in the list. static String notEqual(String attribute, dynamic value) => _addQuery(attribute, 'notEqual', value); + /// Filter resources where [attribute] is less than [value]. + /// + /// [value] can be a single value or a list. If a list is used + /// the query will return resources where [attribute] is equal + /// to any of the values in the list. static String lessThan(String attribute, dynamic value) => _addQuery(attribute, 'lessThan', value); + /// Filter resources where [attribute] is less than or equal to [value]. + /// + /// [value] can be a single value or a list. If a list is used + /// the query will return resources where [attribute] is equal + /// to any of the values in the list. static String lessThanEqual(String attribute, dynamic value) => _addQuery(attribute, 'lessThanEqual', value); + /// Filter resources where [attribute] is greater than [value]. + /// + /// [value] can be a single value or a list. If a list is used + /// the query will return resources where [attribute] is equal + /// to any of the values in the list. static String greaterThan(String attribute, dynamic value) => _addQuery(attribute, 'greaterThan', value); + /// Filter resources where [attribute] is greater than or equal to [value]. + /// + /// [value] can be a single value or a list. If a list is used + /// the query will return resources where [attribute] is equal + /// to any of the values in the list. static String greaterThanEqual(String attribute, dynamic value) => _addQuery(attribute, 'greaterThanEqual', value); + /// Filter resources where by searching [attribute] for [value]. + /// + /// A fulltext index on [attribute] is required for this query to work. static String search(String attribute, String value) => _addQuery(attribute, 'search', value); + /// Filter resources where [attribute] is null. static String isNull(String attribute) => 'isNull("$attribute")'; + /// Filter resources where [attribute] is not null. static String isNotNull(String attribute) => 'isNotNull("$attribute")'; + /// Filter resources where [attribute] is between [start] and [end] (inclusive). static String between(String attribute, dynamic start, dynamic end) => _addQuery(attribute, 'between', [start, end]); + /// Filter resources where [attribute] starts with [value]. static String startsWith(String attribute, String value) => _addQuery(attribute, 'startsWith', value); + /// Filter resources where [attribute] ends with [value]. static String endsWith(String attribute, String value) => _addQuery(attribute, 'endsWith', value); - static String select(List attributes) => 'select([${attributes.map((attr) => "\"$attr\"").join(",")}])'; + /// Specify which attributes should be returned by the API call. + static String select(List attributes) => + 'select([${attributes.map((attr) => "\"$attr\"").join(",")}])'; + /// Sort results by [attribute] ascending. static String orderAsc(String attribute) => 'orderAsc("$attribute")'; + /// Sort results by [attribute] descending. static String orderDesc(String attribute) => 'orderDesc("$attribute")'; + /// Return results before [id]. + /// + /// Refer to the [Cursor Based Pagination](https://appwrite.io/docs/pagination#cursor-pagination) + /// docs for more information. static String cursorBefore(String id) => 'cursorBefore("$id")'; + /// Return results after [id]. + /// + /// Refer to the [Cursor Based Pagination](https://appwrite.io/docs/pagination#cursor-pagination) + /// docs for more information. static String cursorAfter(String id) => 'cursorAfter("$id")'; + /// Return only [limit] results. static String limit(int limit) => 'limit($limit)'; + /// Return results from [offset]. + /// + /// Refer to the [Offset Pagination](https://appwrite.io/docs/pagination#offset-pagination) + /// docs for more information. static String offset(int offset) => 'offset($offset)'; static String _addQuery(String attribute, String method, dynamic value) => (value is List) - ? '$method("$attribute", [${value.map((item) => parseValues(item)).join(",")}])' - : '$method("$attribute", [${parseValues(value)}])'; + ? '$method("$attribute", [${value.map((item) => _parseValues(item)).join(",")}])' + : '$method("$attribute", [${_parseValues(value)}])'; - static String parseValues(dynamic value) => + static String _parseValues(dynamic value) => (value is String) ? '"$value"' : '$value'; -} +} \ No newline at end of file diff --git a/lib/role.dart b/lib/role.dart index 445579e..9289d69 100644 --- a/lib/role.dart +++ b/lib/role.dart @@ -1,12 +1,20 @@ part of appwrite; +/// Helper class to generate role strings for [Permission]. class Role { Role._(); + /// Grants access to anyone. + /// + /// This includes authenticated and unauthenticated users. static String any() { return 'any'; } + /// Grants access to a specific user by user ID. + /// + /// You can optionally pass verified or unverified for + /// [status] to target specific types of users. static String user(String id, [String status = '']) { if(status.isEmpty) { return 'user:$id'; @@ -14,6 +22,10 @@ class Role { return 'user:$id/$status'; } + /// Grants access to any authenticated or anonymous user. + /// + /// You can optionally pass verified or unverified for + /// [status] to target specific types of users. static String users([String status = '']) { if(status.isEmpty) { return 'users'; @@ -21,10 +33,17 @@ class Role { return 'users/$status'; } + /// Grants access to any guest user without a session. + /// + /// Authenticated users don't have access to this role. static String guests() { return 'guests'; } + /// Grants access to a team by team ID. + /// + /// You can optionally pass a role for [role] to target + /// team members with the specified role. static String team(String id, [String role = '']) { if(role.isEmpty) { return 'team:$id'; @@ -32,6 +51,10 @@ class Role { return 'team:$id/$role'; } + /// Grants access to a specific member of a team. + /// + /// When the member is removed from the team, they will + /// no longer have access. static String member(String id) { return 'member:$id'; } diff --git a/lib/services/account.dart b/lib/services/account.dart index 96ba5bc..61118f2 100644 --- a/lib/services/account.dart +++ b/lib/services/account.dart @@ -1,13 +1,13 @@ part of appwrite; - /// The Account service allows you to authenticate and manage a user account. +/// The Account service allows you to authenticate and manage a user account. class Account extends Service { + /// Initializes a [Account] service Account(super.client); /// Get Account /// /// Get currently logged in user data as JSON object. - /// Future get() async { const String path = '/account'; @@ -32,7 +32,6 @@ class Account extends Service { /// route to start verifying the user email address. To allow the new user to /// login to their new account, you need to create a new [account /// session](/docs/client/account#accountCreateSession). - /// Future create({required String userId, required String email, required String password, String? name}) async { const String path = '/account'; @@ -63,7 +62,6 @@ class Account extends Service { /// This endpoint can also be used to convert an anonymous account to a normal /// one, by passing an email address and a new password. /// - /// Future updateEmail({required String email, required String password}) async { const String path = '/account/email'; @@ -89,7 +87,6 @@ class Account extends Service { /// Appwrite server-side API and SDKs. The JWT secret is valid for 15 minutes /// from its creation and will be invalid if the user will logout in that time /// frame. - /// Future createJWT() async { const String path = '/account/jwt'; @@ -110,7 +107,6 @@ class Account extends Service { /// /// Get currently logged in user list of latest security activity logs. Each /// log returns user IP address, location and date and time of log. - /// Future listLogs({List? queries}) async { const String path = '/account/logs'; @@ -131,7 +127,6 @@ class Account extends Service { /// Update Name /// /// Update currently logged in user account name. - /// Future updateName({required String name}) async { const String path = '/account/name'; @@ -154,7 +149,6 @@ class Account extends Service { /// Update currently logged in user password. For validation, user is required /// to pass in the new password, and the old password. For users created with /// OAuth, Team Invites and Magic URL, oldPassword is optional. - /// Future updatePassword({required String password, String? oldPassword}) async { const String path = '/account/password'; @@ -180,7 +174,6 @@ class Account extends Service { /// SMS is not sent automatically, however you can use the [POST /// /account/verification/phone](/docs/client/account#accountCreatePhoneVerification) /// endpoint to send a confirmation SMS. - /// Future updatePhone({required String phone, required String password}) async { const String path = '/account/phone'; @@ -202,7 +195,6 @@ class Account extends Service { /// Get Account Preferences /// /// Get currently logged in user preferences as a key-value object. - /// Future getPrefs() async { const String path = '/account/prefs'; @@ -224,7 +216,6 @@ class Account extends Service { /// Update currently logged in user account preferences. The object you pass is /// stored as is, and replaces any previous value. The maximum allowed prefs /// size is 64kB and throws error if exceeded. - /// Future updatePrefs({required Map prefs}) async { const String path = '/account/prefs'; @@ -252,7 +243,6 @@ class Account extends Service { /// /account/recovery](/docs/client/account#accountUpdateRecovery) endpoint to /// complete the process. The verification link sent to the user's email /// address is valid for 1 hour. - /// Future createRecovery({required String email, required String url}) async { const String path = '/account/recovery'; @@ -282,7 +272,6 @@ class Account extends Service { /// Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) /// the only valid redirect URLs are the ones from domains you have set when /// adding your platforms in the console interface. - /// Future updateRecovery({required String userId, required String secret, required String password, required String passwordAgain}) async { const String path = '/account/recovery'; @@ -307,7 +296,6 @@ class Account extends Service { /// /// Get currently logged in user list of active sessions across different /// devices. - /// Future listSessions() async { const String path = '/account/sessions'; @@ -328,7 +316,6 @@ class Account extends Service { /// /// Delete all sessions from the user account and remove any sessions cookies /// from the end client. - /// Future deleteSessions() async { const String path = '/account/sessions'; @@ -353,7 +340,6 @@ class Account extends Service { /// need to update its [email and /// password](/docs/client/account#accountUpdateEmail) or create an [OAuth2 /// session](/docs/client/account#accountCreateOAuth2Session). - /// Future createAnonymousSession() async { const String path = '/account/sessions/anonymous'; @@ -377,7 +363,6 @@ class Account extends Service { /// /// A user is limited to 10 active sessions at a time by default. [Learn more /// about session limits](/docs/authentication-security#limits). - /// Future createEmailSession({required String email, required String password}) async { const String path = '/account/sessions/email'; @@ -412,7 +397,6 @@ class Account extends Service { /// /// A user is limited to 10 active sessions at a time by default. [Learn more /// about session limits](/docs/authentication-security#limits). - /// Future createMagicURLSession({required String userId, required String email, String? url}) async { const String path = '/account/sessions/magic-url'; @@ -445,7 +429,6 @@ class Account extends Service { /// Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) /// the only valid redirect URLs are the ones from domains you have set when /// adding your platforms in the console interface. - /// Future updateMagicURLSession({required String userId, required String secret}) async { const String path = '/account/sessions/magic-url'; @@ -481,7 +464,6 @@ class Account extends Service { /// A user is limited to 10 active sessions at a time by default. [Learn more /// about session limits](/docs/authentication-security#limits). /// - /// Future createOAuth2Session({required String provider, String? success, String? failure, List? scopes}) async { final String path = '/account/sessions/oauth2/{provider}'.replaceAll('{provider}', provider); @@ -528,7 +510,6 @@ class Account extends Service { /// /// A user is limited to 10 active sessions at a time by default. [Learn more /// about session limits](/docs/authentication-security#limits). - /// Future createPhoneSession({required String userId, required String phone}) async { const String path = '/account/sessions/phone'; @@ -554,7 +535,6 @@ class Account extends Service { /// [createPhoneSession](/docs/client/account#accountCreatePhoneSession) /// endpoint and the **secret** received via SMS to successfully update and /// confirm the phone session. - /// Future updatePhoneSession({required String userId, required String secret}) async { const String path = '/account/sessions/phone'; @@ -577,7 +557,6 @@ class Account extends Service { /// /// Use this endpoint to get a logged in user's session using a Session ID. /// Inputting 'current' will return the current session being used. - /// Future getSession({required String sessionId}) async { final String path = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); @@ -599,7 +578,6 @@ class Account extends Service { /// Access tokens have limited lifespan and expire to mitigate security risks. /// If session was created using an OAuth provider, this route can be used to /// "refresh" the access token. - /// Future updateSession({required String sessionId}) async { final String path = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); @@ -622,7 +600,6 @@ class Account extends Service { /// account sessions across all of their different devices. When using the /// Session ID argument, only the unique session ID provided is deleted. /// - /// Future deleteSession({required String sessionId}) async { final String path = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); @@ -644,7 +621,6 @@ class Account extends Service { /// Block the currently logged in user account. Behind the scene, the user /// record is not deleted but permanently blocked from any access. To /// completely delete a user, use the Users API instead. - /// Future updateStatus() async { const String path = '/account/status'; @@ -678,7 +654,6 @@ class Account extends Service { /// the only valid redirect URLs are the ones from domains you have set when /// adding your platforms in the console interface. /// - /// Future createVerification({required String url}) async { const String path = '/account/verification'; @@ -702,7 +677,6 @@ class Account extends Service { /// the **userId** and **secret** parameters that were attached to your app URL /// to verify the user email ownership. If confirmed this route will return a /// 200 status code. - /// Future updateVerification({required String userId, required String secret}) async { const String path = '/account/verification'; @@ -729,7 +703,6 @@ class Account extends Service { /// endpoint. Learn more about how to [complete the verification /// process](/docs/client/account#accountUpdatePhoneVerification). The /// verification code sent to the user's phone number is valid for 15 minutes. - /// Future createPhoneVerification() async { const String path = '/account/verification/phone'; @@ -752,7 +725,6 @@ class Account extends Service { /// **userId** and **secret** that were sent to your user's phone number to /// verify the user email ownership. If confirmed this route will return a 200 /// status code. - /// Future updatePhoneVerification({required String userId, required String secret}) async { const String path = '/account/verification/phone'; diff --git a/lib/services/avatars.dart b/lib/services/avatars.dart index 6962ff5..f5edcba 100644 --- a/lib/services/avatars.dart +++ b/lib/services/avatars.dart @@ -1,8 +1,9 @@ part of appwrite; - /// The Avatars service aims to help you complete everyday tasks related to - /// your app image, icons, and avatars. +/// The Avatars service aims to help you complete everyday tasks related to +/// your app image, icons, and avatars. class Avatars extends Service { + /// Initializes a [Avatars] service Avatars(super.client); /// Get Browser Icon @@ -16,7 +17,6 @@ class Avatars extends Service { /// with preserved aspect ratio. If both dimensions are 0, the API provides an /// image at source quality. If dimensions are not specified, the default size /// of image returned is 100x100px. - /// Future getBrowser({required String code, int? width, int? height, int? quality}) async { final String path = '/avatars/browsers/{code}'.replaceAll('{code}', code); @@ -44,7 +44,6 @@ class Avatars extends Service { /// image at source quality. If dimensions are not specified, the default size /// of image returned is 100x100px. /// - /// Future getCreditCard({required String code, int? width, int? height, int? quality}) async { final String path = '/avatars/credit-cards/{code}'.replaceAll('{code}', code); @@ -66,7 +65,6 @@ class Avatars extends Service { /// Use this endpoint to fetch the favorite icon (AKA favicon) of any remote /// website URL. /// - /// Future getFavicon({required String url}) async { const String path = '/avatars/favicon'; @@ -93,7 +91,6 @@ class Avatars extends Service { /// image at source quality. If dimensions are not specified, the default size /// of image returned is 100x100px. /// - /// Future getFlag({required String code, int? width, int? height, int? quality}) async { final String path = '/avatars/flags/{code}'.replaceAll('{code}', code); @@ -122,7 +119,6 @@ class Avatars extends Service { /// image at source quality. If dimensions are not specified, the default size /// of image returned is 400x400px. /// - /// Future getImage({required String url, int? width, int? height}) async { const String path = '/avatars/image'; @@ -157,7 +153,6 @@ class Avatars extends Service { /// image at source quality. If dimensions are not specified, the default size /// of image returned is 100x100px. /// - /// Future getInitials({String? name, int? width, int? height, String? background}) async { const String path = '/avatars/initials'; @@ -180,7 +175,6 @@ class Avatars extends Service { /// Converts a given plain text to a QR code image. You can use the query /// parameters to change the size and style of the resulting image. /// - /// Future getQR({required String text, int? size, int? margin, bool? download}) async { const String path = '/avatars/qr'; diff --git a/lib/services/databases.dart b/lib/services/databases.dart index 03e4d20..fe42763 100644 --- a/lib/services/databases.dart +++ b/lib/services/databases.dart @@ -1,15 +1,15 @@ part of appwrite; - /// The Databases service allows you to create structured collections of - /// documents, query and filter lists of documents +/// The Databases service allows you to create structured collections of +/// documents, query and filter lists of documents class Databases extends Service { + /// Initializes a [Databases] service Databases(super.client); /// List Documents /// /// Get a list of all the user's documents in a given collection. You can use /// the query params to filter your results. - /// Future listDocuments({required String databaseId, required String collectionId, List? queries}) async { final String path = '/databases/{databaseId}/collections/{collectionId}/documents'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); @@ -33,7 +33,6 @@ class Databases extends Service { /// collection resource using either a [server /// integration](/docs/server/databases#databasesCreateCollection) API or /// directly from your database console. - /// Future createDocument({required String databaseId, required String collectionId, required String documentId, required Map data, List? permissions}) async { final String path = '/databases/{databaseId}/collections/{collectionId}/documents'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); @@ -57,7 +56,6 @@ class Databases extends Service { /// /// Get a document by its unique ID. This endpoint response returns a JSON /// object with the document data. - /// Future getDocument({required String databaseId, required String collectionId, required String documentId, List? queries}) async { final String path = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{documentId}', documentId); @@ -79,7 +77,6 @@ class Databases extends Service { /// /// Update a document by its unique ID. Using the patch method you can pass /// only specific fields that will get updated. - /// Future updateDocument({required String databaseId, required String collectionId, required String documentId, Map? data, List? permissions}) async { final String path = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{documentId}', documentId); @@ -101,7 +98,6 @@ class Databases extends Service { /// Delete Document /// /// Delete a document by its unique ID. - /// Future deleteDocument({required String databaseId, required String collectionId, required String documentId}) async { final String path = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{documentId}', documentId); diff --git a/lib/services/functions.dart b/lib/services/functions.dart index 7cb2ee0..4433a4d 100644 --- a/lib/services/functions.dart +++ b/lib/services/functions.dart @@ -1,15 +1,15 @@ part of appwrite; - /// The Functions Service allows you view, create and manage your Cloud - /// Functions. +/// The Functions Service allows you view, create and manage your Cloud +/// Functions. class Functions extends Service { + /// Initializes a [Functions] service Functions(super.client); /// List Executions /// /// Get a list of all the current user function execution logs. You can use the /// query params to filter your results. - /// Future listExecutions({required String functionId, List? queries, String? search}) async { final String path = '/functions/{functionId}/executions'.replaceAll('{functionId}', functionId); @@ -34,7 +34,6 @@ class Functions extends Service { /// current execution status. You can ping the `Get Execution` endpoint to get /// updates on the current execution status. Once this endpoint is called, your /// function execution process will start asynchronously. - /// Future createExecution({required String functionId, String? data, bool? xasync}) async { final String path = '/functions/{functionId}/executions'.replaceAll('{functionId}', functionId); @@ -56,7 +55,6 @@ class Functions extends Service { /// Get Execution /// /// Get a function execution log by its unique ID. - /// Future getExecution({required String functionId, required String executionId}) async { final String path = '/functions/{functionId}/executions/{executionId}'.replaceAll('{functionId}', functionId).replaceAll('{executionId}', executionId); diff --git a/lib/services/graphql.dart b/lib/services/graphql.dart index 6e5b698..9b15ca1 100644 --- a/lib/services/graphql.dart +++ b/lib/services/graphql.dart @@ -1,14 +1,14 @@ part of appwrite; - /// The GraphQL API allows you to query and mutate your Appwrite server using - /// GraphQL. +/// The GraphQL API allows you to query and mutate your Appwrite server using +/// GraphQL. class Graphql extends Service { + /// Initializes a [Graphql] service Graphql(super.client); /// GraphQL Endpoint /// /// Execute a GraphQL mutation. - /// Future query({required Map query}) async { const String path = '/graphql'; @@ -29,7 +29,6 @@ class Graphql extends Service { /// GraphQL Endpoint /// /// Execute a GraphQL mutation. - /// Future mutation({required Map query}) async { const String path = '/graphql/mutation'; diff --git a/lib/services/locale.dart b/lib/services/locale.dart index 75e104f..06bdff5 100644 --- a/lib/services/locale.dart +++ b/lib/services/locale.dart @@ -1,8 +1,9 @@ part of appwrite; - /// The Locale service allows you to customize your app based on your users' - /// location. +/// The Locale service allows you to customize your app based on your users' +/// location. class Locale extends Service { + /// Initializes a [Locale] service Locale(super.client); /// Get User Locale @@ -13,7 +14,6 @@ class Locale extends Service { /// supported language. /// /// ([IP Geolocation by DB-IP](https://db-ip.com)) - /// Future get() async { const String path = '/locale'; @@ -34,7 +34,6 @@ class Locale extends Service { /// /// List of all continents. You can use the locale header to get the data in a /// supported language. - /// Future listContinents() async { const String path = '/locale/continents'; @@ -55,7 +54,6 @@ class Locale extends Service { /// /// List of all countries. You can use the locale header to get the data in a /// supported language. - /// Future listCountries() async { const String path = '/locale/countries'; @@ -76,7 +74,6 @@ class Locale extends Service { /// /// List of all countries that are currently members of the EU. You can use the /// locale header to get the data in a supported language. - /// Future listCountriesEU() async { const String path = '/locale/countries/eu'; @@ -97,7 +94,6 @@ class Locale extends Service { /// /// List of all countries phone codes. You can use the locale header to get the /// data in a supported language. - /// Future listCountriesPhones() async { const String path = '/locale/countries/phones'; @@ -119,7 +115,6 @@ class Locale extends Service { /// List of all currencies, including currency symbol, name, plural, and /// decimal digits for all major and minor currencies. You can use the locale /// header to get the data in a supported language. - /// Future listCurrencies() async { const String path = '/locale/currencies'; @@ -140,7 +135,6 @@ class Locale extends Service { /// /// List of all languages classified by ISO 639-1 including 2-letter code, name /// in English, and name in the respective language. - /// Future listLanguages() async { const String path = '/locale/languages'; diff --git a/lib/services/storage.dart b/lib/services/storage.dart index 23d0922..e536758 100644 --- a/lib/services/storage.dart +++ b/lib/services/storage.dart @@ -1,14 +1,14 @@ part of appwrite; - /// The Storage service allows you to manage your project files. +/// The Storage service allows you to manage your project files. class Storage extends Service { + /// Initializes a [Storage] service Storage(super.client); /// List Files /// /// Get a list of all the user files. You can use the query params to filter /// your results. - /// Future listFiles({required String bucketId, List? queries, String? search}) async { final String path = '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); @@ -47,7 +47,6 @@ class Storage extends Service { /// If you're creating a new file using one of the Appwrite SDKs, all the /// chunking logic will be managed by the SDK internally. /// - /// Future createFile({required String bucketId, required String fileId, required InputFile file, List? permissions, Function(UploadProgress)? onProgress}) async { final String path = '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); @@ -83,7 +82,6 @@ class Storage extends Service { /// /// Get a file by its unique ID. This endpoint response returns a JSON object /// with the file metadata. - /// Future getFile({required String bucketId, required String fileId}) async { final String path = '/storage/buckets/{bucketId}/files/{fileId}'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); @@ -104,7 +102,6 @@ class Storage extends Service { /// /// Update a file by its unique ID. Only users with write permissions have /// access to update this resource. - /// Future updateFile({required String bucketId, required String fileId, List? permissions}) async { final String path = '/storage/buckets/{bucketId}/files/{fileId}'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); @@ -126,7 +123,6 @@ class Storage extends Service { /// /// Delete a file by its unique ID. Only users with write permissions have /// access to delete this resource. - /// Future deleteFile({required String bucketId, required String fileId}) async { final String path = '/storage/buckets/{bucketId}/files/{fileId}'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); @@ -148,7 +144,6 @@ class Storage extends Service { /// Get a file content by its unique ID. The endpoint response return with a /// 'Content-Disposition: attachment' header that tells the browser to start /// downloading the file to user downloads directory. - /// Future getFileDownload({required String bucketId, required String fileId}) async { final String path = '/storage/buckets/{bucketId}/files/{fileId}/download'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); @@ -169,7 +164,6 @@ class Storage extends Service { /// and spreadsheets, will return the file icon image. You can also pass query /// string arguments for cutting and resizing your preview image. Preview is /// supported only for image files smaller than 10MB. - /// Future getFilePreview({required String bucketId, required String fileId, int? width, int? height, String? gravity, int? quality, int? borderWidth, String? borderColor, int? borderRadius, double? opacity, int? rotation, String? background, String? output}) async { final String path = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); @@ -199,7 +193,6 @@ class Storage extends Service { /// Get a file content by its unique ID. This endpoint is similar to the /// download method but returns with no 'Content-Disposition: attachment' /// header. - /// Future getFileView({required String bucketId, required String fileId}) async { final String path = '/storage/buckets/{bucketId}/files/{fileId}/view'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); diff --git a/lib/services/teams.dart b/lib/services/teams.dart index 3296843..1b97616 100644 --- a/lib/services/teams.dart +++ b/lib/services/teams.dart @@ -1,15 +1,15 @@ part of appwrite; - /// The Teams service allows you to group users of your project and to enable - /// them to share read and write access to your project resources +/// The Teams service allows you to group users of your project and to enable +/// them to share read and write access to your project resources class Teams extends Service { + /// Initializes a [Teams] service Teams(super.client); /// List Teams /// /// Get a list of all the teams in which the current user is a member. You can /// use the parameters to filter your results. - /// Future list({List? queries, String? search}) async { const String path = '/teams'; @@ -33,7 +33,6 @@ class Teams extends Service { /// Create a new team. The user who creates the team will automatically be /// assigned as the owner of the team. Only the users with the owner role can /// invite new members, add new owners and delete or update the team. - /// Future create({required String teamId, required String name, List? roles}) async { const String path = '/teams'; @@ -56,7 +55,6 @@ class Teams extends Service { /// Get Team /// /// Get a team by its ID. All team members have read access for this resource. - /// Future get({required String teamId}) async { final String path = '/teams/{teamId}'.replaceAll('{teamId}', teamId); @@ -76,7 +74,6 @@ class Teams extends Service { /// Update Name /// /// Update the team's name by its unique ID. - /// Future updateName({required String teamId, required String name}) async { final String path = '/teams/{teamId}'.replaceAll('{teamId}', teamId); @@ -98,7 +95,6 @@ class Teams extends Service { /// /// Delete a team using its ID. Only team members with the owner role can /// delete the team. - /// Future delete({required String teamId}) async { final String path = '/teams/{teamId}'.replaceAll('{teamId}', teamId); @@ -119,7 +115,6 @@ class Teams extends Service { /// /// Use this endpoint to list a team's members using the team's ID. All team /// members have read access to this endpoint. - /// Future listMemberships({required String teamId, List? queries, String? search}) async { final String path = '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); @@ -161,7 +156,6 @@ class Teams extends Service { /// Appwrite will accept the only redirect URLs under the domains you have /// added as a platform on the Appwrite Console. /// - /// Future createMembership({required String teamId, required List roles, required String url, String? email, String? userId, String? phone, String? name}) async { final String path = '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); @@ -188,7 +182,6 @@ class Teams extends Service { /// /// Get a team member by the membership unique id. All team members have read /// access for this resource. - /// Future getMembership({required String teamId, required String membershipId}) async { final String path = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); @@ -210,7 +203,6 @@ class Teams extends Service { /// Modify the roles of a team member. Only team members with the owner role /// have access to this endpoint. Learn more about [roles and /// permissions](/docs/permissions). - /// Future updateMembershipRoles({required String teamId, required String membershipId, required List roles}) async { final String path = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); @@ -233,7 +225,6 @@ class Teams extends Service { /// This endpoint allows a user to leave a team or for a team owner to delete /// the membership of any other team member. You can also use this endpoint to /// delete a user membership even if it is not accepted. - /// Future deleteMembership({required String teamId, required String membershipId}) async { final String path = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); @@ -259,7 +250,6 @@ class Teams extends Service { /// If the request is successful, a session for the user is automatically /// created. /// - /// Future updateMembershipStatus({required String teamId, required String membershipId, required String userId, required String secret}) async { final String path = '/teams/{teamId}/memberships/{membershipId}/status'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); @@ -283,7 +273,6 @@ class Teams extends Service { /// Get the team's shared preferences by its unique ID. If a preference doesn't /// need to be shared by all team members, prefer storing them in [user /// preferences](/docs/client/account#accountGetPrefs). - /// Future getPrefs({required String teamId}) async { final String path = '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); @@ -305,7 +294,6 @@ class Teams extends Service { /// Update the team's preferences by its unique ID. The object you pass is /// stored as is and replaces any previous value. The maximum allowed prefs /// size is 64kB and throws an error if exceeded. - /// Future updatePrefs({required String teamId, required Map prefs}) async { final String path = '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); diff --git a/lib/src/client.dart b/lib/src/client.dart index 7b662f8..0104067 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -5,22 +5,32 @@ import 'client_stub.dart' import 'response.dart'; import 'upload_progress.dart'; +/// [Client] that handles requests to Appwrite. +/// +/// The [Client] is also responsible for managing user's sessions. abstract class Client { + /// The size for cunked uploads in bytes. static const int CHUNK_SIZE = 5*1024*1024; + /// Holds configuration such as project. late Map config; late String _endPoint; late String? _endPointRealtime; + /// Appwrite endpoint. String get endPoint => _endPoint; + /// Appwrite realtime endpoint. String? get endPointRealtime => _endPointRealtime; + /// Initializes a [Client]. factory Client( {String endPoint = 'https://HOSTNAME/v1', bool selfSigned = false}) => createClient(endPoint: endPoint, selfSigned: selfSigned); + /// Handle OAuth2 session creation. Future webAuth(Uri url, {String? callbackUrlScheme}); + /// Upload a file in chunks. Future chunkedUpload({ required String path, required Map params, @@ -30,20 +40,36 @@ abstract class Client { Function(UploadProgress)? onProgress, }); + /// Set self signed to [status]. + /// + /// If self signed is true, [Client] will ignore invalid certificates. + /// This is helpful in environments where your Appwrite + /// instance does not have a valid SSL certificate. Client setSelfSigned({bool status = true}); + /// Set the Appwrite endpoint. Client setEndpoint(String endPoint); + /// Set the Appwrite realtime endpoint. Client setEndPointRealtime(String endPoint); - /// Your project ID + /// Set Project. + /// + /// Your project ID. Client setProject(value); - /// Your secret JSON Web Token + + /// Set JWT. + /// + /// Your secret JSON Web Token. Client setJWT(value); + + /// Set Locale. Client setLocale(value); + /// Add headers that should be sent with all API calls. Client addHeader(String key, String value); + /// Send the API request. Future call(HttpMethod method, { String path = '', Map headers = const {}, diff --git a/lib/src/client_browser.dart b/lib/src/client_browser.dart index 93192d4..1f99e4c 100644 --- a/lib/src/client_browser.dart +++ b/lib/src/client_browser.dart @@ -43,7 +43,7 @@ class ClientBrowser extends ClientBase with ClientMixin { 'x-sdk-name': 'Flutter', 'x-sdk-platform': 'client', 'x-sdk-language': 'flutter', - 'x-sdk-version': '9.0.0', + 'x-sdk-version': '9.0.1', 'X-Appwrite-Response-Format': '1.0.0', }; diff --git a/lib/src/client_io.dart b/lib/src/client_io.dart index 06a8abf..ea7effa 100644 --- a/lib/src/client_io.dart +++ b/lib/src/client_io.dart @@ -64,7 +64,7 @@ class ClientIO extends ClientBase with ClientMixin { 'x-sdk-name': 'Flutter', 'x-sdk-platform': 'client', 'x-sdk-language': 'flutter', - 'x-sdk-version': '9.0.0', + 'x-sdk-version': '9.0.1', 'X-Appwrite-Response-Format' : '1.0.0', }; diff --git a/lib/src/enums.dart b/lib/src/enums.dart index 9f84bd9..6566f2e 100644 --- a/lib/src/enums.dart +++ b/lib/src/enums.dart @@ -1,6 +1,8 @@ +/// HTTP methods. enum HttpMethod { get, post, put, delete, patch } extension HttpMethodString on HttpMethod { + /// Returns the HTTP method in all caps. String name() { return toString().split('.').last.toUpperCase(); } diff --git a/lib/src/exception.dart b/lib/src/exception.dart index a5c6a9f..2cc8608 100644 --- a/lib/src/exception.dart +++ b/lib/src/exception.dart @@ -1,14 +1,23 @@ +/// Exception thrown by the appwrite package. class AppwriteException implements Exception { + /// Error message. final String? message; + + /// Error type. + /// + /// See [Error Types](https://appwrite.io/docs/response-codes#errorTypes) + /// for more information. final String? type; final int? code; final dynamic response; + /// Initializes an Appwrite Exception. AppwriteException([this.message = "", this.code, this.type, this.response]); + /// Returns the error type, message, and code. @override String toString() { - if (message == null) return "AppwriteException"; - return "AppwriteException: $type, $message (${code ?? 0})"; + if (message == null || message == "") return "AppwriteException"; + return "AppwriteException: ${type ?? ''}, $message (${code ?? 0})"; } } diff --git a/lib/src/input_file.dart b/lib/src/input_file.dart index 13c6e75..c0be7c0 100644 --- a/lib/src/input_file.dart +++ b/lib/src/input_file.dart @@ -1,5 +1,6 @@ import 'exception.dart'; +/// Helper class to handle files. class InputFile { late final String? path; late final List? bytes; @@ -9,13 +10,13 @@ class InputFile { @Deprecated('Use `InputFile.fromPath` or `InputFile.fromBytes` instead.') InputFile({this.path, this.filename, this.contentType, this.bytes}) { if (path == null && bytes == null) { - throw AppwriteException('One of `path` or `bytes` is required'); + throw AppwriteException('One of `path` or `bytes` is required'); } } InputFile._({this.path, this.filename, this.contentType, this.bytes}) { if (path == null && bytes == null) { - throw AppwriteException('One of `path` or `bytes` is required'); + throw AppwriteException('One of `path` or `bytes` is required'); } } diff --git a/lib/src/realtime.dart b/lib/src/realtime.dart index f30ad0d..fffb7c6 100644 --- a/lib/src/realtime.dart +++ b/lib/src/realtime.dart @@ -5,7 +5,9 @@ import 'realtime_subscription.dart'; import 'service.dart'; import 'client.dart'; +/// Realtime allows you to listen to any events on the server-side in realtime using the subscribe method. abstract class Realtime extends Service { + /// Initializes a [Realtime] service factory Realtime(Client client) => createRealtime(client); /// Subscribes to Appwrite events and returns a `RealtimeSubscription` object, which can be used @@ -42,9 +44,8 @@ abstract class Realtime extends Service { /// RealtimeSubscription subscribe(List channels); - // The [close code][] set when the WebSocket connection is closed. + /// The [close code](https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.5) set when the WebSocket connection is closed. /// /// Before the connection has been closed, this will be `null`. - int? get closeCode => null; } diff --git a/lib/src/realtime_message.dart b/lib/src/realtime_message.dart index 9e7b879..e12b8a4 100644 --- a/lib/src/realtime_message.dart +++ b/lib/src/realtime_message.dart @@ -1,11 +1,24 @@ import 'dart:convert'; import 'package:flutter/foundation.dart'; +/// Realtime Message class RealtimeMessage { + /// All permutations of the system event that triggered this message + /// + /// The first event in the list is the most specfic event without wildcards. final List events; + + /// The data related to the event final Map payload; + + /// All channels that match this event final List channels; + + /// ISO 8601 formatted timestamp in UTC timezone in + /// which the event was sent from Appwrite final String timestamp; + + /// Initializes a [RealtimeMessage] RealtimeMessage({ required this.events, required this.payload, @@ -13,6 +26,7 @@ class RealtimeMessage { required this.timestamp, }); + /// Returns a copy of this [RealtimeMessage] with specified attributes overridden. RealtimeMessage copyWith({ List? events, Map? payload, @@ -27,6 +41,7 @@ class RealtimeMessage { ); } + /// Returns a [Map] representation of this [RealtimeMessage]. Map toMap() { return { 'events': events, @@ -36,6 +51,7 @@ class RealtimeMessage { }; } + /// Initializes a [RealtimeMessage] from a [Map]. factory RealtimeMessage.fromMap(Map map) { return RealtimeMessage( events: List.from(map['events'] ?? []), @@ -45,11 +61,14 @@ class RealtimeMessage { ); } + /// Converts a [RealtimeMessage] to a JSON [String]. String toJson() => json.encode(toMap()); + /// Initializes a [RealtimeMessage] from a JSON [String]. factory RealtimeMessage.fromJson(String source) => RealtimeMessage.fromMap(json.decode(source)); + /// Returns a string representation of this [RealtimeMessage]. @override String toString() { return 'RealtimeMessage(events: $events, payload: $payload, channels: $channels, timestamp: $timestamp)'; diff --git a/lib/src/realtime_subscription.dart b/lib/src/realtime_subscription.dart index b36a862..e45d3b4 100644 --- a/lib/src/realtime_subscription.dart +++ b/lib/src/realtime_subscription.dart @@ -1,8 +1,13 @@ import 'realtime_message.dart'; +/// Realtime Subscription class RealtimeSubscription { + /// Stream of [RealtimeMessage]s final Stream stream; + + /// Closes the subscription final Future Function() close; + /// Initializes a [RealtimeSubscription] RealtimeSubscription({required this.stream, required this.close}); } diff --git a/lib/src/response.dart b/lib/src/response.dart index bf4eea3..ff7d14b 100644 --- a/lib/src/response.dart +++ b/lib/src/response.dart @@ -1,8 +1,11 @@ import 'dart:convert'; +/// Appwrite Response class Response { + /// Initializes a [Response] Response({this.data}); + /// HTTP body returned from Appwrite T? data; @override diff --git a/lib/src/upload_progress.dart b/lib/src/upload_progress.dart index 4ed965d..44cde38 100644 --- a/lib/src/upload_progress.dart +++ b/lib/src/upload_progress.dart @@ -1,11 +1,23 @@ import 'dart:convert'; +/// Progress of a File Upload class UploadProgress { + /// ID of the file. final String $id; + + /// Progress percentage. final double progress; + + /// Size uploaded in bytes. final int sizeUploaded; + + /// Total number of chunks. final int chunksTotal; + + /// Number of chunks uploaded. final int chunksUploaded; + + /// Initializes an [UploadProgress] UploadProgress({ required this.$id, required this.progress, @@ -14,6 +26,7 @@ class UploadProgress { required this.chunksUploaded, }); + /// Initializes an [UploadProgress] from a [Map] factory UploadProgress.fromMap(Map map) { return UploadProgress( $id: map['\$id'] ?? '', @@ -24,6 +37,7 @@ class UploadProgress { ); } + /// Converts an [UploadProgress] to a [Map] Map toMap() { return { "\$id": $id, @@ -34,11 +48,14 @@ class UploadProgress { }; } + /// Converts an [UploadProgress] to a JSON [String] String toJson() => json.encode(toMap()); + /// Initializes an [UploadProgress] from a JSON [String] factory UploadProgress.fromJson(String source) => UploadProgress.fromMap(json.decode(source)); + /// Returns a string representation of an [UploadProgress] @override String toString() { return 'UploadProgress(\$id: ${$id}, progress: $progress, sizeUploaded: $sizeUploaded, chunksTotal: $chunksTotal, chunksUploaded: $chunksUploaded)'; diff --git a/pubspec.yaml b/pubspec.yaml index c6d328c..30c9b30 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: appwrite -version: 9.0.0 +version: 9.0.1 description: Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API homepage: https://appwrite.io repository: https://github.com/appwrite/sdk-for-flutter @@ -18,17 +18,18 @@ environment: dependencies: flutter: sdk: flutter - cookie_jar: ^3.0.1 - device_info_plus: ^8.1.0 - flutter_web_auth_2: ^2.0.4 - http: ^0.13.5 - package_info_plus: ^3.0.3 - path_provider: ^2.0.13 - web_socket_channel: ^2.3.0 - universal_html: ^2.0.9 + cookie_jar: ^4.0.3 + device_info_plus: ^9.0.2 + flutter_web_auth_2: ^2.1.4 + http: '>=0.13.6 <1.0.1' + package_info_plus: ^4.0.2 + path_provider: ^2.0.15 + web_socket_channel: ^2.4.0 + universal_html: ^2.2.2 dev_dependencies: - path_provider_platform_interface: ^2.0.5 + path_provider_platform_interface: ^2.0.6 flutter_lints: ^2.0.1 flutter_test: sdk: flutter + mockito: ^5.4.2 \ No newline at end of file diff --git a/test/id_test.dart b/test/id_test.dart new file mode 100644 index 0000000..1dda4b5 --- /dev/null +++ b/test/id_test.dart @@ -0,0 +1,16 @@ +import 'package:appwrite/appwrite.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('unique()', () { + test('returns unique()', () { + expect(ID.unique(), 'unique()'); + }); + }); + + group('custom()', () { + test('returns the custom string', () { + expect(ID.custom('custom'), 'custom'); + }); + }); +} diff --git a/test/permission_test.dart b/test/permission_test.dart new file mode 100644 index 0000000..3407962 --- /dev/null +++ b/test/permission_test.dart @@ -0,0 +1,34 @@ +import 'package:appwrite/appwrite.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('read()', () { + test('returns read', () { + expect(Permission.read(Role.any()), 'read("any")'); + }); + }); + + group('write()', () { + test('returns write', () { + expect(Permission.write(Role.any()), 'write("any")'); + }); + }); + + group('create()', () { + test('returns create', () { + expect(Permission.create(Role.any()), 'create("any")'); + }); + }); + + group('update()', () { + test('returns update', () { + expect(Permission.update(Role.any()), 'update("any")'); + }); + }); + + group('delete()', () { + test('returns delete', () { + expect(Permission.delete(Role.any()), 'delete("any")'); + }); + }); +} diff --git a/test/query_test.dart b/test/query_test.dart new file mode 100644 index 0000000..6fd1a07 --- /dev/null +++ b/test/query_test.dart @@ -0,0 +1,192 @@ +import 'package:appwrite/appwrite.dart'; +import 'package:flutter_test/flutter_test.dart'; + +class BasicFilterQueryTest { + final String description; + final dynamic value; + final String expectedValues; + + BasicFilterQueryTest({ + required this.description, + required this.value, + required this.expectedValues, + }); +} + +void main() { + group('basic filter tests', () { + final tests = [ + BasicFilterQueryTest( + description: 'with a string', + value: 's', + expectedValues: '["s"]', + ), + BasicFilterQueryTest( + description: 'with an integer', + value: 1, + expectedValues: '[1]', + ), + BasicFilterQueryTest( + description: 'with a double', + value: 1.2, + expectedValues: '[1.2]', + ), + BasicFilterQueryTest( + description: 'with a whole number double', + value: 1.0, + expectedValues: '[1.0]', + ), + BasicFilterQueryTest( + description: 'with a bool', + value: false, + expectedValues: '[false]', + ), + BasicFilterQueryTest( + description: 'with a list', + value: ['a', 'b', 'c'], + expectedValues: '["a","b","c"]', + ), + ]; + + group('equal()', () { + for (var t in tests) { + test(t.description, () { + expect( + Query.equal('attr', t.value), + 'equal("attr", ${t.expectedValues})', + ); + }); + } + }); + + group('notEqual()', () { + for (var t in tests) { + test(t.description, () { + expect( + Query.notEqual('attr', t.value), + 'notEqual("attr", ${t.expectedValues})', + ); + }); + } + }); + + group('lessThan()', () { + for (var t in tests) { + test(t.description, () { + expect( + Query.lessThan('attr', t.value), + 'lessThan("attr", ${t.expectedValues})', + ); + }); + } + }); + + group('lessThanEqual()', () { + for (var t in tests) { + test(t.description, () { + expect( + Query.lessThanEqual('attr', t.value), + 'lessThanEqual("attr", ${t.expectedValues})', + ); + }); + } + }); + + group('greaterThan()', () { + for (var t in tests) { + test(t.description, () { + expect( + Query.greaterThan('attr', t.value), + 'greaterThan("attr", ${t.expectedValues})', + ); + }); + } + }); + + group('greaterThanEqual()', () { + for (var t in tests) { + test(t.description, () { + expect( + Query.greaterThanEqual('attr', t.value), + 'greaterThanEqual("attr", ${t.expectedValues})', + ); + }); + } + }); + }); + + group('search()', () { + test('returns search', () { + expect(Query.search('attr', 'keyword1 keyword2'), 'search("attr", ["keyword1 keyword2"])'); + }); + }); + + group('isNull()', () { + test('returns isNull', () { + expect(Query.isNull('attr'), 'isNull("attr")'); + }); + }); + + group('isNotNull()', () { + test('returns isNotNull', () { + expect(Query.isNotNull('attr'), 'isNotNull("attr")'); + }); + }); + + group('between()', () { + test('with integers', () { + expect(Query.between('attr', 1, 2), 'between("attr", [1,2])'); + }); + + test('with doubles', () { + expect(Query.between('attr', 1.0, 2.0), 'between("attr", [1.0,2.0])'); + }); + + test('with strings', () { + expect(Query.between('attr', "a", "z"), 'between("attr", ["a","z"])'); + }); + }); + + group('select()', () { + test('returns select', () { + expect(Query.select(['attr1', 'attr2']), 'select(["attr1","attr2"])'); + }); + }); + + group('orderAsc()', () { + test('returns orderAsc', () { + expect(Query.orderAsc('attr'), 'orderAsc("attr")'); + }); + }); + + group('orderDesc()', () { + test('returns orderDesc', () { + expect(Query.orderDesc('attr'), 'orderDesc("attr")'); + }); + }); + + group('cursorBefore()', () { + test('returns cursorBefore', () { + expect(Query.cursorBefore(ID.custom('custom')), 'cursorBefore("custom")'); + }); + }); + + group('cursorAfter()', () { + test('returns cursorAfter', () { + expect(Query.cursorAfter(ID.custom('custom')), 'cursorAfter("custom")'); + }); + }); + + group('limit()', () { + test('returns limit', () { + expect(Query.limit(1), 'limit(1)'); + }); + }); + + group('offset()', () { + test('returns offset', () { + expect(Query.offset(1), 'offset(1)'); + }); + }); +} + diff --git a/test/role_test.dart b/test/role_test.dart new file mode 100644 index 0000000..e237ef8 --- /dev/null +++ b/test/role_test.dart @@ -0,0 +1,52 @@ +import 'package:appwrite/appwrite.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('any()', () { + test('returns any', () { + expect(Role.any(), 'any'); + }); + }); + + group('user()', () { + test('without status', () { + expect(Role.user('custom'), 'user:custom'); + }); + + test('with status', () { + expect(Role.user('custom', 'verified'), 'user:custom/verified'); + }); + }); + + group('users()', () { + test('without status', () { + expect(Role.users(), 'users'); + }); + + test('with status', () { + expect(Role.users('verified'), 'users/verified'); + }); + }); + + group('guests()', () { + test('returns guests', () { + expect(Role.guests(), 'guests'); + }); + }); + + group('team()', () { + test('without role', () { + expect(Role.team('custom'), 'team:custom'); + }); + + test('with role', () { + expect(Role.team('custom', 'owner'), 'team:custom/owner'); + }); + }); + + group('member()', () { + test('returns member', () { + expect(Role.member('custom'), 'member:custom'); + }); + }); +} diff --git a/test/services/account_test.dart b/test/services/account_test.dart new file mode 100644 index 0000000..3590210 --- /dev/null +++ b/test/services/account_test.dart @@ -0,0 +1,809 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:appwrite/models.dart' as models; +import 'package:appwrite/src/enums.dart'; +import 'package:appwrite/src/response.dart'; +import 'dart:typed_data'; +import 'package:appwrite/appwrite.dart'; + +class MockClient extends Mock implements Client { + Map config = {'project': 'testproject'}; + String endPoint = 'https://localhost/v1'; + @override + Future call( + HttpMethod? method, { + String path = '', + Map headers = const {}, + Map params = const {}, + ResponseType? responseType, + }) async { + return super.noSuchMethod(Invocation.method(#call, [method]), + returnValue: Response()); + } + + @override + Future webAuth( + Uri? url, + { + String? callbackUrlScheme, + } + ) async { + return super.noSuchMethod(Invocation.method(#webAuth, [url]), returnValue: 'done'); + } + + @override + Future chunkedUpload({ + String? path, + Map? params, + String? paramName, + String? idParamName, + Map? headers, + Function(UploadProgress)? onProgress, + }) async { + return super.noSuchMethod(Invocation.method(#chunkedUpload, [path, params, paramName, idParamName, headers]), returnValue: Response(data: {})); + } +} + +void main() { + group('Account test', () { + late MockClient client; + late Account account; + + setUp(() { + client = MockClient(); + account = Account(client); + }); + + test('test method get()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'prefs': {},}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.get( + ); + expect(response, isA()); + + }); + + test('test method create()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'prefs': {},}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.create( + userId: '[USER_ID]', + email: 'email@example.com', + password: '', + ); + expect(response, isA()); + + }); + + test('test method updateEmail()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'prefs': {},}; + + + when(client.call( + HttpMethod.patch, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.updateEmail( + email: 'email@example.com', + password: 'password', + ); + expect(response, isA()); + + }); + + test('test method createJWT()', () async { + final Map data = { + 'jwt': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c',}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.createJWT( + ); + expect(response, isA()); + + }); + + test('test method listLogs()', () async { + final Map data = { + 'total': 5, + 'logs': [],}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.listLogs( + ); + expect(response, isA()); + + }); + + test('test method updateName()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'prefs': {},}; + + + when(client.call( + HttpMethod.patch, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.updateName( + name: '[NAME]', + ); + expect(response, isA()); + + }); + + test('test method updatePassword()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'prefs': {},}; + + + when(client.call( + HttpMethod.patch, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.updatePassword( + password: '', + ); + expect(response, isA()); + + }); + + test('test method updatePhone()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'prefs': {},}; + + + when(client.call( + HttpMethod.patch, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.updatePhone( + phone: '+12065550100', + password: 'password', + ); + expect(response, isA()); + + }); + + test('test method getPrefs()', () async { + final Map data = {}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.getPrefs( + ); + expect(response, isA()); + + }); + + test('test method updatePrefs()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'prefs': {},}; + + + when(client.call( + HttpMethod.patch, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.updatePrefs( + prefs: {}, + ); + expect(response, isA()); + + }); + + test('test method createRecovery()', () async { + final Map data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00',}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.createRecovery( + email: 'email@example.com', + url: 'https://example.com', + ); + expect(response, isA()); + + }); + + test('test method updateRecovery()', () async { + final Map data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00',}; + + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.updateRecovery( + userId: '[USER_ID]', + secret: '[SECRET]', + password: 'password', + passwordAgain: 'password', + ); + expect(response, isA()); + + }); + + test('test method listSessions()', () async { + final Map data = { + 'total': 5, + 'sessions': [],}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.listSessions( + ); + expect(response, isA()); + + }); + + test('test method deleteSessions()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.deleteSessions( + ); + }); + + test('test method createAnonymousSession()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5bb8c16897e', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'provider': 'email', + 'providerUid': 'user@example.com', + 'providerAccessToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'providerAccessTokenExpiry': '2020-10-15T06:38:00.000+00:00', + 'providerRefreshToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'ip': '127.0.0.1', + 'osCode': 'Mac', + 'osName': 'Mac', + 'osVersion': 'Mac', + 'clientType': 'browser', + 'clientCode': 'CM', + 'clientName': 'Chrome Mobile iOS', + 'clientVersion': '84.0', + 'clientEngine': 'WebKit', + 'clientEngineVersion': '605.1.15', + 'deviceName': 'smartphone', + 'deviceBrand': 'Google', + 'deviceModel': 'Nexus 5', + 'countryCode': 'US', + 'countryName': 'United States', + 'current': true,}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.createAnonymousSession( + ); + expect(response, isA()); + + }); + + test('test method createEmailSession()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5bb8c16897e', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'provider': 'email', + 'providerUid': 'user@example.com', + 'providerAccessToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'providerAccessTokenExpiry': '2020-10-15T06:38:00.000+00:00', + 'providerRefreshToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'ip': '127.0.0.1', + 'osCode': 'Mac', + 'osName': 'Mac', + 'osVersion': 'Mac', + 'clientType': 'browser', + 'clientCode': 'CM', + 'clientName': 'Chrome Mobile iOS', + 'clientVersion': '84.0', + 'clientEngine': 'WebKit', + 'clientEngineVersion': '605.1.15', + 'deviceName': 'smartphone', + 'deviceBrand': 'Google', + 'deviceModel': 'Nexus 5', + 'countryCode': 'US', + 'countryName': 'United States', + 'current': true,}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.createEmailSession( + email: 'email@example.com', + password: 'password', + ); + expect(response, isA()); + + }); + + test('test method createMagicURLSession()', () async { + final Map data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00',}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.createMagicURLSession( + userId: '[USER_ID]', + email: 'email@example.com', + ); + expect(response, isA()); + + }); + + test('test method updateMagicURLSession()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5bb8c16897e', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'provider': 'email', + 'providerUid': 'user@example.com', + 'providerAccessToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'providerAccessTokenExpiry': '2020-10-15T06:38:00.000+00:00', + 'providerRefreshToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'ip': '127.0.0.1', + 'osCode': 'Mac', + 'osName': 'Mac', + 'osVersion': 'Mac', + 'clientType': 'browser', + 'clientCode': 'CM', + 'clientName': 'Chrome Mobile iOS', + 'clientVersion': '84.0', + 'clientEngine': 'WebKit', + 'clientEngineVersion': '605.1.15', + 'deviceName': 'smartphone', + 'deviceBrand': 'Google', + 'deviceModel': 'Nexus 5', + 'countryCode': 'US', + 'countryName': 'United States', + 'current': true,}; + + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.updateMagicURLSession( + userId: '[USER_ID]', + secret: '[SECRET]', + ); + expect(response, isA()); + + }); + + test('test method createOAuth2Session()', () async { + + when(client.webAuth( + Uri(), + )).thenAnswer((_) async => 'done'); + + + final response = await account.createOAuth2Session( + provider: 'amazon', + ); + }); + + test('test method createPhoneSession()', () async { + final Map data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00',}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.createPhoneSession( + userId: '[USER_ID]', + phone: '+12065550100', + ); + expect(response, isA()); + + }); + + test('test method updatePhoneSession()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5bb8c16897e', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'provider': 'email', + 'providerUid': 'user@example.com', + 'providerAccessToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'providerAccessTokenExpiry': '2020-10-15T06:38:00.000+00:00', + 'providerRefreshToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'ip': '127.0.0.1', + 'osCode': 'Mac', + 'osName': 'Mac', + 'osVersion': 'Mac', + 'clientType': 'browser', + 'clientCode': 'CM', + 'clientName': 'Chrome Mobile iOS', + 'clientVersion': '84.0', + 'clientEngine': 'WebKit', + 'clientEngineVersion': '605.1.15', + 'deviceName': 'smartphone', + 'deviceBrand': 'Google', + 'deviceModel': 'Nexus 5', + 'countryCode': 'US', + 'countryName': 'United States', + 'current': true,}; + + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.updatePhoneSession( + userId: '[USER_ID]', + secret: '[SECRET]', + ); + expect(response, isA()); + + }); + + test('test method getSession()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5bb8c16897e', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'provider': 'email', + 'providerUid': 'user@example.com', + 'providerAccessToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'providerAccessTokenExpiry': '2020-10-15T06:38:00.000+00:00', + 'providerRefreshToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'ip': '127.0.0.1', + 'osCode': 'Mac', + 'osName': 'Mac', + 'osVersion': 'Mac', + 'clientType': 'browser', + 'clientCode': 'CM', + 'clientName': 'Chrome Mobile iOS', + 'clientVersion': '84.0', + 'clientEngine': 'WebKit', + 'clientEngineVersion': '605.1.15', + 'deviceName': 'smartphone', + 'deviceBrand': 'Google', + 'deviceModel': 'Nexus 5', + 'countryCode': 'US', + 'countryName': 'United States', + 'current': true,}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.getSession( + sessionId: '[SESSION_ID]', + ); + expect(response, isA()); + + }); + + test('test method updateSession()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5bb8c16897e', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'provider': 'email', + 'providerUid': 'user@example.com', + 'providerAccessToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'providerAccessTokenExpiry': '2020-10-15T06:38:00.000+00:00', + 'providerRefreshToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'ip': '127.0.0.1', + 'osCode': 'Mac', + 'osName': 'Mac', + 'osVersion': 'Mac', + 'clientType': 'browser', + 'clientCode': 'CM', + 'clientName': 'Chrome Mobile iOS', + 'clientVersion': '84.0', + 'clientEngine': 'WebKit', + 'clientEngineVersion': '605.1.15', + 'deviceName': 'smartphone', + 'deviceBrand': 'Google', + 'deviceModel': 'Nexus 5', + 'countryCode': 'US', + 'countryName': 'United States', + 'current': true,}; + + + when(client.call( + HttpMethod.patch, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.updateSession( + sessionId: '[SESSION_ID]', + ); + expect(response, isA()); + + }); + + test('test method deleteSession()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.deleteSession( + sessionId: '[SESSION_ID]', + ); + }); + + test('test method updateStatus()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'John Doe', + 'registration': '2020-10-15T06:38:00.000+00:00', + 'status': true, + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'prefs': {},}; + + + when(client.call( + HttpMethod.patch, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.updateStatus( + ); + expect(response, isA()); + + }); + + test('test method createVerification()', () async { + final Map data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00',}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.createVerification( + url: 'https://example.com', + ); + expect(response, isA()); + + }); + + test('test method updateVerification()', () async { + final Map data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00',}; + + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.updateVerification( + userId: '[USER_ID]', + secret: '[SECRET]', + ); + expect(response, isA()); + + }); + + test('test method createPhoneVerification()', () async { + final Map data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00',}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.createPhoneVerification( + ); + expect(response, isA()); + + }); + + test('test method updatePhoneVerification()', () async { + final Map data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00',}; + + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.updatePhoneVerification( + userId: '[USER_ID]', + secret: '[SECRET]', + ); + expect(response, isA()); + + }); + + }); +} \ No newline at end of file diff --git a/test/services/avatars_test.dart b/test/services/avatars_test.dart new file mode 100644 index 0000000..60c20f9 --- /dev/null +++ b/test/services/avatars_test.dart @@ -0,0 +1,155 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:appwrite/models.dart' as models; +import 'package:appwrite/src/enums.dart'; +import 'package:appwrite/src/response.dart'; +import 'dart:typed_data'; +import 'package:appwrite/appwrite.dart'; + +class MockClient extends Mock implements Client { + Map config = {'project': 'testproject'}; + String endPoint = 'https://localhost/v1'; + @override + Future call( + HttpMethod? method, { + String path = '', + Map headers = const {}, + Map params = const {}, + ResponseType? responseType, + }) async { + return super.noSuchMethod(Invocation.method(#call, [method]), + returnValue: Response()); + } + + @override + Future webAuth( + Uri? url, + { + String? callbackUrlScheme, + } + ) async { + return super.noSuchMethod(Invocation.method(#webAuth, [url]), returnValue: 'done'); + } + + @override + Future chunkedUpload({ + String? path, + Map? params, + String? paramName, + String? idParamName, + Map? headers, + Function(UploadProgress)? onProgress, + }) async { + return super.noSuchMethod(Invocation.method(#chunkedUpload, [path, params, paramName, idParamName, headers]), returnValue: Response(data: {})); + } +} + +void main() { + group('Avatars test', () { + late MockClient client; + late Avatars avatars; + + setUp(() { + client = MockClient(); + avatars = Avatars(client); + }); + + test('test method getBrowser()', () async {final Uint8List data = Uint8List.fromList([]); + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await avatars.getBrowser( + code: 'aa', + ); + expect(response, isA()); + + }); + + test('test method getCreditCard()', () async {final Uint8List data = Uint8List.fromList([]); + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await avatars.getCreditCard( + code: 'amex', + ); + expect(response, isA()); + + }); + + test('test method getFavicon()', () async {final Uint8List data = Uint8List.fromList([]); + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await avatars.getFavicon( + url: 'https://example.com', + ); + expect(response, isA()); + + }); + + test('test method getFlag()', () async {final Uint8List data = Uint8List.fromList([]); + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await avatars.getFlag( + code: 'af', + ); + expect(response, isA()); + + }); + + test('test method getImage()', () async {final Uint8List data = Uint8List.fromList([]); + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await avatars.getImage( + url: 'https://example.com', + ); + expect(response, isA()); + + }); + + test('test method getInitials()', () async {final Uint8List data = Uint8List.fromList([]); + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await avatars.getInitials( + ); + expect(response, isA()); + + }); + + test('test method getQR()', () async {final Uint8List data = Uint8List.fromList([]); + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await avatars.getQR( + text: '[TEXT]', + ); + expect(response, isA()); + + }); + + }); +} \ No newline at end of file diff --git a/test/services/databases_test.dart b/test/services/databases_test.dart new file mode 100644 index 0000000..cee69ed --- /dev/null +++ b/test/services/databases_test.dart @@ -0,0 +1,165 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:appwrite/models.dart' as models; +import 'package:appwrite/src/enums.dart'; +import 'package:appwrite/src/response.dart'; +import 'dart:typed_data'; +import 'package:appwrite/appwrite.dart'; + +class MockClient extends Mock implements Client { + Map config = {'project': 'testproject'}; + String endPoint = 'https://localhost/v1'; + @override + Future call( + HttpMethod? method, { + String path = '', + Map headers = const {}, + Map params = const {}, + ResponseType? responseType, + }) async { + return super.noSuchMethod(Invocation.method(#call, [method]), + returnValue: Response()); + } + + @override + Future webAuth( + Uri? url, + { + String? callbackUrlScheme, + } + ) async { + return super.noSuchMethod(Invocation.method(#webAuth, [url]), returnValue: 'done'); + } + + @override + Future chunkedUpload({ + String? path, + Map? params, + String? paramName, + String? idParamName, + Map? headers, + Function(UploadProgress)? onProgress, + }) async { + return super.noSuchMethod(Invocation.method(#chunkedUpload, [path, params, paramName, idParamName, headers]), returnValue: Response(data: {})); + } +} + +void main() { + group('Databases test', () { + late MockClient client; + late Databases databases; + + setUp(() { + client = MockClient(); + databases = Databases(client); + }); + + test('test method listDocuments()', () async { + final Map data = { + 'total': 5, + 'documents': [],}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await databases.listDocuments( + databaseId: '[DATABASE_ID]', + collectionId: '[COLLECTION_ID]', + ); + expect(response, isA()); + + }); + + test('test method createDocument()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$collectionId': '5e5ea5c15117e', + '\$databaseId': '5e5ea5c15117e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [],}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await databases.createDocument( + databaseId: '[DATABASE_ID]', + collectionId: '[COLLECTION_ID]', + documentId: '[DOCUMENT_ID]', + data: {}, + ); + expect(response, isA()); + + }); + + test('test method getDocument()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$collectionId': '5e5ea5c15117e', + '\$databaseId': '5e5ea5c15117e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [],}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await databases.getDocument( + databaseId: '[DATABASE_ID]', + collectionId: '[COLLECTION_ID]', + documentId: '[DOCUMENT_ID]', + ); + expect(response, isA()); + + }); + + test('test method updateDocument()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$collectionId': '5e5ea5c15117e', + '\$databaseId': '5e5ea5c15117e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [],}; + + + when(client.call( + HttpMethod.patch, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await databases.updateDocument( + databaseId: '[DATABASE_ID]', + collectionId: '[COLLECTION_ID]', + documentId: '[DOCUMENT_ID]', + ); + expect(response, isA()); + + }); + + test('test method deleteDocument()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await databases.deleteDocument( + databaseId: '[DATABASE_ID]', + collectionId: '[COLLECTION_ID]', + documentId: '[DOCUMENT_ID]', + ); + }); + + }); +} \ No newline at end of file diff --git a/test/services/functions_test.dart b/test/services/functions_test.dart new file mode 100644 index 0000000..70ae42d --- /dev/null +++ b/test/services/functions_test.dart @@ -0,0 +1,133 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:appwrite/models.dart' as models; +import 'package:appwrite/src/enums.dart'; +import 'package:appwrite/src/response.dart'; +import 'dart:typed_data'; +import 'package:appwrite/appwrite.dart'; + +class MockClient extends Mock implements Client { + Map config = {'project': 'testproject'}; + String endPoint = 'https://localhost/v1'; + @override + Future call( + HttpMethod? method, { + String path = '', + Map headers = const {}, + Map params = const {}, + ResponseType? responseType, + }) async { + return super.noSuchMethod(Invocation.method(#call, [method]), + returnValue: Response()); + } + + @override + Future webAuth( + Uri? url, + { + String? callbackUrlScheme, + } + ) async { + return super.noSuchMethod(Invocation.method(#webAuth, [url]), returnValue: 'done'); + } + + @override + Future chunkedUpload({ + String? path, + Map? params, + String? paramName, + String? idParamName, + Map? headers, + Function(UploadProgress)? onProgress, + }) async { + return super.noSuchMethod(Invocation.method(#chunkedUpload, [path, params, paramName, idParamName, headers]), returnValue: Response(data: {})); + } +} + +void main() { + group('Functions test', () { + late MockClient client; + late Functions functions; + + setUp(() { + client = MockClient(); + functions = Functions(client); + }); + + test('test method listExecutions()', () async { + final Map data = { + 'total': 5, + 'executions': [],}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await functions.listExecutions( + functionId: '[FUNCTION_ID]', + ); + expect(response, isA()); + + }); + + test('test method createExecution()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'functionId': '5e5ea6g16897e', + 'trigger': 'http', + 'status': 'processing', + 'statusCode': 0, + 'response': '', + 'stdout': '', + 'stderr': '', + 'duration': 0.4,}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await functions.createExecution( + functionId: '[FUNCTION_ID]', + ); + expect(response, isA()); + + }); + + test('test method getExecution()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'functionId': '5e5ea6g16897e', + 'trigger': 'http', + 'status': 'processing', + 'statusCode': 0, + 'response': '', + 'stdout': '', + 'stderr': '', + 'duration': 0.4,}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await functions.getExecution( + functionId: '[FUNCTION_ID]', + executionId: '[EXECUTION_ID]', + ); + expect(response, isA()); + + }); + + }); +} \ No newline at end of file diff --git a/test/services/graphql_test.dart b/test/services/graphql_test.dart new file mode 100644 index 0000000..bb5e8ec --- /dev/null +++ b/test/services/graphql_test.dart @@ -0,0 +1,84 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:appwrite/models.dart' as models; +import 'package:appwrite/src/enums.dart'; +import 'package:appwrite/src/response.dart'; +import 'dart:typed_data'; +import 'package:appwrite/appwrite.dart'; + +class MockClient extends Mock implements Client { + Map config = {'project': 'testproject'}; + String endPoint = 'https://localhost/v1'; + @override + Future call( + HttpMethod? method, { + String path = '', + Map headers = const {}, + Map params = const {}, + ResponseType? responseType, + }) async { + return super.noSuchMethod(Invocation.method(#call, [method]), + returnValue: Response()); + } + + @override + Future webAuth( + Uri? url, + { + String? callbackUrlScheme, + } + ) async { + return super.noSuchMethod(Invocation.method(#webAuth, [url]), returnValue: 'done'); + } + + @override + Future chunkedUpload({ + String? path, + Map? params, + String? paramName, + String? idParamName, + Map? headers, + Function(UploadProgress)? onProgress, + }) async { + return super.noSuchMethod(Invocation.method(#chunkedUpload, [path, params, paramName, idParamName, headers]), returnValue: Response(data: {})); + } +} + +void main() { + group('Graphql test', () { + late MockClient client; + late Graphql graphql; + + setUp(() { + client = MockClient(); + graphql = Graphql(client); + }); + + test('test method query()', () async { + final data = ''; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await graphql.query( + query: {}, + ); + }); + + test('test method mutation()', () async { + final data = ''; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await graphql.mutation( + query: {}, + ); + }); + + }); +} \ No newline at end of file diff --git a/test/services/locale_test.dart b/test/services/locale_test.dart new file mode 100644 index 0000000..640da15 --- /dev/null +++ b/test/services/locale_test.dart @@ -0,0 +1,182 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:appwrite/models.dart' as models; +import 'package:appwrite/src/enums.dart'; +import 'package:appwrite/src/response.dart'; +import 'dart:typed_data'; +import 'package:appwrite/appwrite.dart'; + +class MockClient extends Mock implements Client { + Map config = {'project': 'testproject'}; + String endPoint = 'https://localhost/v1'; + @override + Future call( + HttpMethod? method, { + String path = '', + Map headers = const {}, + Map params = const {}, + ResponseType? responseType, + }) async { + return super.noSuchMethod(Invocation.method(#call, [method]), + returnValue: Response()); + } + + @override + Future webAuth( + Uri? url, + { + String? callbackUrlScheme, + } + ) async { + return super.noSuchMethod(Invocation.method(#webAuth, [url]), returnValue: 'done'); + } + + @override + Future chunkedUpload({ + String? path, + Map? params, + String? paramName, + String? idParamName, + Map? headers, + Function(UploadProgress)? onProgress, + }) async { + return super.noSuchMethod(Invocation.method(#chunkedUpload, [path, params, paramName, idParamName, headers]), returnValue: Response(data: {})); + } +} + +void main() { + group('Locale test', () { + late MockClient client; + late Locale locale; + + setUp(() { + client = MockClient(); + locale = Locale(client); + }); + + test('test method get()', () async { + final Map data = { + 'ip': '127.0.0.1', + 'countryCode': 'US', + 'country': 'United States', + 'continentCode': 'NA', + 'continent': 'North America', + 'eu': true, + 'currency': 'USD',}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await locale.get( + ); + expect(response, isA()); + + }); + + test('test method listContinents()', () async { + final Map data = { + 'total': 5, + 'continents': [],}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await locale.listContinents( + ); + expect(response, isA()); + + }); + + test('test method listCountries()', () async { + final Map data = { + 'total': 5, + 'countries': [],}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await locale.listCountries( + ); + expect(response, isA()); + + }); + + test('test method listCountriesEU()', () async { + final Map data = { + 'total': 5, + 'countries': [],}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await locale.listCountriesEU( + ); + expect(response, isA()); + + }); + + test('test method listCountriesPhones()', () async { + final Map data = { + 'total': 5, + 'phones': [],}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await locale.listCountriesPhones( + ); + expect(response, isA()); + + }); + + test('test method listCurrencies()', () async { + final Map data = { + 'total': 5, + 'currencies': [],}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await locale.listCurrencies( + ); + expect(response, isA()); + + }); + + test('test method listLanguages()', () async { + final Map data = { + 'total': 5, + 'languages': [],}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await locale.listLanguages( + ); + expect(response, isA()); + + }); + + }); +} \ No newline at end of file diff --git a/test/services/storage_test.dart b/test/services/storage_test.dart new file mode 100644 index 0000000..477a76f --- /dev/null +++ b/test/services/storage_test.dart @@ -0,0 +1,224 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:appwrite/models.dart' as models; +import 'package:appwrite/src/enums.dart'; +import 'package:appwrite/src/response.dart'; +import 'dart:typed_data'; +import 'package:appwrite/appwrite.dart'; + +class MockClient extends Mock implements Client { + Map config = {'project': 'testproject'}; + String endPoint = 'https://localhost/v1'; + @override + Future call( + HttpMethod? method, { + String path = '', + Map headers = const {}, + Map params = const {}, + ResponseType? responseType, + }) async { + return super.noSuchMethod(Invocation.method(#call, [method]), + returnValue: Response()); + } + + @override + Future webAuth( + Uri? url, + { + String? callbackUrlScheme, + } + ) async { + return super.noSuchMethod(Invocation.method(#webAuth, [url]), returnValue: 'done'); + } + + @override + Future chunkedUpload({ + String? path, + Map? params, + String? paramName, + String? idParamName, + Map? headers, + Function(UploadProgress)? onProgress, + }) async { + return super.noSuchMethod(Invocation.method(#chunkedUpload, [path, params, paramName, idParamName, headers]), returnValue: Response(data: {})); + } +} + +void main() { + group('Storage test', () { + late MockClient client; + late Storage storage; + + setUp(() { + client = MockClient(); + storage = Storage(client); + }); + + test('test method listFiles()', () async { + final Map data = { + 'total': 5, + 'files': [],}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await storage.listFiles( + bucketId: '[BUCKET_ID]', + ); + expect(response, isA()); + + }); + + test('test method createFile()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + 'bucketId': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'name': 'Pink.png', + 'signature': '5d529fd02b544198ae075bd57c1762bb', + 'mimeType': 'image/png', + 'sizeOriginal': 17890, + 'chunksTotal': 17890, + 'chunksUploaded': 17890,}; + + + when(client.chunkedUpload( + path: argThat(isNotNull), + params: argThat(isNotNull), + paramName: argThat(isNotNull), + idParamName: argThat(isNotNull), + headers: argThat(isNotNull), + )).thenAnswer((_) async => Response(data: data)); + + + final response = await storage.createFile( + bucketId: '[BUCKET_ID]', + fileId: '[FILE_ID]', + file: InputFile.fromPath(path: './image.png'), + ); + expect(response, isA()); + + }); + + test('test method getFile()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + 'bucketId': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'name': 'Pink.png', + 'signature': '5d529fd02b544198ae075bd57c1762bb', + 'mimeType': 'image/png', + 'sizeOriginal': 17890, + 'chunksTotal': 17890, + 'chunksUploaded': 17890,}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await storage.getFile( + bucketId: '[BUCKET_ID]', + fileId: '[FILE_ID]', + ); + expect(response, isA()); + + }); + + test('test method updateFile()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + 'bucketId': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'name': 'Pink.png', + 'signature': '5d529fd02b544198ae075bd57c1762bb', + 'mimeType': 'image/png', + 'sizeOriginal': 17890, + 'chunksTotal': 17890, + 'chunksUploaded': 17890,}; + + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await storage.updateFile( + bucketId: '[BUCKET_ID]', + fileId: '[FILE_ID]', + ); + expect(response, isA()); + + }); + + test('test method deleteFile()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await storage.deleteFile( + bucketId: '[BUCKET_ID]', + fileId: '[FILE_ID]', + ); + }); + + test('test method getFileDownload()', () async {final Uint8List data = Uint8List.fromList([]); + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await storage.getFileDownload( + bucketId: '[BUCKET_ID]', + fileId: '[FILE_ID]', + ); + expect(response, isA()); + + }); + + test('test method getFilePreview()', () async {final Uint8List data = Uint8List.fromList([]); + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await storage.getFilePreview( + bucketId: '[BUCKET_ID]', + fileId: '[FILE_ID]', + ); + expect(response, isA()); + + }); + + test('test method getFileView()', () async {final Uint8List data = Uint8List.fromList([]); + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await storage.getFileView( + bucketId: '[BUCKET_ID]', + fileId: '[FILE_ID]', + ); + expect(response, isA()); + + }); + + }); +} \ No newline at end of file diff --git a/test/services/teams_test.dart b/test/services/teams_test.dart new file mode 100644 index 0000000..5f3401c --- /dev/null +++ b/test/services/teams_test.dart @@ -0,0 +1,341 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:appwrite/models.dart' as models; +import 'package:appwrite/src/enums.dart'; +import 'package:appwrite/src/response.dart'; +import 'dart:typed_data'; +import 'package:appwrite/appwrite.dart'; + +class MockClient extends Mock implements Client { + Map config = {'project': 'testproject'}; + String endPoint = 'https://localhost/v1'; + @override + Future call( + HttpMethod? method, { + String path = '', + Map headers = const {}, + Map params = const {}, + ResponseType? responseType, + }) async { + return super.noSuchMethod(Invocation.method(#call, [method]), + returnValue: Response()); + } + + @override + Future webAuth( + Uri? url, + { + String? callbackUrlScheme, + } + ) async { + return super.noSuchMethod(Invocation.method(#webAuth, [url]), returnValue: 'done'); + } + + @override + Future chunkedUpload({ + String? path, + Map? params, + String? paramName, + String? idParamName, + Map? headers, + Function(UploadProgress)? onProgress, + }) async { + return super.noSuchMethod(Invocation.method(#chunkedUpload, [path, params, paramName, idParamName, headers]), returnValue: Response(data: {})); + } +} + +void main() { + group('Teams test', () { + late MockClient client; + late Teams teams; + + setUp(() { + client = MockClient(); + teams = Teams(client); + }); + + test('test method list()', () async { + final Map data = { + 'total': 5, + 'teams': [],}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await teams.list( + ); + expect(response, isA()); + + }); + + test('test method create()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'VIP', + 'total': 7, + 'prefs': {},}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await teams.create( + teamId: '[TEAM_ID]', + name: '[NAME]', + ); + expect(response, isA()); + + }); + + test('test method get()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'VIP', + 'total': 7, + 'prefs': {},}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await teams.get( + teamId: '[TEAM_ID]', + ); + expect(response, isA()); + + }); + + test('test method updateName()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'VIP', + 'total': 7, + 'prefs': {},}; + + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await teams.updateName( + teamId: '[TEAM_ID]', + name: '[NAME]', + ); + expect(response, isA()); + + }); + + test('test method delete()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await teams.delete( + teamId: '[TEAM_ID]', + ); + }); + + test('test method listMemberships()', () async { + final Map data = { + 'total': 5, + 'memberships': [],}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await teams.listMemberships( + teamId: '[TEAM_ID]', + ); + expect(response, isA()); + + }); + + test('test method createMembership()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c16897e', + 'userName': 'John Doe', + 'userEmail': 'john@appwrite.io', + 'teamId': '5e5ea5c16897e', + 'teamName': 'VIP', + 'invited': '2020-10-15T06:38:00.000+00:00', + 'joined': '2020-10-15T06:38:00.000+00:00', + 'confirm': true, + 'roles': [],}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await teams.createMembership( + teamId: '[TEAM_ID]', + roles: [], + url: 'https://example.com', + ); + expect(response, isA()); + + }); + + test('test method getMembership()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c16897e', + 'userName': 'John Doe', + 'userEmail': 'john@appwrite.io', + 'teamId': '5e5ea5c16897e', + 'teamName': 'VIP', + 'invited': '2020-10-15T06:38:00.000+00:00', + 'joined': '2020-10-15T06:38:00.000+00:00', + 'confirm': true, + 'roles': [],}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await teams.getMembership( + teamId: '[TEAM_ID]', + membershipId: '[MEMBERSHIP_ID]', + ); + expect(response, isA()); + + }); + + test('test method updateMembershipRoles()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c16897e', + 'userName': 'John Doe', + 'userEmail': 'john@appwrite.io', + 'teamId': '5e5ea5c16897e', + 'teamName': 'VIP', + 'invited': '2020-10-15T06:38:00.000+00:00', + 'joined': '2020-10-15T06:38:00.000+00:00', + 'confirm': true, + 'roles': [],}; + + + when(client.call( + HttpMethod.patch, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await teams.updateMembershipRoles( + teamId: '[TEAM_ID]', + membershipId: '[MEMBERSHIP_ID]', + roles: [], + ); + expect(response, isA()); + + }); + + test('test method deleteMembership()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await teams.deleteMembership( + teamId: '[TEAM_ID]', + membershipId: '[MEMBERSHIP_ID]', + ); + }); + + test('test method updateMembershipStatus()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c16897e', + 'userName': 'John Doe', + 'userEmail': 'john@appwrite.io', + 'teamId': '5e5ea5c16897e', + 'teamName': 'VIP', + 'invited': '2020-10-15T06:38:00.000+00:00', + 'joined': '2020-10-15T06:38:00.000+00:00', + 'confirm': true, + 'roles': [],}; + + + when(client.call( + HttpMethod.patch, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await teams.updateMembershipStatus( + teamId: '[TEAM_ID]', + membershipId: '[MEMBERSHIP_ID]', + userId: '[USER_ID]', + secret: '[SECRET]', + ); + expect(response, isA()); + + }); + + test('test method getPrefs()', () async { + final Map data = {}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await teams.getPrefs( + teamId: '[TEAM_ID]', + ); + expect(response, isA()); + + }); + + test('test method updatePrefs()', () async { + final Map data = {}; + + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await teams.updatePrefs( + teamId: '[TEAM_ID]', + prefs: {}, + ); + expect(response, isA()); + + }); + + }); +} \ No newline at end of file diff --git a/test/src/cookie_manager_test.dart b/test/src/cookie_manager_test.dart new file mode 100644 index 0000000..e29c284 --- /dev/null +++ b/test/src/cookie_manager_test.dart @@ -0,0 +1,99 @@ +import 'package:appwrite/src/cookie_manager.dart'; +import 'package:cookie_jar/cookie_jar.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:http/http.dart'; + +void main() { + group('getCookies()', () { + test('conversion', () { + List cookies = [ + Cookie('name', 'value'), + Cookie('name2', 'value2'), + ]; + + expect( + CookieManager.getCookies(cookies), + "name=value; name2=value2", + ); + }); + }); + + group('onRequest()', () { + late CookieJar cookieJar; + late CookieManager cookieManager; + + setUp(() { + cookieJar = CookieJar(); + cookieManager = CookieManager(cookieJar); + }); + + test('without cookie', () async { + final request = Request('GET', Uri.parse('https://appwrite.io')); + await cookieManager.onRequest(request); + expect(request.headers, {}); + }); + + test('with cookie', () async { + final uri = Uri.parse('https://appwrite.io'); + final cookies = [ + Cookie('name', 'value'), + Cookie('name2', 'value2'), + ]; + cookieJar.saveFromResponse(uri, cookies); + + final request = Request('GET', uri); + await cookieManager.onRequest(request); + expect(request.headers, { + 'cookie': 'name=value; name2=value2' + }); + }); + }); + + group('onResponse()', () { + late CookieJar cookieJar; + late CookieManager cookieManager; + + setUp(() { + cookieJar = CookieJar(); + cookieManager = CookieManager(cookieJar); + }); + + test('without cookie', () async { + final uri = Uri.parse('https://appwrite.io'); + final request = Request('POST', uri); + final response = Response( + 'body', + 200, + headers: {}, + request: request, + ); + + await cookieManager.onResponse(response); + + final cookies = await cookieJar.loadForRequest(uri); + + expect(cookies, []); + }); + + test('with cookie', () async { + final uri = Uri.parse('https://appwrite.io'); + final request = Request('POST', uri); + final response = Response( + 'body', + 200, + headers: { + 'set-cookie': 'name=value' + }, + request: request, + ); + + await cookieManager.onResponse(response); + + final cookies = await cookieJar.loadForRequest(uri); + + expect(cookies.length, 1); + expect(cookies.first.name, 'name'); + expect(cookies.first.value, 'value'); + }); + }); +} \ No newline at end of file diff --git a/test/src/enums_test.dart b/test/src/enums_test.dart new file mode 100644 index 0000000..6cd9ae0 --- /dev/null +++ b/test/src/enums_test.dart @@ -0,0 +1,12 @@ +import 'package:appwrite/src/enums.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('name()', () { + for (final method in HttpMethod.values) { + test('returns ${method.toString().split('.').last.toUpperCase()} for $method', () { + expect(method.name(), method.toString().split('.').last.toUpperCase()); + }); + } + }); +} \ No newline at end of file diff --git a/test/src/exception_test.dart b/test/src/exception_test.dart new file mode 100644 index 0000000..590ad28 --- /dev/null +++ b/test/src/exception_test.dart @@ -0,0 +1,17 @@ +import 'package:appwrite/src/exception.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('AppwriteException', () { + test('toString should return correct string representation', () { + final exception1 = AppwriteException(); + expect(exception1.toString(), equals('AppwriteException')); + + final exception2 = AppwriteException('Some error message'); + expect(exception2.toString(), equals('AppwriteException: , Some error message (0)')); + + final exception3 = AppwriteException('Invalid request', 400, 'ValidationError'); + expect(exception3.toString(), equals('AppwriteException: ValidationError, Invalid request (400)')); + }); + }); +} diff --git a/test/src/input_file_test.dart b/test/src/input_file_test.dart new file mode 100644 index 0000000..ee7a82e --- /dev/null +++ b/test/src/input_file_test.dart @@ -0,0 +1,47 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:appwrite/src/exception.dart'; +import 'package:appwrite/src/input_file.dart'; + +void main() { + group('InputFile', () { + test('throws exception when neither path nor bytes are provided', () { + expect( + () => InputFile(), + throwsA(isA().having( + (e) => e.message, + 'message', + 'One of `path` or `bytes` is required', + )), + ); + }); + + test('throws exception when path and bytes are both null', () { + expect( + () => InputFile(path: null, bytes: null), + throwsA(isA().having( + (e) => e.message, + 'message', + 'One of `path` or `bytes` is required', + )), + ); + }); + + test('creates InputFile from path', () { + final inputFile = InputFile.fromPath(path: '/path/to/file'); + + expect(inputFile.path, '/path/to/file'); + expect(inputFile.filename, isNull); + expect(inputFile.contentType, isNull); + expect(inputFile.bytes, isNull); + }); + + test('creates InputFile from bytes', () { + final inputFile = InputFile.fromBytes(bytes: [1, 2, 3], filename: 'file.txt'); + + expect(inputFile.path, isNull); + expect(inputFile.filename, 'file.txt'); + expect(inputFile.contentType, isNull); + expect(inputFile.bytes, [1, 2, 3]); + }); + }); +} diff --git a/test/src/interceptor_test.dart b/test/src/interceptor_test.dart new file mode 100644 index 0000000..3752c38 --- /dev/null +++ b/test/src/interceptor_test.dart @@ -0,0 +1,39 @@ +import 'dart:async'; +import 'package:http/http.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:appwrite/src/interceptor.dart'; + +class MockRequest extends Mock implements BaseRequest { + final Map headers = {}; + + @override + Future send() async { + final response = StreamedResponse(ByteStream.fromBytes([]), 200); + response.headers.addAll(headers); + return response; + } +} + +void main() { + group('HeadersInterceptor', () { + test('onRequest should add headers to the request', () async { + final headers = {'Authorization': 'Bearer token123'}; + final interceptor = HeadersInterceptor(headers); + final request = MockRequest(); + + final interceptedRequest = await interceptor.onRequest(request); + + expect(interceptedRequest.headers, equals(headers)); + }); + + test('onResponse should return the same response', () async { + final response = Response('', 200); + final interceptor = HeadersInterceptor({}); + + final interceptedResponse = await interceptor.onResponse(response); + + expect(interceptedResponse, equals(response)); + }); + }); +} diff --git a/test/src/models/algo_argon2_test.dart b/test/src/models/algo_argon2_test.dart new file mode 100644 index 0000000..f82df4d --- /dev/null +++ b/test/src/models/algo_argon2_test.dart @@ -0,0 +1,24 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('AlgoArgon2', () { + + test('model', () { + final model = AlgoArgon2( + type: 'argon2', + memoryCost: 65536, + timeCost: 4, + threads: 3, + ); + + final map = model.toMap(); + final result = AlgoArgon2.fromMap(map); + + expect(result.type, 'argon2'); + expect(result.memoryCost, 65536); + expect(result.timeCost, 4); + expect(result.threads, 3); + }); + }); +} diff --git a/test/src/models/algo_bcrypt_test.dart b/test/src/models/algo_bcrypt_test.dart new file mode 100644 index 0000000..d77bb45 --- /dev/null +++ b/test/src/models/algo_bcrypt_test.dart @@ -0,0 +1,18 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('AlgoBcrypt', () { + + test('model', () { + final model = AlgoBcrypt( + type: 'bcrypt', + ); + + final map = model.toMap(); + final result = AlgoBcrypt.fromMap(map); + + expect(result.type, 'bcrypt'); + }); + }); +} diff --git a/test/src/models/algo_md5_test.dart b/test/src/models/algo_md5_test.dart new file mode 100644 index 0000000..b8b724c --- /dev/null +++ b/test/src/models/algo_md5_test.dart @@ -0,0 +1,18 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('AlgoMd5', () { + + test('model', () { + final model = AlgoMd5( + type: 'md5', + ); + + final map = model.toMap(); + final result = AlgoMd5.fromMap(map); + + expect(result.type, 'md5'); + }); + }); +} diff --git a/test/src/models/algo_phpass_test.dart b/test/src/models/algo_phpass_test.dart new file mode 100644 index 0000000..65e15de --- /dev/null +++ b/test/src/models/algo_phpass_test.dart @@ -0,0 +1,18 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('AlgoPhpass', () { + + test('model', () { + final model = AlgoPhpass( + type: 'phpass', + ); + + final map = model.toMap(); + final result = AlgoPhpass.fromMap(map); + + expect(result.type, 'phpass'); + }); + }); +} diff --git a/test/src/models/algo_scrypt_modified_test.dart b/test/src/models/algo_scrypt_modified_test.dart new file mode 100644 index 0000000..8e5c274 --- /dev/null +++ b/test/src/models/algo_scrypt_modified_test.dart @@ -0,0 +1,24 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('AlgoScryptModified', () { + + test('model', () { + final model = AlgoScryptModified( + type: 'scryptMod', + salt: 'UxLMreBr6tYyjQ==', + saltSeparator: 'Bw==', + signerKey: 'XyEKE9RcTDeLEsL/RjwPDBv/RqDl8fb3gpYEOQaPihbxf1ZAtSOHCjuAAa7Q3oHpCYhXSN9tizHgVOwn6krflQ==', + ); + + final map = model.toMap(); + final result = AlgoScryptModified.fromMap(map); + + expect(result.type, 'scryptMod'); + expect(result.salt, 'UxLMreBr6tYyjQ=='); + expect(result.saltSeparator, 'Bw=='); + expect(result.signerKey, 'XyEKE9RcTDeLEsL/RjwPDBv/RqDl8fb3gpYEOQaPihbxf1ZAtSOHCjuAAa7Q3oHpCYhXSN9tizHgVOwn6krflQ=='); + }); + }); +} diff --git a/test/src/models/algo_scrypt_test.dart b/test/src/models/algo_scrypt_test.dart new file mode 100644 index 0000000..3e8c90b --- /dev/null +++ b/test/src/models/algo_scrypt_test.dart @@ -0,0 +1,26 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('AlgoScrypt', () { + + test('model', () { + final model = AlgoScrypt( + type: 'scrypt', + costCpu: 8, + costMemory: 14, + costParallel: 1, + length: 64, + ); + + final map = model.toMap(); + final result = AlgoScrypt.fromMap(map); + + expect(result.type, 'scrypt'); + expect(result.costCpu, 8); + expect(result.costMemory, 14); + expect(result.costParallel, 1); + expect(result.length, 64); + }); + }); +} diff --git a/test/src/models/algo_sha_test.dart b/test/src/models/algo_sha_test.dart new file mode 100644 index 0000000..7d4a2b4 --- /dev/null +++ b/test/src/models/algo_sha_test.dart @@ -0,0 +1,18 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('AlgoSha', () { + + test('model', () { + final model = AlgoSha( + type: 'sha', + ); + + final map = model.toMap(); + final result = AlgoSha.fromMap(map); + + expect(result.type, 'sha'); + }); + }); +} diff --git a/test/src/models/continent_list_test.dart b/test/src/models/continent_list_test.dart new file mode 100644 index 0000000..0dc0597 --- /dev/null +++ b/test/src/models/continent_list_test.dart @@ -0,0 +1,20 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('ContinentList', () { + + test('model', () { + final model = ContinentList( + total: 5, + continents: [], + ); + + final map = model.toMap(); + final result = ContinentList.fromMap(map); + + expect(result.total, 5); + expect(result.continents, []); + }); + }); +} diff --git a/test/src/models/continent_test.dart b/test/src/models/continent_test.dart new file mode 100644 index 0000000..3e47afc --- /dev/null +++ b/test/src/models/continent_test.dart @@ -0,0 +1,20 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('Continent', () { + + test('model', () { + final model = Continent( + name: 'Europe', + code: 'EU', + ); + + final map = model.toMap(); + final result = Continent.fromMap(map); + + expect(result.name, 'Europe'); + expect(result.code, 'EU'); + }); + }); +} diff --git a/test/src/models/country_list_test.dart b/test/src/models/country_list_test.dart new file mode 100644 index 0000000..f632136 --- /dev/null +++ b/test/src/models/country_list_test.dart @@ -0,0 +1,20 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('CountryList', () { + + test('model', () { + final model = CountryList( + total: 5, + countries: [], + ); + + final map = model.toMap(); + final result = CountryList.fromMap(map); + + expect(result.total, 5); + expect(result.countries, []); + }); + }); +} diff --git a/test/src/models/country_test.dart b/test/src/models/country_test.dart new file mode 100644 index 0000000..9f644c0 --- /dev/null +++ b/test/src/models/country_test.dart @@ -0,0 +1,20 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('Country', () { + + test('model', () { + final model = Country( + name: 'United States', + code: 'US', + ); + + final map = model.toMap(); + final result = Country.fromMap(map); + + expect(result.name, 'United States'); + expect(result.code, 'US'); + }); + }); +} diff --git a/test/src/models/currency_list_test.dart b/test/src/models/currency_list_test.dart new file mode 100644 index 0000000..bfcc89e --- /dev/null +++ b/test/src/models/currency_list_test.dart @@ -0,0 +1,20 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('CurrencyList', () { + + test('model', () { + final model = CurrencyList( + total: 5, + currencies: [], + ); + + final map = model.toMap(); + final result = CurrencyList.fromMap(map); + + expect(result.total, 5); + expect(result.currencies, []); + }); + }); +} diff --git a/test/src/models/currency_test.dart b/test/src/models/currency_test.dart new file mode 100644 index 0000000..60c3ff1 --- /dev/null +++ b/test/src/models/currency_test.dart @@ -0,0 +1,30 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('Currency', () { + + test('model', () { + final model = Currency( + symbol: '\$', + name: 'US dollar', + symbolNative: '\$', + decimalDigits: 2, + rounding: 0, + code: 'USD', + namePlural: 'US dollars', + ); + + final map = model.toMap(); + final result = Currency.fromMap(map); + + expect(result.symbol, '\$'); + expect(result.name, 'US dollar'); + expect(result.symbolNative, '\$'); + expect(result.decimalDigits, 2); + expect(result.rounding, 0); + expect(result.code, 'USD'); + expect(result.namePlural, 'US dollars'); + }); + }); +} diff --git a/test/src/models/document_list_test.dart b/test/src/models/document_list_test.dart new file mode 100644 index 0000000..6991889 --- /dev/null +++ b/test/src/models/document_list_test.dart @@ -0,0 +1,20 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('DocumentList', () { + + test('model', () { + final model = DocumentList( + total: 5, + documents: [], + ); + + final map = model.toMap(); + final result = DocumentList.fromMap(map); + + expect(result.total, 5); + expect(result.documents, []); + }); + }); +} diff --git a/test/src/models/document_test.dart b/test/src/models/document_test.dart new file mode 100644 index 0000000..8888013 --- /dev/null +++ b/test/src/models/document_test.dart @@ -0,0 +1,29 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('Document', () { + + test('model', () { + final model = Document( + $id: '5e5ea5c16897e', + $collectionId: '5e5ea5c15117e', + $databaseId: '5e5ea5c15117e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + $permissions: [], + data: {}, + ); + + final map = model.toMap(); + final result = Document.fromMap(map); + + expect(result.$id, '5e5ea5c16897e'); + expect(result.$collectionId, '5e5ea5c15117e'); + expect(result.$databaseId, '5e5ea5c15117e'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$permissions, []); + }); + }); +} diff --git a/test/src/models/execution_list_test.dart b/test/src/models/execution_list_test.dart new file mode 100644 index 0000000..17d304c --- /dev/null +++ b/test/src/models/execution_list_test.dart @@ -0,0 +1,20 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('ExecutionList', () { + + test('model', () { + final model = ExecutionList( + total: 5, + executions: [], + ); + + final map = model.toMap(); + final result = ExecutionList.fromMap(map); + + expect(result.total, 5); + expect(result.executions, []); + }); + }); +} diff --git a/test/src/models/execution_test.dart b/test/src/models/execution_test.dart new file mode 100644 index 0000000..befb3f7 --- /dev/null +++ b/test/src/models/execution_test.dart @@ -0,0 +1,40 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('Execution', () { + + test('model', () { + final model = Execution( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + $permissions: [], + functionId: '5e5ea6g16897e', + trigger: 'http', + status: 'processing', + statusCode: 0, + response: '', + stdout: '', + stderr: '', + duration: 0.4, + ); + + final map = model.toMap(); + final result = Execution.fromMap(map); + + expect(result.$id, '5e5ea5c16897e'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$permissions, []); + expect(result.functionId, '5e5ea6g16897e'); + expect(result.trigger, 'http'); + expect(result.status, 'processing'); + expect(result.statusCode, 0); + expect(result.response, ''); + expect(result.stdout, ''); + expect(result.stderr, ''); + expect(result.duration, 0.4); + }); + }); +} diff --git a/test/src/models/file_list_test.dart b/test/src/models/file_list_test.dart new file mode 100644 index 0000000..529f596 --- /dev/null +++ b/test/src/models/file_list_test.dart @@ -0,0 +1,20 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('FileList', () { + + test('model', () { + final model = FileList( + total: 5, + files: [], + ); + + final map = model.toMap(); + final result = FileList.fromMap(map); + + expect(result.total, 5); + expect(result.files, []); + }); + }); +} diff --git a/test/src/models/file_test.dart b/test/src/models/file_test.dart new file mode 100644 index 0000000..50b1559 --- /dev/null +++ b/test/src/models/file_test.dart @@ -0,0 +1,38 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('File', () { + + test('model', () { + final model = File( + $id: '5e5ea5c16897e', + bucketId: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + $permissions: [], + name: 'Pink.png', + signature: '5d529fd02b544198ae075bd57c1762bb', + mimeType: 'image/png', + sizeOriginal: 17890, + chunksTotal: 17890, + chunksUploaded: 17890, + ); + + final map = model.toMap(); + final result = File.fromMap(map); + + expect(result.$id, '5e5ea5c16897e'); + expect(result.bucketId, '5e5ea5c16897e'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$permissions, []); + expect(result.name, 'Pink.png'); + expect(result.signature, '5d529fd02b544198ae075bd57c1762bb'); + expect(result.mimeType, 'image/png'); + expect(result.sizeOriginal, 17890); + expect(result.chunksTotal, 17890); + expect(result.chunksUploaded, 17890); + }); + }); +} diff --git a/test/src/models/jwt_test.dart b/test/src/models/jwt_test.dart new file mode 100644 index 0000000..9f357e6 --- /dev/null +++ b/test/src/models/jwt_test.dart @@ -0,0 +1,18 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('Jwt', () { + + test('model', () { + final model = Jwt( + jwt: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c', + ); + + final map = model.toMap(); + final result = Jwt.fromMap(map); + + expect(result.jwt, 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'); + }); + }); +} diff --git a/test/src/models/language_list_test.dart b/test/src/models/language_list_test.dart new file mode 100644 index 0000000..bff06c9 --- /dev/null +++ b/test/src/models/language_list_test.dart @@ -0,0 +1,20 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('LanguageList', () { + + test('model', () { + final model = LanguageList( + total: 5, + languages: [], + ); + + final map = model.toMap(); + final result = LanguageList.fromMap(map); + + expect(result.total, 5); + expect(result.languages, []); + }); + }); +} diff --git a/test/src/models/language_test.dart b/test/src/models/language_test.dart new file mode 100644 index 0000000..0cddf22 --- /dev/null +++ b/test/src/models/language_test.dart @@ -0,0 +1,22 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('Language', () { + + test('model', () { + final model = Language( + name: 'Italian', + code: 'it', + nativeName: 'Italiano', + ); + + final map = model.toMap(); + final result = Language.fromMap(map); + + expect(result.name, 'Italian'); + expect(result.code, 'it'); + expect(result.nativeName, 'Italiano'); + }); + }); +} diff --git a/test/src/models/locale_test.dart b/test/src/models/locale_test.dart new file mode 100644 index 0000000..9a90c1c --- /dev/null +++ b/test/src/models/locale_test.dart @@ -0,0 +1,30 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('Locale', () { + + test('model', () { + final model = Locale( + ip: '127.0.0.1', + countryCode: 'US', + country: 'United States', + continentCode: 'NA', + continent: 'North America', + eu: true, + currency: 'USD', + ); + + final map = model.toMap(); + final result = Locale.fromMap(map); + + expect(result.ip, '127.0.0.1'); + expect(result.countryCode, 'US'); + expect(result.country, 'United States'); + expect(result.continentCode, 'NA'); + expect(result.continent, 'North America'); + expect(result.eu, true); + expect(result.currency, 'USD'); + }); + }); +} diff --git a/test/src/models/log_list_test.dart b/test/src/models/log_list_test.dart new file mode 100644 index 0000000..8211953 --- /dev/null +++ b/test/src/models/log_list_test.dart @@ -0,0 +1,20 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('LogList', () { + + test('model', () { + final model = LogList( + total: 5, + logs: [], + ); + + final map = model.toMap(); + final result = LogList.fromMap(map); + + expect(result.total, 5); + expect(result.logs, []); + }); + }); +} diff --git a/test/src/models/log_test.dart b/test/src/models/log_test.dart new file mode 100644 index 0000000..c82d920 --- /dev/null +++ b/test/src/models/log_test.dart @@ -0,0 +1,58 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('Log', () { + + test('model', () { + final model = Log( + event: 'account.sessions.create', + userId: '610fc2f985ee0', + userEmail: 'john@appwrite.io', + userName: 'John Doe', + mode: 'admin', + ip: '127.0.0.1', + time: '2020-10-15T06:38:00.000+00:00', + osCode: 'Mac', + osName: 'Mac', + osVersion: 'Mac', + clientType: 'browser', + clientCode: 'CM', + clientName: 'Chrome Mobile iOS', + clientVersion: '84.0', + clientEngine: 'WebKit', + clientEngineVersion: '605.1.15', + deviceName: 'smartphone', + deviceBrand: 'Google', + deviceModel: 'Nexus 5', + countryCode: 'US', + countryName: 'United States', + ); + + final map = model.toMap(); + final result = Log.fromMap(map); + + expect(result.event, 'account.sessions.create'); + expect(result.userId, '610fc2f985ee0'); + expect(result.userEmail, 'john@appwrite.io'); + expect(result.userName, 'John Doe'); + expect(result.mode, 'admin'); + expect(result.ip, '127.0.0.1'); + expect(result.time, '2020-10-15T06:38:00.000+00:00'); + expect(result.osCode, 'Mac'); + expect(result.osName, 'Mac'); + expect(result.osVersion, 'Mac'); + expect(result.clientType, 'browser'); + expect(result.clientCode, 'CM'); + expect(result.clientName, 'Chrome Mobile iOS'); + expect(result.clientVersion, '84.0'); + expect(result.clientEngine, 'WebKit'); + expect(result.clientEngineVersion, '605.1.15'); + expect(result.deviceName, 'smartphone'); + expect(result.deviceBrand, 'Google'); + expect(result.deviceModel, 'Nexus 5'); + expect(result.countryCode, 'US'); + expect(result.countryName, 'United States'); + }); + }); +} diff --git a/test/src/models/membership_list_test.dart b/test/src/models/membership_list_test.dart new file mode 100644 index 0000000..18eb01f --- /dev/null +++ b/test/src/models/membership_list_test.dart @@ -0,0 +1,20 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('MembershipList', () { + + test('model', () { + final model = MembershipList( + total: 5, + memberships: [], + ); + + final map = model.toMap(); + final result = MembershipList.fromMap(map); + + expect(result.total, 5); + expect(result.memberships, []); + }); + }); +} diff --git a/test/src/models/membership_test.dart b/test/src/models/membership_test.dart new file mode 100644 index 0000000..bc7b3eb --- /dev/null +++ b/test/src/models/membership_test.dart @@ -0,0 +1,40 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('Membership', () { + + test('model', () { + final model = Membership( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + userId: '5e5ea5c16897e', + userName: 'John Doe', + userEmail: 'john@appwrite.io', + teamId: '5e5ea5c16897e', + teamName: 'VIP', + invited: '2020-10-15T06:38:00.000+00:00', + joined: '2020-10-15T06:38:00.000+00:00', + confirm: true, + roles: [], + ); + + final map = model.toMap(); + final result = Membership.fromMap(map); + + expect(result.$id, '5e5ea5c16897e'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.userId, '5e5ea5c16897e'); + expect(result.userName, 'John Doe'); + expect(result.userEmail, 'john@appwrite.io'); + expect(result.teamId, '5e5ea5c16897e'); + expect(result.teamName, 'VIP'); + expect(result.invited, '2020-10-15T06:38:00.000+00:00'); + expect(result.joined, '2020-10-15T06:38:00.000+00:00'); + expect(result.confirm, true); + expect(result.roles, []); + }); + }); +} diff --git a/test/src/models/phone_list_test.dart b/test/src/models/phone_list_test.dart new file mode 100644 index 0000000..b8816c3 --- /dev/null +++ b/test/src/models/phone_list_test.dart @@ -0,0 +1,20 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('PhoneList', () { + + test('model', () { + final model = PhoneList( + total: 5, + phones: [], + ); + + final map = model.toMap(); + final result = PhoneList.fromMap(map); + + expect(result.total, 5); + expect(result.phones, []); + }); + }); +} diff --git a/test/src/models/phone_test.dart b/test/src/models/phone_test.dart new file mode 100644 index 0000000..444a6f2 --- /dev/null +++ b/test/src/models/phone_test.dart @@ -0,0 +1,22 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('Phone', () { + + test('model', () { + final model = Phone( + code: '+1', + countryCode: 'US', + countryName: 'United States', + ); + + final map = model.toMap(); + final result = Phone.fromMap(map); + + expect(result.code, '+1'); + expect(result.countryCode, 'US'); + expect(result.countryName, 'United States'); + }); + }); +} diff --git a/test/src/models/preferences_test.dart b/test/src/models/preferences_test.dart new file mode 100644 index 0000000..aaaec5c --- /dev/null +++ b/test/src/models/preferences_test.dart @@ -0,0 +1,17 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('Preferences', () { + + test('model', () { + final model = Preferences( + data: {}, + ); + + final map = model.toMap(); + final result = Preferences.fromMap(map); + + }); + }); +} diff --git a/test/src/models/session_list_test.dart b/test/src/models/session_list_test.dart new file mode 100644 index 0000000..cc718a1 --- /dev/null +++ b/test/src/models/session_list_test.dart @@ -0,0 +1,20 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('SessionList', () { + + test('model', () { + final model = SessionList( + total: 5, + sessions: [], + ); + + final map = model.toMap(); + final result = SessionList.fromMap(map); + + expect(result.total, 5); + expect(result.sessions, []); + }); + }); +} diff --git a/test/src/models/session_test.dart b/test/src/models/session_test.dart new file mode 100644 index 0000000..259ba68 --- /dev/null +++ b/test/src/models/session_test.dart @@ -0,0 +1,66 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('Session', () { + + test('model', () { + final model = Session( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + userId: '5e5bb8c16897e', + expire: '2020-10-15T06:38:00.000+00:00', + provider: 'email', + providerUid: 'user@example.com', + providerAccessToken: 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + providerAccessTokenExpiry: '2020-10-15T06:38:00.000+00:00', + providerRefreshToken: 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + ip: '127.0.0.1', + osCode: 'Mac', + osName: 'Mac', + osVersion: 'Mac', + clientType: 'browser', + clientCode: 'CM', + clientName: 'Chrome Mobile iOS', + clientVersion: '84.0', + clientEngine: 'WebKit', + clientEngineVersion: '605.1.15', + deviceName: 'smartphone', + deviceBrand: 'Google', + deviceModel: 'Nexus 5', + countryCode: 'US', + countryName: 'United States', + current: true, + ); + + final map = model.toMap(); + final result = Session.fromMap(map); + + expect(result.$id, '5e5ea5c16897e'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.userId, '5e5bb8c16897e'); + expect(result.expire, '2020-10-15T06:38:00.000+00:00'); + expect(result.provider, 'email'); + expect(result.providerUid, 'user@example.com'); + expect(result.providerAccessToken, 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3'); + expect(result.providerAccessTokenExpiry, '2020-10-15T06:38:00.000+00:00'); + expect(result.providerRefreshToken, 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3'); + expect(result.ip, '127.0.0.1'); + expect(result.osCode, 'Mac'); + expect(result.osName, 'Mac'); + expect(result.osVersion, 'Mac'); + expect(result.clientType, 'browser'); + expect(result.clientCode, 'CM'); + expect(result.clientName, 'Chrome Mobile iOS'); + expect(result.clientVersion, '84.0'); + expect(result.clientEngine, 'WebKit'); + expect(result.clientEngineVersion, '605.1.15'); + expect(result.deviceName, 'smartphone'); + expect(result.deviceBrand, 'Google'); + expect(result.deviceModel, 'Nexus 5'); + expect(result.countryCode, 'US'); + expect(result.countryName, 'United States'); + expect(result.current, true); + }); + }); +} diff --git a/test/src/models/team_list_test.dart b/test/src/models/team_list_test.dart new file mode 100644 index 0000000..6c71710 --- /dev/null +++ b/test/src/models/team_list_test.dart @@ -0,0 +1,20 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('TeamList', () { + + test('model', () { + final model = TeamList( + total: 5, + teams: [], + ); + + final map = model.toMap(); + final result = TeamList.fromMap(map); + + expect(result.total, 5); + expect(result.teams, []); + }); + }); +} diff --git a/test/src/models/team_test.dart b/test/src/models/team_test.dart new file mode 100644 index 0000000..123b458 --- /dev/null +++ b/test/src/models/team_test.dart @@ -0,0 +1,28 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('Team', () { + + test('model', () { + final model = Team( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + name: 'VIP', + total: 7, + prefs: Preferences(data: {}), + ); + + final map = model.toMap(); + final result = Team.fromMap(map); + + expect(result.$id, '5e5ea5c16897e'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.name, 'VIP'); + expect(result.total, 7); + expect(result.prefs.data, {"data": {}}); + }); + }); +} diff --git a/test/src/models/token_test.dart b/test/src/models/token_test.dart new file mode 100644 index 0000000..8ac3339 --- /dev/null +++ b/test/src/models/token_test.dart @@ -0,0 +1,26 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('Token', () { + + test('model', () { + final model = Token( + $id: 'bb8ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + userId: '5e5ea5c168bb8', + secret: '', + expire: '2020-10-15T06:38:00.000+00:00', + ); + + final map = model.toMap(); + final result = Token.fromMap(map); + + expect(result.$id, 'bb8ea5c16897e'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.userId, '5e5ea5c168bb8'); + expect(result.secret, ''); + expect(result.expire, '2020-10-15T06:38:00.000+00:00'); + }); + }); +} diff --git a/test/src/models/user_test.dart b/test/src/models/user_test.dart new file mode 100644 index 0000000..795b666 --- /dev/null +++ b/test/src/models/user_test.dart @@ -0,0 +1,40 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('User', () { + + test('model', () { + final model = User( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + name: 'John Doe', + registration: '2020-10-15T06:38:00.000+00:00', + status: true, + passwordUpdate: '2020-10-15T06:38:00.000+00:00', + email: 'john@appwrite.io', + phone: '+4930901820', + emailVerification: true, + phoneVerification: true, + prefs: Preferences(data: {}), + ); + + final map = model.toMap(); + final result = User.fromMap(map); + + expect(result.$id, '5e5ea5c16897e'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.name, 'John Doe'); + expect(result.registration, '2020-10-15T06:38:00.000+00:00'); + expect(result.status, true); + expect(result.passwordUpdate, '2020-10-15T06:38:00.000+00:00'); + expect(result.email, 'john@appwrite.io'); + expect(result.phone, '+4930901820'); + expect(result.emailVerification, true); + expect(result.phoneVerification, true); + expect(result.prefs.data, {"data": {}}); + }); + }); +} diff --git a/test/src/realtime_response_connected_test.dart b/test/src/realtime_response_connected_test.dart new file mode 100644 index 0000000..7433140 --- /dev/null +++ b/test/src/realtime_response_connected_test.dart @@ -0,0 +1,68 @@ +import 'dart:convert'; +import 'package:flutter/foundation.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:appwrite/src/realtime_response_connected.dart'; + +void main() { + group('RealtimeResponseConnected', () { + final channels = ['channel1', 'channel2']; + final user = {'id': 123, 'name': 'John Doe'}; + final response1 = RealtimeResponseConnected(channels: channels, user: user); + + test('copyWith should create a new instance with updated properties', () { + final newChannels = ['channel3', 'channel4']; + final newUser = {'id': 456, 'name': 'Jane Smith'}; + + final updatedResponse = response1.copyWith(channels: newChannels, user: newUser); + + expect(updatedResponse.channels, equals(newChannels)); + expect(updatedResponse.user, equals(newUser)); + }); + + test('toMap should return a map representation of the response', () { + final responseMap = response1.toMap(); + + expect(responseMap['channels'], equals(channels)); + expect(responseMap['user'], equals(user)); + }); + + test('fromMap should create an instance from a map', () { + final responseMap = {'channels': channels, 'user': user}; + + final response2 = RealtimeResponseConnected.fromMap(responseMap); + + expect(response2.channels, equals(channels)); + expect(response2.user, equals(user)); + }); + + test('toJson and fromJson should convert to/from JSON', () { + final jsonString = response1.toJson(); + + final response3 = RealtimeResponseConnected.fromJson(jsonString); + + expect(response3.channels, equals(channels)); + expect(response3.user, equals(user)); + }); + + test('toString should return a string representation of the response', () { + final responseString = response1.toString(); + + expect(responseString, equals('RealtimeResponseConnected(channels: $channels, user: $user)')); + }); + + test('equality operator should compare two instances', () { + final response2 = RealtimeResponseConnected(channels: channels, user: user); + + expect(response1 == response2, isTrue); + }); + + test('hashCode should return a unique hash value', () { + final hashCode1 = response1.hashCode; + + final response2 = RealtimeResponseConnected(channels: channels, user: user); + final hashCode2 = response2.hashCode; + + expect(hashCode1, equals(hashCode2)); + }); + }); +} diff --git a/test/src/realtime_response_test.dart b/test/src/realtime_response_test.dart new file mode 100644 index 0000000..4435280 --- /dev/null +++ b/test/src/realtime_response_test.dart @@ -0,0 +1,69 @@ +import 'dart:convert'; +import 'package:flutter/foundation.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:appwrite/src/realtime_response.dart'; + +void main() { + group('RealtimeResponse', () { + final type = 'event'; + final data = {'event': 'message', 'payload': 'Hello, world!'}; + final response1 = RealtimeResponse(type: type, data: data); + + test('copyWith should create a new instance with updated properties', () { + final newType = 'response'; + final newData = {'result': true}; + + final updatedResponse = response1.copyWith(type: newType, data: newData); + + expect(updatedResponse.type, equals(newType)); + expect(updatedResponse.data, equals(newData)); + }); + + test('toMap should return a map representation of the response', () { + final responseMap = response1.toMap(); + + expect(responseMap['type'], equals(type)); + expect(responseMap['data'], equals(data)); + }); + + test('fromMap should create an instance from a map', () { + final responseMap = {'type': type, 'data': data}; + + final response2 = RealtimeResponse.fromMap(responseMap); + + expect(response2.type, equals(type)); + expect(response2.data, equals(data)); + }); + + test('toJson and fromJson should convert to/from JSON', () { + final jsonString = response1.toJson(); + + final response3 = RealtimeResponse.fromJson(jsonString); + + expect(response3.type, equals(type)); + expect(response3.data, equals(data)); + }); + + test('toString should return a string representation of the response', () { + final responseString = response1.toString(); + + expect( + responseString, equals('RealtimeResponse(type: $type, data: $data)')); + }); + + test('equality operator should compare two instances', () { + final response2 = RealtimeResponse(type: type, data: data); + + expect(response1 == response2, isTrue); + }); + + test('hashCode should return a unique hash value', () { + final hashCode1 = response1.hashCode; + + final response2 = RealtimeResponse(type: type, data: data); + final hashCode2 = response2.hashCode; + + expect(hashCode1, equals(hashCode2)); + }); + }); +} diff --git a/test/src/realtime_subscription_test.dart b/test/src/realtime_subscription_test.dart new file mode 100644 index 0000000..346e516 --- /dev/null +++ b/test/src/realtime_subscription_test.dart @@ -0,0 +1,21 @@ +import 'package:mockito/mockito.dart'; +import 'package:appwrite/src/realtime_message.dart'; +import 'package:appwrite/src/realtime_subscription.dart'; +import 'package:flutter_test/flutter_test.dart'; + +class MockStream extends Mock implements Stream {} + + + +void main() { + group('RealtimeSubscription', () { + final mockStream = MockStream(); + final mockCloseFunction = () async {}; + final subscription = RealtimeSubscription(stream: mockStream, close: mockCloseFunction); + + test('should have the correct stream and close function', () { + expect(subscription.stream, equals(mockStream)); + expect(subscription.close, equals(mockCloseFunction)); + }); + }); +} diff --git a/test/src/response_test.dart b/test/src/response_test.dart new file mode 100644 index 0000000..33af028 --- /dev/null +++ b/test/src/response_test.dart @@ -0,0 +1,18 @@ +import 'package:appwrite/src/response.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('toString()', () { + test('with a string', () { + final response = Response(data: 'string'); + + expect(response.toString(), 'string'); + }); + + test('with a map', () { + final response = Response(data: {'x': 1}); + + expect(response.toString(), '{"x":1}'); + }); + }); +} \ No newline at end of file diff --git a/test/src/upload_progress_test.dart b/test/src/upload_progress_test.dart new file mode 100644 index 0000000..d21607e --- /dev/null +++ b/test/src/upload_progress_test.dart @@ -0,0 +1,90 @@ +import 'dart:convert'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:appwrite/src/upload_progress.dart'; + +void main() { + group('UploadProgress', () { + final id = '12345'; + final progress = 0.75; + final sizeUploaded = 1024; + final chunksTotal = 10; + final chunksUploaded = 5; + final progressMap = { + "\$id": id, + "progress": progress, + "sizeUploaded": sizeUploaded, + "chunksTotal": chunksTotal, + "chunksUploaded": chunksUploaded + }; + final uploadProgress = UploadProgress( + $id: id, + progress: progress, + sizeUploaded: sizeUploaded, + chunksTotal: chunksTotal, + chunksUploaded: chunksUploaded, + ); + + test('fromMap should create an instance from a map', () { + final result = UploadProgress.fromMap(progressMap); + + expect(result.$id, equals(id)); + expect(result.progress, equals(progress)); + expect(result.sizeUploaded, equals(sizeUploaded)); + expect(result.chunksTotal, equals(chunksTotal)); + expect(result.chunksUploaded, equals(chunksUploaded)); + }); + + test('toMap should return a map representation of the progress', () { + final result = uploadProgress.toMap(); + + expect(result, equals(progressMap)); + }); + + test('toJson and fromJson should convert to/from JSON', () { + final jsonString = uploadProgress.toJson(); + + final result = UploadProgress.fromJson(jsonString); + + expect(result.$id, equals(id)); + expect(result.progress, equals(progress)); + expect(result.sizeUploaded, equals(sizeUploaded)); + expect(result.chunksTotal, equals(chunksTotal)); + expect(result.chunksUploaded, equals(chunksUploaded)); + }); + + test('toString should return a string representation of the progress', () { + final expectedString = + 'UploadProgress(\$id: $id, progress: $progress, sizeUploaded: $sizeUploaded, chunksTotal: $chunksTotal, chunksUploaded: $chunksUploaded)'; + final resultString = uploadProgress.toString(); + + expect(resultString, equals(expectedString)); + }); + + test('equality operator should compare two instances', () { + final uploadProgress2 = UploadProgress( + $id: id, + progress: progress, + sizeUploaded: sizeUploaded, + chunksTotal: chunksTotal, + chunksUploaded: chunksUploaded, + ); + + expect(uploadProgress == uploadProgress2, isTrue); + }); + + test('hashCode should return a unique hash value', () { + final hashCode1 = uploadProgress.hashCode; + + final uploadProgress2 = UploadProgress( + $id: id, + progress: progress, + sizeUploaded: sizeUploaded, + chunksTotal: chunksTotal, + chunksUploaded: chunksUploaded, + ); + final hashCode2 = uploadProgress2.hashCode; + + expect(hashCode1, equals(hashCode2)); + }); + }); +} From 87b9b566905296930452a3dd60b82b31304ebfae Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 21 Jun 2023 09:34:40 +0000 Subject: [PATCH 2/2] fix comments --- lib/query.dart | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/lib/query.dart b/lib/query.dart index 31a44c2..7376388 100644 --- a/lib/query.dart +++ b/lib/query.dart @@ -21,40 +21,22 @@ class Query { _addQuery(attribute, 'notEqual', value); /// Filter resources where [attribute] is less than [value]. - /// - /// [value] can be a single value or a list. If a list is used - /// the query will return resources where [attribute] is equal - /// to any of the values in the list. static String lessThan(String attribute, dynamic value) => _addQuery(attribute, 'lessThan', value); /// Filter resources where [attribute] is less than or equal to [value]. - /// - /// [value] can be a single value or a list. If a list is used - /// the query will return resources where [attribute] is equal - /// to any of the values in the list. static String lessThanEqual(String attribute, dynamic value) => _addQuery(attribute, 'lessThanEqual', value); /// Filter resources where [attribute] is greater than [value]. - /// - /// [value] can be a single value or a list. If a list is used - /// the query will return resources where [attribute] is equal - /// to any of the values in the list. static String greaterThan(String attribute, dynamic value) => _addQuery(attribute, 'greaterThan', value); /// Filter resources where [attribute] is greater than or equal to [value]. - /// - /// [value] can be a single value or a list. If a list is used - /// the query will return resources where [attribute] is equal - /// to any of the values in the list. static String greaterThanEqual(String attribute, dynamic value) => _addQuery(attribute, 'greaterThanEqual', value); /// Filter resources where by searching [attribute] for [value]. - /// - /// A fulltext index on [attribute] is required for this query to work. static String search(String attribute, String value) => _addQuery(attribute, 'search', value);