diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..eebc892f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,16 @@ +name: Analyze and test + +on: pull_request + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install Flutter + uses: subosito/flutter-action@v2 + with: + channel: stable + - run: flutter pub get + - run: flutter analyze --no-fatal-infos --no-fatal-warnings + - run: flutter test \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a291e24..9794709e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,26 @@ # Change Log +## 18.0.0 + +* Support for Appwrite 1.8 +* Added TablesDB service +* Added new query types: + * `notContains` + * `notSearch` + * `notBetween` + * `notStartsWith` + * `notEndsWith` + * `createdBefore` + * `createdAfter` + * `updatedBefore` + * `updatedAfter` +* Deprecated `updateMagicURLSession` +* Deprecated `updatePhoneSession` +* Deprecated Databases service +> The TablesDB service is the new recommended way to work with databases. +> Existing databases/collections/attributes/documents can be managed using the TablesDB service. +> Existing Databases service will continue to work, but new features may only be added to the TablesDB service. + ## 17.1.0 * Add `incrementDocumentAttribute` and `decrementDocumentAttribute` support to `Databases` service diff --git a/README.md b/README.md index 236b5191..22703b2d 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,12 @@ [![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.7.x-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.8.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) -**This SDK is compatible with Appwrite server version 1.7.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-flutter/releases).** +**This SDK is compatible with Appwrite server version 1.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-flutter/releases).** Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Flutter SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) @@ -21,7 +21,7 @@ Add this to your package's `pubspec.yaml` file: ```yml dependencies: - appwrite: ^17.1.0 + appwrite: ^18.0.0 ``` You can install packages from the command line: @@ -50,7 +50,7 @@ In order to capture the Appwrite OAuth callback url, the following activity need .... .... - + @@ -76,8 +76,8 @@ The Appwrite SDK uses ASWebAuthenticationSession on iOS 12+ and SFAuthentication ### Linux For **Linux** add your app name and package name, Your package name is generally the **name** in your pubspec.yaml file. If you cannot find the correct package name, run the application in linux, and make any request with proper exception handling, you should get the application ID needed to add in the received error message. -### Mac OS -For **Mac OS** add your app name and Bundle ID, You can find your Bundle Identifier in the General tab for your app's primary target in Xcode. +### macOS +For **macOS** add your app name and Bundle ID, You can find your Bundle Identifier in the General tab for your app's primary target in Xcode. The Appwrite SDK uses ASWebAuthenticationSession on macOS 10.15+ to allow OAuth authentication. You have to change your macOS Deployment Target in Xcode to be macOS >= 10.15 to be able to build your app for macOS. @@ -121,77 +121,53 @@ For **Windows** add your app name and package name, Your package n ### Init your SDK -

Initialize your SDK with your Appwrite server API endpoint and project ID, which can be found in your project settings page. +

Initialize your SDK with your project ID, which can be found in your project settings page. ```dart -import 'package:appwrite/appwrite.dart'; - -void main() { - Client client = Client(); - - client - .setEndpoint('https://localhost/v1') // Your Appwrite Endpoint - .setProject('5e8cf4f46b5e8') // Your project ID - .setSelfSigned() // Use only on dev mode with a self-signed SSL cert - ; -} +Client client = Client().setProject(''); ``` -Before starting to send any API calls to your new Appwrite instance, make sure your Android or iOS emulators has network access to the Appwrite server hostname or IP address. - -When trying to connect to Appwrite from an emulator or a mobile device, localhost is the hostname for the device or emulator and not your local Appwrite instance. You should replace localhost with your private IP as the Appwrite endpoint's hostname. You can also use a service like [ngrok](https://ngrok.com/) to proxy the Appwrite API. +> If using a self-hosted instance, you will also need to set your Appwrite endpoint using the `setEndpoint` method. Before starting to send any API calls to your new Appwrite instance, make sure your Android or iOS emulators has network access to the Appwrite server hostname or IP address. +> When trying to connect to a local Appwrite instance from an emulator or a mobile device, localhost is the hostname for the device or emulator and not your machine. You should replace localhost with your machine's private IP as the Appwrite endpoint's hostname (e.g. 192.168.1.100). You can also use a service like [ngrok](https://ngrok.com/) to proxy the Appwrite API. ### Make Your First Request

Once your SDK object is set, access any of the Appwrite services and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the [API References](https://appwrite.io/docs) section. ```dart -// Register User Account account = Account(client); -final user = await account - .create( - userId: ID.unique(), email: "email@example.com", password: "password", name: "Walter O'Brien" - ); + +User user = await account.create( + userId: ID.unique(), + email: 'email@example.com', + password: 'password', + name: 'Walter O'Brien', +); ``` ### Full Example ```dart -import 'package:appwrite/appwrite.dart'; - -void main() { - Client client = Client(); - +Client client = Client().setProject('>'); - client - .setEndpoint('https://localhost/v1') // Your Appwrite Endpoint - .setProject('5e8cf4f46b5e8') // Your project ID - .setSelfSigned() // Use only on dev mode with a self-signed SSL cert - ; - - - // Register User - Account account = Account(client); +Account account = Account(client); - final user = await account - .create( - userId: ID.unique(), email: "email@example.com", password: "password", name: "Walter O'Brien" - ); -} +User user = await account.create( + userId: ID.unique(), + email: 'email@example.com', + password: 'password', + name: 'Walter O'Brien' +); ``` ### Error Handling The Appwrite Flutter SDK raises `AppwriteException` object with `message`, `type`, `code` and `response` properties. You can handle any errors by catching `AppwriteException` and present the `message` to the user or handle it yourself based on the provided error information. Below is an example. ```dart -Account account = Account(client); - try { - final user = await account.create(userId: ID.unique(), email: "email@example.com", password: "password", name: "Walter O'Brien"); - print(user.toMap()); + User user = await account.create(...); } on AppwriteException catch(e) { - //show message to user or do other operation based on error as required - print(e.message); + // Handle the exception } ``` diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 00000000..a3be6b82 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1 @@ +include: package:flutter_lints/flutter.yaml \ No newline at end of file diff --git a/docs/examples/account/create-j-w-t.md b/docs/examples/account/create-jwt.md similarity index 100% rename from docs/examples/account/create-j-w-t.md rename to docs/examples/account/create-jwt.md diff --git a/docs/examples/account/create-magic-u-r-l-token.md b/docs/examples/account/create-magic-url-token.md similarity index 100% rename from docs/examples/account/create-magic-u-r-l-token.md rename to docs/examples/account/create-magic-url-token.md diff --git a/docs/examples/account/create-mfa-authenticator.md b/docs/examples/account/create-mfa-authenticator.md index ca661496..b9d7e967 100644 --- a/docs/examples/account/create-mfa-authenticator.md +++ b/docs/examples/account/create-mfa-authenticator.md @@ -6,6 +6,6 @@ Client client = Client() Account account = Account(client); -MfaType result = await account.createMfaAuthenticator( +MfaType result = await account.createMFAAuthenticator( type: AuthenticatorType.totp, ); diff --git a/docs/examples/account/create-mfa-challenge.md b/docs/examples/account/create-mfa-challenge.md index 6815e5c5..09ce17b2 100644 --- a/docs/examples/account/create-mfa-challenge.md +++ b/docs/examples/account/create-mfa-challenge.md @@ -6,6 +6,6 @@ Client client = Client() Account account = Account(client); -MfaChallenge result = await account.createMfaChallenge( +MfaChallenge result = await account.createMFAChallenge( factor: AuthenticationFactor.email, ); diff --git a/docs/examples/account/create-mfa-recovery-codes.md b/docs/examples/account/create-mfa-recovery-codes.md index 274dc598..9b69ad1b 100644 --- a/docs/examples/account/create-mfa-recovery-codes.md +++ b/docs/examples/account/create-mfa-recovery-codes.md @@ -6,4 +6,4 @@ Client client = Client() Account account = Account(client); -MfaRecoveryCodes result = await account.createMfaRecoveryCodes(); +MfaRecoveryCodes result = await account.createMFARecoveryCodes(); diff --git a/docs/examples/account/create-o-auth2session.md b/docs/examples/account/create-o-auth-2-session.md similarity index 100% rename from docs/examples/account/create-o-auth2session.md rename to docs/examples/account/create-o-auth-2-session.md diff --git a/docs/examples/account/create-o-auth2token.md b/docs/examples/account/create-o-auth-2-token.md similarity index 100% rename from docs/examples/account/create-o-auth2token.md rename to docs/examples/account/create-o-auth-2-token.md diff --git a/docs/examples/account/delete-mfa-authenticator.md b/docs/examples/account/delete-mfa-authenticator.md index bf4b0c50..b938ca68 100644 --- a/docs/examples/account/delete-mfa-authenticator.md +++ b/docs/examples/account/delete-mfa-authenticator.md @@ -6,6 +6,6 @@ Client client = Client() Account account = Account(client); -await account.deleteMfaAuthenticator( +await account.deleteMFAAuthenticator( type: AuthenticatorType.totp, ); diff --git a/docs/examples/account/get-mfa-recovery-codes.md b/docs/examples/account/get-mfa-recovery-codes.md index f9d50131..09bff7ff 100644 --- a/docs/examples/account/get-mfa-recovery-codes.md +++ b/docs/examples/account/get-mfa-recovery-codes.md @@ -6,4 +6,4 @@ Client client = Client() Account account = Account(client); -MfaRecoveryCodes result = await account.getMfaRecoveryCodes(); +MfaRecoveryCodes result = await account.getMFARecoveryCodes(); diff --git a/docs/examples/account/list-mfa-factors.md b/docs/examples/account/list-mfa-factors.md index 9f945400..5e87cbaa 100644 --- a/docs/examples/account/list-mfa-factors.md +++ b/docs/examples/account/list-mfa-factors.md @@ -6,4 +6,4 @@ Client client = Client() Account account = Account(client); -MfaFactors result = await account.listMfaFactors(); +MfaFactors result = await account.listMFAFactors(); diff --git a/docs/examples/account/update-magic-u-r-l-session.md b/docs/examples/account/update-magic-url-session.md similarity index 100% rename from docs/examples/account/update-magic-u-r-l-session.md rename to docs/examples/account/update-magic-url-session.md diff --git a/docs/examples/account/update-mfa-authenticator.md b/docs/examples/account/update-mfa-authenticator.md index 7f026578..96bdcc1b 100644 --- a/docs/examples/account/update-mfa-authenticator.md +++ b/docs/examples/account/update-mfa-authenticator.md @@ -6,7 +6,7 @@ Client client = Client() Account account = Account(client); -User result = await account.updateMfaAuthenticator( +User result = await account.updateMFAAuthenticator( type: AuthenticatorType.totp, otp: '', ); diff --git a/docs/examples/account/update-mfa-challenge.md b/docs/examples/account/update-mfa-challenge.md index a938f0af..b917e411 100644 --- a/docs/examples/account/update-mfa-challenge.md +++ b/docs/examples/account/update-mfa-challenge.md @@ -6,7 +6,7 @@ Client client = Client() Account account = Account(client); -Session result = await account.updateMfaChallenge( +Session result = await account.updateMFAChallenge( challengeId: '', otp: '', ); diff --git a/docs/examples/account/update-mfa-recovery-codes.md b/docs/examples/account/update-mfa-recovery-codes.md index 37334ef6..377149bf 100644 --- a/docs/examples/account/update-mfa-recovery-codes.md +++ b/docs/examples/account/update-mfa-recovery-codes.md @@ -6,4 +6,4 @@ Client client = Client() Account account = Account(client); -MfaRecoveryCodes result = await account.updateMfaRecoveryCodes(); +MfaRecoveryCodes result = await account.updateMFARecoveryCodes(); diff --git a/docs/examples/account/update-m-f-a.md b/docs/examples/account/update-mfa.md similarity index 100% rename from docs/examples/account/update-m-f-a.md rename to docs/examples/account/update-mfa.md diff --git a/docs/examples/avatars/get-q-r.md b/docs/examples/avatars/get-qr.md similarity index 100% rename from docs/examples/avatars/get-q-r.md rename to docs/examples/avatars/get-qr.md diff --git a/docs/examples/functions/create-execution.md b/docs/examples/functions/create-execution.md index d2a3d9e0..bbd7cd37 100644 --- a/docs/examples/functions/create-execution.md +++ b/docs/examples/functions/create-execution.md @@ -13,5 +13,5 @@ Execution result = await functions.createExecution( path: '', // optional method: ExecutionMethod.gET, // optional headers: {}, // optional - scheduledAt: '', // optional + scheduledAt: '', // optional ); diff --git a/docs/examples/locale/list-countries-e-u.md b/docs/examples/locale/list-countries-eu.md similarity index 100% rename from docs/examples/locale/list-countries-e-u.md rename to docs/examples/locale/list-countries-eu.md diff --git a/docs/examples/tablesdb/create-row.md b/docs/examples/tablesdb/create-row.md new file mode 100644 index 00000000..f546133b --- /dev/null +++ b/docs/examples/tablesdb/create-row.md @@ -0,0 +1,15 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +TablesDB tablesDB = TablesDB(client); + +Row result = await tablesDB.createRow( + databaseId: '', + tableId: '', + rowId: '', + data: {}, + permissions: ["read("any")"], // optional +); diff --git a/docs/examples/tablesdb/decrement-row-column.md b/docs/examples/tablesdb/decrement-row-column.md new file mode 100644 index 00000000..4f3b4bdb --- /dev/null +++ b/docs/examples/tablesdb/decrement-row-column.md @@ -0,0 +1,16 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +TablesDB tablesDB = TablesDB(client); + +Row result = await tablesDB.decrementRowColumn( + databaseId: '', + tableId: '', + rowId: '', + column: '', + value: 0, // optional + min: 0, // optional +); diff --git a/docs/examples/tablesdb/delete-row.md b/docs/examples/tablesdb/delete-row.md new file mode 100644 index 00000000..cc902fa1 --- /dev/null +++ b/docs/examples/tablesdb/delete-row.md @@ -0,0 +1,13 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +TablesDB tablesDB = TablesDB(client); + +await tablesDB.deleteRow( + databaseId: '', + tableId: '', + rowId: '', +); diff --git a/docs/examples/tablesdb/get-row.md b/docs/examples/tablesdb/get-row.md new file mode 100644 index 00000000..29e6eaab --- /dev/null +++ b/docs/examples/tablesdb/get-row.md @@ -0,0 +1,14 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +TablesDB tablesDB = TablesDB(client); + +Row result = await tablesDB.getRow( + databaseId: '', + tableId: '', + rowId: '', + queries: [], // optional +); diff --git a/docs/examples/tablesdb/increment-row-column.md b/docs/examples/tablesdb/increment-row-column.md new file mode 100644 index 00000000..e05dc767 --- /dev/null +++ b/docs/examples/tablesdb/increment-row-column.md @@ -0,0 +1,16 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +TablesDB tablesDB = TablesDB(client); + +Row result = await tablesDB.incrementRowColumn( + databaseId: '', + tableId: '', + rowId: '', + column: '', + value: 0, // optional + max: 0, // optional +); diff --git a/docs/examples/tablesdb/list-rows.md b/docs/examples/tablesdb/list-rows.md new file mode 100644 index 00000000..7763e2ae --- /dev/null +++ b/docs/examples/tablesdb/list-rows.md @@ -0,0 +1,13 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +TablesDB tablesDB = TablesDB(client); + +RowList result = await tablesDB.listRows( + databaseId: '', + tableId: '', + queries: [], // optional +); diff --git a/docs/examples/tablesdb/update-row.md b/docs/examples/tablesdb/update-row.md new file mode 100644 index 00000000..c2cc84d7 --- /dev/null +++ b/docs/examples/tablesdb/update-row.md @@ -0,0 +1,15 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +TablesDB tablesDB = TablesDB(client); + +Row result = await tablesDB.updateRow( + databaseId: '', + tableId: '', + rowId: '', + data: {}, // optional + permissions: ["read("any")"], // optional +); diff --git a/docs/examples/tablesdb/upsert-row.md b/docs/examples/tablesdb/upsert-row.md new file mode 100644 index 00000000..6a958a18 --- /dev/null +++ b/docs/examples/tablesdb/upsert-row.md @@ -0,0 +1,15 @@ +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +TablesDB tablesDB = TablesDB(client); + +Row result = await tablesDB.upsertRow( + databaseId: '', + tableId: '', + rowId: '', + data: {}, // optional + permissions: ["read("any")"], // optional +); diff --git a/lib/appwrite.dart b/lib/appwrite.dart index d1d56109..62e9c5a8 100644 --- a/lib/appwrite.dart +++ b/lib/appwrite.dart @@ -1,6 +1,6 @@ /// Appwrite Flutter SDK /// -/// This SDK is compatible with Appwrite server version 1.7.x. +/// This SDK is compatible with Appwrite server version 1.8.x. /// For older versions, please check /// [previous releases](https://github.com/appwrite/sdk-for-flutter/releases). library appwrite; @@ -38,4 +38,5 @@ part 'services/graphql.dart'; part 'services/locale.dart'; part 'services/messaging.dart'; part 'services/storage.dart'; +part 'services/tables_db.dart'; part 'services/teams.dart'; diff --git a/lib/models.dart b/lib/models.dart index a6de0d82..d4fae416 100644 --- a/lib/models.dart +++ b/lib/models.dart @@ -2,6 +2,7 @@ library appwrite.models; part 'src/models/model.dart'; +part 'src/models/row_list.dart'; part 'src/models/document_list.dart'; part 'src/models/session_list.dart'; part 'src/models/identity_list.dart'; @@ -16,6 +17,7 @@ part 'src/models/language_list.dart'; part 'src/models/currency_list.dart'; part 'src/models/phone_list.dart'; part 'src/models/locale_code_list.dart'; +part 'src/models/row.dart'; part 'src/models/document.dart'; part 'src/models/log.dart'; part 'src/models/user.dart'; diff --git a/lib/query.dart b/lib/query.dart index 7d7d06fd..bfdd664c 100644 --- a/lib/query.dart +++ b/lib/query.dart @@ -82,6 +82,43 @@ class Query { static String contains(String attribute, dynamic value) => Query._('contains', attribute, value).toString(); + /// Filter resources where [attribute] does not contain [value] + /// [value] can be a single value or a list. + static String notContains(String attribute, dynamic value) => + Query._('notContains', attribute, value).toString(); + + /// Filter resources by searching [attribute] for [value] (inverse of search). + static String notSearch(String attribute, String value) => + Query._('notSearch', attribute, value).toString(); + + /// Filter resources where [attribute] is not between [start] and [end] (exclusive). + static String notBetween(String attribute, dynamic start, dynamic end) => + Query._('notBetween', attribute, [start, end]).toString(); + + /// Filter resources where [attribute] does not start with [value]. + static String notStartsWith(String attribute, String value) => + Query._('notStartsWith', attribute, value).toString(); + + /// Filter resources where [attribute] does not end with [value]. + static String notEndsWith(String attribute, String value) => + Query._('notEndsWith', attribute, value).toString(); + + /// Filter resources where document was created before [value]. + static String createdBefore(String value) => + Query._('createdBefore', null, value).toString(); + + /// Filter resources where document was created after [value]. + static String createdAfter(String value) => + Query._('createdAfter', null, value).toString(); + + /// Filter resources where document was updated before [value]. + static String updatedBefore(String value) => + Query._('updatedBefore', null, value).toString(); + + /// Filter resources where document was updated after [value]. + static String updatedAfter(String value) => + Query._('updatedAfter', null, value).toString(); + static String or(List queries) => Query._( 'or', null, diff --git a/lib/services/account.dart b/lib/services/account.dart index 262be7a3..2ecd6811 100644 --- a/lib/services/account.dart +++ b/lib/services/account.dart @@ -190,6 +190,9 @@ class Account extends Service { /// authenticator using the [verify /// authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) /// method. + @Deprecated( + 'This API has been deprecated since 1.8.0. Please use `Account.createMFAAuthenticator` instead.', + ) Future createMfaAuthenticator({ required enums.AuthenticatorType type, }) async { @@ -212,9 +215,38 @@ class Account extends Service { return models.MfaType.fromMap(res.data); } + /// Add an authenticator app to be used as an MFA factor. Verify the + /// authenticator using the [verify + /// authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) + /// method. + Future createMFAAuthenticator({ + required enums.AuthenticatorType type, + }) async { + final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll( + '{type}', + type.value, + ); + + final Map apiParams = {}; + + final Map apiHeaders = {'content-type': 'application/json'}; + + final res = await client.call( + HttpMethod.post, + path: apiPath, + params: apiParams, + headers: apiHeaders, + ); + + return models.MfaType.fromMap(res.data); + } + /// Verify an authenticator app after adding it using the [add /// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) /// method. + @Deprecated( + 'This API has been deprecated since 1.8.0. Please use `Account.updateMFAAuthenticator` instead.', + ) Future updateMfaAuthenticator({ required enums.AuthenticatorType type, required String otp, @@ -238,7 +270,36 @@ class Account extends Service { return models.User.fromMap(res.data); } + /// Verify an authenticator app after adding it using the [add + /// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) + /// method. + Future updateMFAAuthenticator({ + required enums.AuthenticatorType type, + required String otp, + }) async { + final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll( + '{type}', + type.value, + ); + + final Map apiParams = {'otp': otp}; + + final Map apiHeaders = {'content-type': 'application/json'}; + + final res = await client.call( + HttpMethod.put, + path: apiPath, + params: apiParams, + headers: apiHeaders, + ); + + return models.User.fromMap(res.data); + } + /// Delete an authenticator for a user by ID. + @Deprecated( + 'This API has been deprecated since 1.8.0. Please use `Account.deleteMFAAuthenticator` instead.', + ) Future deleteMfaAuthenticator({required enums.AuthenticatorType type}) async { final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll( '{type}', @@ -259,9 +320,33 @@ class Account extends Service { return res.data; } + /// Delete an authenticator for a user by ID. + Future deleteMFAAuthenticator({required enums.AuthenticatorType type}) async { + final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll( + '{type}', + type.value, + ); + + final Map apiParams = {}; + + final Map apiHeaders = {'content-type': 'application/json'}; + + final res = await client.call( + HttpMethod.delete, + path: apiPath, + params: apiParams, + headers: apiHeaders, + ); + + return res.data; + } + /// Begin the process of MFA verification after sign-in. Finish the flow with /// [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) /// method. + @Deprecated( + 'This API has been deprecated since 1.8.0. Please use `Account.createMFAChallenge` instead.', + ) Future createMfaChallenge({ required enums.AuthenticationFactor factor, }) async { @@ -281,11 +366,36 @@ class Account extends Service { return models.MfaChallenge.fromMap(res.data); } + /// Begin the process of MFA verification after sign-in. Finish the flow with + /// [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) + /// method. + Future createMFAChallenge({ + required enums.AuthenticationFactor factor, + }) async { + const String apiPath = '/account/mfa/challenge'; + + final Map apiParams = {'factor': factor.value}; + + final Map apiHeaders = {'content-type': 'application/json'}; + + final res = await client.call( + HttpMethod.post, + path: apiPath, + params: apiParams, + headers: apiHeaders, + ); + + return models.MfaChallenge.fromMap(res.data); + } + /// Complete the MFA challenge by providing the one-time password. Finish the /// process of MFA verification by providing the one-time password. To begin /// the flow, use /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) /// method. + @Deprecated( + 'This API has been deprecated since 1.8.0. Please use `Account.updateMFAChallenge` instead.', + ) Future updateMfaChallenge({ required String challengeId, required String otp, @@ -309,7 +419,38 @@ class Account extends Service { return models.Session.fromMap(res.data); } + /// Complete the MFA challenge by providing the one-time password. Finish the + /// process of MFA verification by providing the one-time password. To begin + /// the flow, use + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method. + Future updateMFAChallenge({ + required String challengeId, + required String otp, + }) async { + const String apiPath = '/account/mfa/challenge'; + + final Map apiParams = { + 'challengeId': challengeId, + 'otp': otp, + }; + + final Map apiHeaders = {'content-type': 'application/json'}; + + final res = await client.call( + HttpMethod.put, + path: apiPath, + params: apiParams, + headers: apiHeaders, + ); + + return models.Session.fromMap(res.data); + } + /// List the factors available on the account to be used as a MFA challange. + @Deprecated( + 'This API has been deprecated since 1.8.0. Please use `Account.listMFAFactors` instead.', + ) Future listMfaFactors() async { const String apiPath = '/account/mfa/factors'; @@ -327,10 +468,31 @@ class Account extends Service { return models.MfaFactors.fromMap(res.data); } + /// List the factors available on the account to be used as a MFA challange. + Future listMFAFactors() async { + const String apiPath = '/account/mfa/factors'; + + final Map apiParams = {}; + + final Map apiHeaders = {}; + + final res = await client.call( + HttpMethod.get, + path: apiPath, + params: apiParams, + headers: apiHeaders, + ); + + return models.MfaFactors.fromMap(res.data); + } + /// Get recovery codes that can be used as backup for MFA flow. Before getting /// codes, they must be generated using /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) /// method. An OTP challenge is required to read recovery codes. + @Deprecated( + 'This API has been deprecated since 1.8.0. Please use `Account.getMFARecoveryCodes` instead.', + ) Future getMfaRecoveryCodes() async { const String apiPath = '/account/mfa/recovery-codes'; @@ -348,11 +510,35 @@ class Account extends Service { return models.MfaRecoveryCodes.fromMap(res.data); } + /// Get recovery codes that can be used as backup for MFA flow. Before getting + /// codes, they must be generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. An OTP challenge is required to read recovery codes. + Future getMFARecoveryCodes() async { + const String apiPath = '/account/mfa/recovery-codes'; + + final Map apiParams = {}; + + final Map apiHeaders = {}; + + final res = await client.call( + HttpMethod.get, + path: apiPath, + params: apiParams, + headers: apiHeaders, + ); + + return models.MfaRecoveryCodes.fromMap(res.data); + } + /// Generate recovery codes as backup for MFA flow. It's recommended to /// generate and show then immediately after user successfully adds their /// authehticator. Recovery codes can be used as a MFA verification type in /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) /// method. + @Deprecated( + 'This API has been deprecated since 1.8.0. Please use `Account.createMFARecoveryCodes` instead.', + ) Future createMfaRecoveryCodes() async { const String apiPath = '/account/mfa/recovery-codes'; @@ -370,10 +556,35 @@ class Account extends Service { return models.MfaRecoveryCodes.fromMap(res.data); } + /// Generate recovery codes as backup for MFA flow. It's recommended to + /// generate and show then immediately after user successfully adds their + /// authehticator. Recovery codes can be used as a MFA verification type in + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method. + Future createMFARecoveryCodes() async { + const String apiPath = '/account/mfa/recovery-codes'; + + final Map apiParams = {}; + + final Map apiHeaders = {'content-type': 'application/json'}; + + final res = await client.call( + HttpMethod.post, + path: apiPath, + params: apiParams, + headers: apiHeaders, + ); + + return models.MfaRecoveryCodes.fromMap(res.data); + } + /// Regenerate recovery codes that can be used as backup for MFA flow. Before /// regenerating codes, they must be first generated using /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) /// method. An OTP challenge is required to regenreate recovery codes. + @Deprecated( + 'This API has been deprecated since 1.8.0. Please use `Account.updateMFARecoveryCodes` instead.', + ) Future updateMfaRecoveryCodes() async { const String apiPath = '/account/mfa/recovery-codes'; @@ -391,6 +602,27 @@ class Account extends Service { return models.MfaRecoveryCodes.fromMap(res.data); } + /// Regenerate recovery codes that can be used as backup for MFA flow. Before + /// regenerating codes, they must be first generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. An OTP challenge is required to regenreate recovery codes. + Future updateMFARecoveryCodes() async { + const String apiPath = '/account/mfa/recovery-codes'; + + final Map apiParams = {}; + + final Map apiHeaders = {'content-type': 'application/json'}; + + final res = await client.call( + HttpMethod.patch, + path: apiPath, + params: apiParams, + headers: apiHeaders, + ); + + return models.MfaRecoveryCodes.fromMap(res.data); + } + /// Update currently logged in user account name. Future updateName({required String name}) async { const String apiPath = '/account/name'; @@ -658,6 +890,7 @@ class Account extends Service { /// Use this endpoint to create a session from token. Provide the **userId** /// and **secret** parameters from the successful response of authentication /// flows initiated by token creation. For example, magic URL and phone login. + @Deprecated('This API has been deprecated.') Future updateMagicURLSession({ required String userId, required String secret, @@ -742,6 +975,7 @@ class Account extends Service { /// Use this endpoint to create a session from token. Provide the **userId** /// and **secret** parameters from the successful response of authentication /// flows initiated by token creation. For example, magic URL and phone login. + @Deprecated('This API has been deprecated.') Future updatePhoneSession({ required String userId, required String secret, @@ -957,8 +1191,11 @@ class Account extends Service { } /// Sends the user an email with a secret key for creating a session. If the - /// provided user ID has not be registered, a new user will be created. Use the - /// returned user ID and secret and submit a request to the [POST + /// email address has never been used, a **new account is created** using the + /// provided `userId`. Otherwise, if the email address is already attached to + /// an account, the **user ID is ignored**. Then, the user will receive an + /// email with the one-time password. Use the returned user ID and secret and + /// submit a request to the [POST /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) /// endpoint to complete the login process. The secret sent to the user's email /// is valid for 15 minutes. @@ -966,6 +1203,7 @@ class Account extends Service { /// A user is limited to 10 active sessions at a time by default. [Learn more /// about session /// limits](https://appwrite.io/docs/authentication-security#limits). + /// Future createEmailToken({ required String userId, required String email, diff --git a/lib/services/databases.dart b/lib/services/databases.dart index 05532935..8e165559 100644 --- a/lib/services/databases.dart +++ b/lib/services/databases.dart @@ -8,6 +8,9 @@ class Databases extends Service { /// Get a list of all the user's documents in a given collection. You can use /// the query params to filter your results. + @Deprecated( + 'This API has been deprecated since 1.8.0. Please use `TablesDB.listRows` instead.', + ) Future listDocuments({ required String databaseId, required String collectionId, @@ -36,6 +39,9 @@ class Databases extends Service { /// collection resource using either a [server /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) /// API or directly from your database console. + @Deprecated( + 'This API has been deprecated since 1.8.0. Please use `TablesDB.createRow` instead.', + ) Future createDocument({ required String databaseId, required String collectionId, @@ -68,6 +74,9 @@ class Databases extends Service { /// Get a document by its unique ID. This endpoint response returns a JSON /// object with the document data. + @Deprecated( + 'This API has been deprecated since 1.8.0. Please use `TablesDB.getRow` instead.', + ) Future getDocument({ required String databaseId, required String collectionId, @@ -94,14 +103,13 @@ class Databases extends Service { return models.Document.fromMap(res.data); } - /// **WARNING: Experimental Feature** - This endpoint is experimental and not - /// yet officially supported. It may be subject to breaking changes or removal - /// in future versions. - /// /// Create or update a Document. Before using this route, you should create a /// new collection resource using either a [server /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) /// API or directly from your database console. + @Deprecated( + 'This API has been deprecated since 1.8.0. Please use `TablesDB.upsertRow` instead.', + ) Future upsertDocument({ required String databaseId, required String collectionId, @@ -134,6 +142,9 @@ 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. + @Deprecated( + 'This API has been deprecated since 1.8.0. Please use `TablesDB.updateRow` instead.', + ) Future updateDocument({ required String databaseId, required String collectionId, @@ -165,6 +176,9 @@ class Databases extends Service { } /// Delete a document by its unique ID. + @Deprecated( + 'This API has been deprecated since 1.8.0. Please use `TablesDB.deleteRow` instead.', + ) Future deleteDocument({ required String databaseId, required String collectionId, @@ -191,6 +205,9 @@ class Databases extends Service { } /// Decrement a specific attribute of a document by a given value. + @Deprecated( + 'This API has been deprecated since 1.8.0. Please use `TablesDB.decrementRowColumn` instead.', + ) Future decrementDocumentAttribute({ required String databaseId, required String collectionId, @@ -221,6 +238,9 @@ class Databases extends Service { } /// Increment a specific attribute of a document by a given value. + @Deprecated( + 'This API has been deprecated since 1.8.0. Please use `TablesDB.incrementRowColumn` instead.', + ) Future incrementDocumentAttribute({ required String databaseId, required String collectionId, diff --git a/lib/services/tables_db.dart b/lib/services/tables_db.dart new file mode 100644 index 00000000..2c6f1c09 --- /dev/null +++ b/lib/services/tables_db.dart @@ -0,0 +1,244 @@ +part of '../appwrite.dart'; + +class TablesDB extends Service { + /// Initializes a [TablesDB] service + TablesDB(super.client); + + /// Get a list of all the user's rows in a given table. You can use the query + /// params to filter your results. + Future listRows({ + required String databaseId, + required String tableId, + List? queries, + }) async { + final String apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{tableId}', tableId); + + final Map apiParams = {'queries': queries}; + + final Map apiHeaders = {}; + + final res = await client.call( + HttpMethod.get, + path: apiPath, + params: apiParams, + headers: apiHeaders, + ); + + return models.RowList.fromMap(res.data); + } + + /// Create a new Row. Before using this route, you should create a new table + /// resource using either a [server + /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) + /// API or directly from your database console. + Future createRow({ + required String databaseId, + required String tableId, + required String rowId, + required Map data, + List? permissions, + }) async { + final String apiPath = '/tablesdb/{databaseId}/tables/{tableId}/rows' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{tableId}', tableId); + + final Map apiParams = { + 'rowId': rowId, + 'data': data, + 'permissions': permissions, + }; + + final Map apiHeaders = {'content-type': 'application/json'}; + + final res = await client.call( + HttpMethod.post, + path: apiPath, + params: apiParams, + headers: apiHeaders, + ); + + return models.Row.fromMap(res.data); + } + + /// Get a row by its unique ID. This endpoint response returns a JSON object + /// with the row data. + Future getRow({ + required String databaseId, + required String tableId, + required String rowId, + List? queries, + }) async { + final String apiPath = + '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{tableId}', tableId) + .replaceAll('{rowId}', rowId); + + final Map apiParams = {'queries': queries}; + + final Map apiHeaders = {}; + + final res = await client.call( + HttpMethod.get, + path: apiPath, + params: apiParams, + headers: apiHeaders, + ); + + return models.Row.fromMap(res.data); + } + + /// Create or update a Row. Before using this route, you should create a new + /// table resource using either a [server + /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) + /// API or directly from your database console. + Future upsertRow({ + required String databaseId, + required String tableId, + required String rowId, + Map? data, + List? permissions, + }) async { + final String apiPath = + '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{tableId}', tableId) + .replaceAll('{rowId}', rowId); + + final Map apiParams = { + 'data': data, + 'permissions': permissions, + }; + + final Map apiHeaders = {'content-type': 'application/json'}; + + final res = await client.call( + HttpMethod.put, + path: apiPath, + params: apiParams, + headers: apiHeaders, + ); + + return models.Row.fromMap(res.data); + } + + /// Update a row by its unique ID. Using the patch method you can pass only + /// specific fields that will get updated. + Future updateRow({ + required String databaseId, + required String tableId, + required String rowId, + Map? data, + List? permissions, + }) async { + final String apiPath = + '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{tableId}', tableId) + .replaceAll('{rowId}', rowId); + + final Map apiParams = { + 'data': data, + 'permissions': permissions, + }; + + final Map apiHeaders = {'content-type': 'application/json'}; + + final res = await client.call( + HttpMethod.patch, + path: apiPath, + params: apiParams, + headers: apiHeaders, + ); + + return models.Row.fromMap(res.data); + } + + /// Delete a row by its unique ID. + Future deleteRow({ + required String databaseId, + required String tableId, + required String rowId, + }) async { + final String apiPath = + '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{tableId}', tableId) + .replaceAll('{rowId}', rowId); + + final Map apiParams = {}; + + final Map apiHeaders = {'content-type': 'application/json'}; + + final res = await client.call( + HttpMethod.delete, + path: apiPath, + params: apiParams, + headers: apiHeaders, + ); + + return res.data; + } + + /// Decrement a specific column of a row by a given value. + Future decrementRowColumn({ + required String databaseId, + required String tableId, + required String rowId, + required String column, + double? value, + double? min, + }) async { + final String apiPath = + '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}/{column}/decrement' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{tableId}', tableId) + .replaceAll('{rowId}', rowId) + .replaceAll('{column}', column); + + final Map apiParams = {'value': value, 'min': min}; + + final Map apiHeaders = {'content-type': 'application/json'}; + + final res = await client.call( + HttpMethod.patch, + path: apiPath, + params: apiParams, + headers: apiHeaders, + ); + + return models.Row.fromMap(res.data); + } + + /// Increment a specific column of a row by a given value. + Future incrementRowColumn({ + required String databaseId, + required String tableId, + required String rowId, + required String column, + double? value, + double? max, + }) async { + final String apiPath = + '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}/{column}/increment' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{tableId}', tableId) + .replaceAll('{rowId}', rowId) + .replaceAll('{column}', column); + + final Map apiParams = {'value': value, 'max': max}; + + final Map apiHeaders = {'content-type': 'application/json'}; + + final res = await client.call( + HttpMethod.patch, + path: apiPath, + params: apiParams, + headers: apiHeaders, + ); + + return models.Row.fromMap(res.data); + } +} diff --git a/lib/src/client_browser.dart b/lib/src/client_browser.dart index 0d77dc17..7b4d47a5 100644 --- a/lib/src/client_browser.dart +++ b/lib/src/client_browser.dart @@ -40,8 +40,8 @@ class ClientBrowser extends ClientBase with ClientMixin { 'x-sdk-name': 'Flutter', 'x-sdk-platform': 'client', 'x-sdk-language': 'flutter', - 'x-sdk-version': '17.1.0', - 'X-Appwrite-Response-Format': '1.7.0', + 'x-sdk-version': '18.0.0', + 'X-Appwrite-Response-Format': '1.8.0', }; config = {}; @@ -132,7 +132,7 @@ class ClientBrowser extends ClientBase with ClientMixin { } Future init() async { - final cookieFallback = web.window.localStorage['cookieFallback']; + final cookieFallback = web.window.localStorage.getItem('cookieFallback'); if (cookieFallback != null) { addHeader('x-fallback-cookies', cookieFallback); } @@ -253,7 +253,7 @@ class ClientBrowser extends ClientBase with ClientMixin { 'Appwrite is using localStorage for session management. Increase your security by adding a custom domain as your API endpoint.', ); addHeader('X-Fallback-Cookies', cookieFallback); - web.window.localStorage['cookieFallback'] = cookieFallback; + web.window.localStorage.setItem('cookieFallback', cookieFallback); } return prepareResponse(res, responseType: responseType); } catch (e) { diff --git a/lib/src/client_io.dart b/lib/src/client_io.dart index 3169c587..2ff7f93e 100644 --- a/lib/src/client_io.dart +++ b/lib/src/client_io.dart @@ -58,8 +58,8 @@ class ClientIO extends ClientBase with ClientMixin { 'x-sdk-name': 'Flutter', 'x-sdk-platform': 'client', 'x-sdk-language': 'flutter', - 'x-sdk-version': '17.1.0', - 'X-Appwrite-Response-Format': '1.7.0', + 'x-sdk-version': '18.0.0', + 'X-Appwrite-Response-Format': '1.8.0', }; config = {}; diff --git a/lib/src/enums.dart b/lib/src/enums.dart index 08fd6068..0f250ea3 100644 --- a/lib/src/enums.dart +++ b/lib/src/enums.dart @@ -16,6 +16,6 @@ enum ResponseType { /// Transform the response data to a String encoded with UTF8. plain, - /// Get original bytes, the type of response will be List + /// Get original bytes, the type of response will be `List` bytes, } diff --git a/lib/src/models/continent_list.dart b/lib/src/models/continent_list.dart index 2c605d3b..ec2c0755 100644 --- a/lib/src/models/continent_list.dart +++ b/lib/src/models/continent_list.dart @@ -2,7 +2,7 @@ part of '../../models.dart'; /// Continents List class ContinentList implements Model { - /// Total number of continents documents that matched your query. + /// Total number of continents that matched your query. final int total; /// List of continents. diff --git a/lib/src/models/country_list.dart b/lib/src/models/country_list.dart index 6ef8ec42..65e13be3 100644 --- a/lib/src/models/country_list.dart +++ b/lib/src/models/country_list.dart @@ -2,7 +2,7 @@ part of '../../models.dart'; /// Countries List class CountryList implements Model { - /// Total number of countries documents that matched your query. + /// Total number of countries that matched your query. final int total; /// List of countries. diff --git a/lib/src/models/currency_list.dart b/lib/src/models/currency_list.dart index acb515e3..7a957f1a 100644 --- a/lib/src/models/currency_list.dart +++ b/lib/src/models/currency_list.dart @@ -2,7 +2,7 @@ part of '../../models.dart'; /// Currencies List class CurrencyList implements Model { - /// Total number of currencies documents that matched your query. + /// Total number of currencies that matched your query. final int total; /// List of currencies. diff --git a/lib/src/models/document_list.dart b/lib/src/models/document_list.dart index 126ad805..4065e17b 100644 --- a/lib/src/models/document_list.dart +++ b/lib/src/models/document_list.dart @@ -2,7 +2,7 @@ part of '../../models.dart'; /// Documents List class DocumentList implements Model { - /// Total number of documents documents that matched your query. + /// Total number of documents that matched your query. final int total; /// List of documents. diff --git a/lib/src/models/execution.dart b/lib/src/models/execution.dart index 8618bcd6..8dfbeab6 100644 --- a/lib/src/models/execution.dart +++ b/lib/src/models/execution.dart @@ -8,7 +8,7 @@ class Execution implements Model { /// Execution creation date in ISO 8601 format. final String $createdAt; - /// Execution upate date in ISO 8601 format. + /// Execution update date in ISO 8601 format. final String $updatedAt; /// Execution roles. @@ -17,6 +17,9 @@ class Execution implements Model { /// Function ID. final String functionId; + /// Function's deployment ID used to create the execution. + final String deploymentId; + /// The trigger that caused the function to execute. Possible values can be: `http`, `schedule`, or `event`. final String trigger; @@ -59,6 +62,7 @@ class Execution implements Model { required this.$updatedAt, required this.$permissions, required this.functionId, + required this.deploymentId, required this.trigger, required this.status, required this.requestMethod, @@ -80,6 +84,7 @@ class Execution implements Model { $updatedAt: map['\$updatedAt'].toString(), $permissions: List.from(map['\$permissions'] ?? []), functionId: map['functionId'].toString(), + deploymentId: map['deploymentId'].toString(), trigger: map['trigger'].toString(), status: map['status'].toString(), requestMethod: map['requestMethod'].toString(), @@ -106,6 +111,7 @@ class Execution implements Model { "\$updatedAt": $updatedAt, "\$permissions": $permissions, "functionId": functionId, + "deploymentId": deploymentId, "trigger": trigger, "status": status, "requestMethod": requestMethod, diff --git a/lib/src/models/execution_list.dart b/lib/src/models/execution_list.dart index 2a2ef056..4ed73943 100644 --- a/lib/src/models/execution_list.dart +++ b/lib/src/models/execution_list.dart @@ -2,7 +2,7 @@ part of '../../models.dart'; /// Executions List class ExecutionList implements Model { - /// Total number of executions documents that matched your query. + /// Total number of executions that matched your query. final int total; /// List of executions. diff --git a/lib/src/models/file_list.dart b/lib/src/models/file_list.dart index 9f01530b..63f49abc 100644 --- a/lib/src/models/file_list.dart +++ b/lib/src/models/file_list.dart @@ -2,7 +2,7 @@ part of '../../models.dart'; /// Files List class FileList implements Model { - /// Total number of files documents that matched your query. + /// Total number of files that matched your query. final int total; /// List of files. diff --git a/lib/src/models/identity_list.dart b/lib/src/models/identity_list.dart index f38eaf66..b4c63f7d 100644 --- a/lib/src/models/identity_list.dart +++ b/lib/src/models/identity_list.dart @@ -2,7 +2,7 @@ part of '../../models.dart'; /// Identities List class IdentityList implements Model { - /// Total number of identities documents that matched your query. + /// Total number of identities that matched your query. final int total; /// List of identities. diff --git a/lib/src/models/language_list.dart b/lib/src/models/language_list.dart index 046b879e..2e65839e 100644 --- a/lib/src/models/language_list.dart +++ b/lib/src/models/language_list.dart @@ -2,7 +2,7 @@ part of '../../models.dart'; /// Languages List class LanguageList implements Model { - /// Total number of languages documents that matched your query. + /// Total number of languages that matched your query. final int total; /// List of languages. diff --git a/lib/src/models/locale_code_list.dart b/lib/src/models/locale_code_list.dart index 662fee4f..be6ddb1f 100644 --- a/lib/src/models/locale_code_list.dart +++ b/lib/src/models/locale_code_list.dart @@ -2,7 +2,7 @@ part of '../../models.dart'; /// Locale codes list class LocaleCodeList implements Model { - /// Total number of localeCodes documents that matched your query. + /// Total number of localeCodes that matched your query. final int total; /// List of localeCodes. diff --git a/lib/src/models/log_list.dart b/lib/src/models/log_list.dart index 628237fa..22273a8c 100644 --- a/lib/src/models/log_list.dart +++ b/lib/src/models/log_list.dart @@ -2,7 +2,7 @@ part of '../../models.dart'; /// Logs List class LogList implements Model { - /// Total number of logs documents that matched your query. + /// Total number of logs that matched your query. final int total; /// List of logs. diff --git a/lib/src/models/membership_list.dart b/lib/src/models/membership_list.dart index 46468a3a..a4d39dca 100644 --- a/lib/src/models/membership_list.dart +++ b/lib/src/models/membership_list.dart @@ -2,7 +2,7 @@ part of '../../models.dart'; /// Memberships List class MembershipList implements Model { - /// Total number of memberships documents that matched your query. + /// Total number of memberships that matched your query. final int total; /// List of memberships. diff --git a/lib/src/models/phone_list.dart b/lib/src/models/phone_list.dart index 18d2803d..879edbc4 100644 --- a/lib/src/models/phone_list.dart +++ b/lib/src/models/phone_list.dart @@ -2,7 +2,7 @@ part of '../../models.dart'; /// Phones List class PhoneList implements Model { - /// Total number of phones documents that matched your query. + /// Total number of phones that matched your query. final int total; /// List of phones. diff --git a/lib/src/models/row.dart b/lib/src/models/row.dart new file mode 100644 index 00000000..3700e577 --- /dev/null +++ b/lib/src/models/row.dart @@ -0,0 +1,66 @@ +part of '../../models.dart'; + +/// Row +class Row implements Model { + /// Row ID. + final String $id; + + /// Row automatically incrementing ID. + final int $sequence; + + /// Table ID. + final String $tableId; + + /// Database ID. + final String $databaseId; + + /// Row creation date in ISO 8601 format. + final String $createdAt; + + /// Row update date in ISO 8601 format. + final String $updatedAt; + + /// Row permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + final List $permissions; + + final Map data; + + Row({ + required this.$id, + required this.$sequence, + required this.$tableId, + required this.$databaseId, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.data, + }); + + factory Row.fromMap(Map map) { + return Row( + $id: map['\$id'].toString(), + $sequence: map['\$sequence'], + $tableId: map['\$tableId'].toString(), + $databaseId: map['\$databaseId'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: List.from(map['\$permissions'] ?? []), + data: map, + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$sequence": $sequence, + "\$tableId": $tableId, + "\$databaseId": $databaseId, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "data": data, + }; + } + + T convertTo(T Function(Map) fromJson) => fromJson(data); +} diff --git a/lib/src/models/row_list.dart b/lib/src/models/row_list.dart new file mode 100644 index 00000000..01f046c6 --- /dev/null +++ b/lib/src/models/row_list.dart @@ -0,0 +1,26 @@ +part of '../../models.dart'; + +/// Rows List +class RowList implements Model { + /// Total number of rows that matched your query. + final int total; + + /// List of rows. + final List rows; + + RowList({required this.total, required this.rows}); + + factory RowList.fromMap(Map map) { + return RowList( + total: map['total'], + rows: List.from(map['rows'].map((p) => Row.fromMap(p))), + ); + } + + Map toMap() { + return {"total": total, "rows": rows.map((p) => p.toMap()).toList()}; + } + + List convertTo(T Function(Map) fromJson) => + rows.map((d) => d.convertTo(fromJson)).toList(); +} diff --git a/lib/src/models/session_list.dart b/lib/src/models/session_list.dart index 479272b9..e9c478af 100644 --- a/lib/src/models/session_list.dart +++ b/lib/src/models/session_list.dart @@ -2,7 +2,7 @@ part of '../../models.dart'; /// Sessions List class SessionList implements Model { - /// Total number of sessions documents that matched your query. + /// Total number of sessions that matched your query. final int total; /// List of sessions. diff --git a/lib/src/models/team_list.dart b/lib/src/models/team_list.dart index e604f192..a3994c06 100644 --- a/lib/src/models/team_list.dart +++ b/lib/src/models/team_list.dart @@ -2,7 +2,7 @@ part of '../../models.dart'; /// Teams List class TeamList implements Model { - /// Total number of teams documents that matched your query. + /// Total number of teams that matched your query. final int total; /// List of teams. diff --git a/lib/src/realtime_browser.dart b/lib/src/realtime_browser.dart index 8e561033..aa6a3ad1 100644 --- a/lib/src/realtime_browser.dart +++ b/lib/src/realtime_browser.dart @@ -26,7 +26,7 @@ class RealtimeBrowser extends RealtimeBase with RealtimeMixin { } String? _getFallbackCookie() { - final fallbackCookie = web.window.localStorage['cookieFallback']; + final fallbackCookie = web.window.localStorage.getItem('cookieFallback'); if (fallbackCookie != null) { final cookie = Map.from(jsonDecode(fallbackCookie)); return cookie.values.first; diff --git a/lib/src/realtime_mixin.dart b/lib/src/realtime_mixin.dart index e3516ba5..fc8817c2 100644 --- a/lib/src/realtime_mixin.dart +++ b/lib/src/realtime_mixin.dart @@ -22,7 +22,6 @@ mixin RealtimeMixin { GetFallbackCookie? getFallbackCookie; int? get closeCode => _websok?.closeCode; Map _subscriptions = {}; - bool _notifyDone = true; bool _reconnect = true; int _retries = 0; StreamSubscription? _websocketSubscription; @@ -65,11 +64,9 @@ mixin RealtimeMixin { _creatingSocket = false; return; } - _notifyDone = false; await _closeConnection(); _lastUrl = uri.toString(); _websok = await getWebSocket(uri); - _notifyDone = true; } debugPrint('subscription: $_lastUrl'); _retries = 0; diff --git a/pubspec.yaml b/pubspec.yaml index 769e92d1..9b82125a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: appwrite -version: 17.1.0 +version: 18.0.0 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 @@ -19,7 +19,7 @@ dependencies: flutter: sdk: flutter cookie_jar: ^4.0.8 - device_info_plus: ^10.1.2 + device_info_plus: ^11.5.0 flutter_web_auth_2: ^4.1.0 http: '>=0.13.6 <2.0.0' package_info_plus: ^8.0.2 @@ -29,7 +29,7 @@ dependencies: dev_dependencies: path_provider_platform_interface: ^2.1.2 - flutter_lints: ^4.0.0 + flutter_lints: ^6.0.0 flutter_test: sdk: flutter mockito: ^5.4.4 diff --git a/test/query_test.dart b/test/query_test.dart index 5784cf45..915aef11 100644 --- a/test/query_test.dart +++ b/test/query_test.dart @@ -1,10 +1,12 @@ +import 'dart:convert'; + import 'package:appwrite/appwrite.dart'; import 'package:flutter_test/flutter_test.dart'; -class BasicFilterQueryTest { +class BasicFilterQueryTest { final String description; - final dynamic value; - final String expectedValues; + final T value; + final List expectedValues; BasicFilterQueryTest({ required this.description, @@ -19,7 +21,7 @@ void main() { BasicFilterQueryTest( description: 'with a string', value: 's', - expectedValues: ["s"], + expectedValues: ['s'], ), BasicFilterQueryTest( description: 'with an integer', @@ -44,14 +46,14 @@ void main() { BasicFilterQueryTest( description: 'with a list', value: ['a', 'b', 'c'], - expectedValues: ["a","b","c"], + expectedValues: ['a', 'b', 'c'], ), ]; group('equal()', () { for (var t in tests) { test(t.description, () { - final query = Query.equal('attr', t.value).toJson(); + final query = jsonDecode(Query.equal('attr', t.value)); expect(query['attribute'], 'attr'); expect(query['values'], t.expectedValues); expect(query['method'], 'equal'); @@ -61,19 +63,23 @@ void main() { group('notEqual()', () { for (var t in tests) { - test(t.description, () { - final query = Query.notEqual('attr', t.value).toJson(); - expect(query['attribute'], 'attr'); - expect(query['values'], t.expectedValues); - expect(query['method'], 'notEqual'); - }); + test( + t.description, + () { + final query = jsonDecode(Query.notEqual('attr', t.value)); + expect(query['attribute'], 'attr'); + expect(query['values'], t.expectedValues); + expect(query['method'], 'notEqual'); + }, + skip: t.value is List, + ); } }); group('lessThan()', () { for (var t in tests) { test(t.description, () { - final query = Query.lessThan('attr', t.value).toJson(); + final query = jsonDecode(Query.lessThan('attr', t.value)); expect(query['attribute'], 'attr'); expect(query['values'], t.expectedValues); expect(query['method'], 'lessThan'); @@ -84,7 +90,7 @@ void main() { group('lessThanEqual()', () { for (var t in tests) { test(t.description, () { - final query = Query.lessThanEqual('attr', t.value).toJson(); + final query = jsonDecode(Query.lessThanEqual('attr', t.value)); expect(query['attribute'], 'attr'); expect(query['values'], t.expectedValues); expect(query['method'], 'lessThanEqual'); @@ -95,7 +101,7 @@ void main() { group('greaterThan()', () { for (var t in tests) { test(t.description, () { - final query = Query.greaterThan('attr', t.value).toJson(); + final query = jsonDecode(Query.greaterThan('attr', t.value)); expect(query['attribute'], 'attr'); expect(query['values'], t.expectedValues); expect(query['method'], 'greaterThan'); @@ -106,7 +112,7 @@ void main() { group('greaterThanEqual()', () { for (var t in tests) { test(t.description, () { - final query = Query.greaterThanEqual('attr', t.value).toJson(); + final query = jsonDecode(Query.greaterThanEqual('attr', t.value)); expect(query['attribute'], 'attr'); expect(query['values'], t.expectedValues); expect(query['method'], 'greaterThanEqual'); @@ -116,21 +122,21 @@ void main() { }); test('returns search', () { - final query = Query.search('attr', 'keyword1 keyword2').toJson(); + final query = jsonDecode(Query.search('attr', 'keyword1 keyword2')); expect(query['attribute'], 'attr'); expect(query['values'], ['keyword1 keyword2']); expect(query['method'], 'search'); }); test('returns isNull', () { - final query = Query.isNull('attr').toJson(); + final query = jsonDecode(Query.isNull('attr')); expect(query['attribute'], 'attr'); expect(query['values'], null); expect(query['method'], 'isNull'); }); test('returns isNotNull', () { - final query = Query.isNotNull('attr', 'keyword1 keyword2').toJson(); + final query = jsonDecode(Query.isNotNull('attr')); expect(query['attribute'], 'attr'); expect(query['values'], null); expect(query['method'], 'isNotNull'); @@ -138,21 +144,21 @@ void main() { group('between()', () { test('with integers', () { - final query = Query.between('attr', 1, 2).toJson(); + final query = jsonDecode(Query.between('attr', 1, 2)); expect(query['attribute'], 'attr'); expect(query['values'], [1, 2]); expect(query['method'], 'between'); }); test('with doubles', () { - final query = Query.between('attr', 1.0, 2.0).toJson(); + final query = jsonDecode(Query.between('attr', 1.0, 2.0)); expect(query['attribute'], 'attr'); expect(query['values'], [1.0, 2.0]); expect(query['method'], 'between'); }); test('with strings', () { - final query = Query.between('attr', 'a', 'z').toJson(); + final query = jsonDecode(Query.between('attr', 'a', 'z')); expect(query['attribute'], 'attr'); expect(query['values'], ['a', 'z']); expect(query['method'], 'between'); @@ -160,52 +166,131 @@ void main() { }); test('returns select', () { - final query = Query.select(['attr1', 'attr2']).toJson(); + final query = jsonDecode(Query.select(['attr1', 'attr2'])); expect(query['attribute'], null); expect(query['values'], ['attr1', 'attr2']); expect(query['method'], 'select'); }); test('returns orderAsc', () { - final query = Query.orderAsc('attr').toJson(); + final query = jsonDecode(Query.orderAsc('attr')); expect(query['attribute'], 'attr'); expect(query['values'], null); expect(query['method'], 'orderAsc'); }); test('returns orderDesc', () { - final query = Query.orderDesc('attr').toJson(); + final query = jsonDecode(Query.orderDesc('attr')); expect(query['attribute'], 'attr'); expect(query['values'], null); expect(query['method'], 'orderDesc'); }); test('returns cursorBefore', () { - final query = Query.cursorBefore('custom').toJson(); + final query = jsonDecode(Query.cursorBefore('custom')); expect(query['attribute'], null); - expect(query['values'], 'custom'); + expect(query['values'], ['custom']); expect(query['method'], 'cursorBefore'); }); test('returns cursorAfter', () { - final query = Query.cursorAfter('custom').toJson(); + final query = jsonDecode(Query.cursorAfter('custom')); expect(query['attribute'], null); - expect(query['values'], 'custom'); + expect(query['values'], ['custom']); expect(query['method'], 'cursorAfter'); }); test('returns limit', () { - final query = Query.limit(1).toJson(); + final query = jsonDecode(Query.limit(1)); expect(query['attribute'], null); - expect(query['values'], 1); + expect(query['values'], [1]); expect(query['method'], 'limit'); }); test('returns offset', () { - final query = Query.offset(1).toJson(); + final query = jsonDecode(Query.offset(1)); expect(query['attribute'], null); - expect(query['values'], 1); + expect(query['values'], [1]); expect(query['method'], 'offset'); }); + + test('returns notContains', () { + final query = jsonDecode(Query.notContains('attr', 'value')); + expect(query['attribute'], 'attr'); + expect(query['values'], ['value']); + expect(query['method'], 'notContains'); + }); + + test('returns notSearch', () { + final query = jsonDecode(Query.notSearch('attr', 'keyword1 keyword2')); + expect(query['attribute'], 'attr'); + expect(query['values'], ['keyword1 keyword2']); + expect(query['method'], 'notSearch'); + }); + + group('notBetween()', () { + test('with integers', () { + final query = jsonDecode(Query.notBetween('attr', 1, 2)); + expect(query['attribute'], 'attr'); + expect(query['values'], [1, 2]); + expect(query['method'], 'notBetween'); + }); + + test('with doubles', () { + final query = jsonDecode(Query.notBetween('attr', 1.0, 2.0)); + expect(query['attribute'], 'attr'); + expect(query['values'], [1.0, 2.0]); + expect(query['method'], 'notBetween'); + }); + + test('with strings', () { + final query = jsonDecode(Query.notBetween('attr', 'a', 'z')); + expect(query['attribute'], 'attr'); + expect(query['values'], ['a', 'z']); + expect(query['method'], 'notBetween'); + }); + }); + + test('returns notStartsWith', () { + final query = jsonDecode(Query.notStartsWith('attr', 'prefix')); + expect(query['attribute'], 'attr'); + expect(query['values'], ['prefix']); + expect(query['method'], 'notStartsWith'); + }); + + test('returns notEndsWith', () { + final query = jsonDecode(Query.notEndsWith('attr', 'suffix')); + expect(query['attribute'], 'attr'); + expect(query['values'], ['suffix']); + expect(query['method'], 'notEndsWith'); + }); + + test('returns createdBefore', () { + final query = jsonDecode(Query.createdBefore('2023-01-01')); + expect(query['attribute'], null); + expect(query['values'], ['2023-01-01']); + expect(query['method'], 'createdBefore'); + }); + + test('returns createdAfter', () { + final query = jsonDecode(Query.createdAfter('2023-01-01')); + expect(query['attribute'], null); + expect(query['values'], ['2023-01-01']); + expect(query['method'], 'createdAfter'); + }); + + test('returns updatedBefore', () { + final query = jsonDecode(Query.updatedBefore('2023-01-01')); + expect(query['attribute'], null); + expect(query['values'], ['2023-01-01']); + expect(query['method'], 'updatedBefore'); + }); + + test('returns updatedAfter', () { + final query = jsonDecode(Query.updatedAfter('2023-01-01')); + expect(query['attribute'], null); + expect(query['values'], ['2023-01-01']); + expect(query['method'], 'updatedAfter'); + }); } diff --git a/test/services/account_test.dart b/test/services/account_test.dart index 045fde1f..ac86fdd1 100644 --- a/test/services/account_test.dart +++ b/test/services/account_test.dart @@ -1,6 +1,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:appwrite/models.dart' as models; +import 'package:appwrite/enums.dart' as enums; import 'package:appwrite/src/enums.dart'; import 'package:appwrite/src/response.dart'; import 'dart:typed_data'; @@ -23,7 +24,7 @@ class MockClient extends Mock implements Client { @override Future webAuth( - Uri? url, + Uri? url, { String? callbackUrlScheme, } @@ -259,7 +260,25 @@ void main() { final response = await account.createMfaAuthenticator( - type: 'totp', + type: enums.AuthenticatorType.totp, + ); + expect(response, isA()); + + }); + + test('test method createMFAAuthenticator()', () async { + final Map data = { + 'secret': '1', + 'uri': '1',}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.createMFAAuthenticator( + type: enums.AuthenticatorType.totp, ); expect(response, isA()); @@ -291,7 +310,40 @@ void main() { final response = await account.updateMfaAuthenticator( - type: 'totp', + type: enums.AuthenticatorType.totp, + otp: '', + ); + expect(response, isA()); + + }); + + test('test method updateMFAAuthenticator()', () 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, + 'labels': [], + 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', + 'email': 'john@appwrite.io', + 'phone': '+4930901820', + 'emailVerification': true, + 'phoneVerification': true, + 'mfa': true, + 'prefs': {}, + 'targets': [], + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.updateMFAAuthenticator( + type: enums.AuthenticatorType.totp, otp: '', ); expect(response, isA()); @@ -307,7 +359,20 @@ void main() { final response = await account.deleteMfaAuthenticator( - type: 'totp', + type: enums.AuthenticatorType.totp, + ); + }); + + test('test method deleteMFAAuthenticator()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.deleteMFAAuthenticator( + type: enums.AuthenticatorType.totp, ); }); @@ -325,7 +390,27 @@ void main() { final response = await account.createMfaChallenge( - factor: 'email', + factor: enums.AuthenticationFactor.email, + ); + expect(response, isA()); + + }); + + test('test method createMFAChallenge()', () async { + final Map data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'expire': '2020-10-15T06:38:00.000+00:00',}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.createMFAChallenge( + factor: enums.AuthenticationFactor.email, ); expect(response, isA()); @@ -377,6 +462,52 @@ void main() { }); + test('test method updateMFAChallenge()', () 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': '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, + 'factors': [], + 'secret': '5e5bb8c16897e', + 'mfaUpdatedAt': '2020-10-15T06:38:00.000+00:00',}; + + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.updateMFAChallenge( + challengeId: '', + otp: '', + ); + expect(response, isA()); + + }); + test('test method listMfaFactors()', () async { final Map data = { 'totp': true, @@ -396,6 +527,25 @@ void main() { }); + test('test method listMFAFactors()', () async { + final Map data = { + 'totp': true, + 'phone': true, + 'email': true, + 'recoveryCode': true,}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.listMFAFactors( + ); + expect(response, isA()); + + }); + test('test method getMfaRecoveryCodes()', () async { final Map data = { 'recoveryCodes': [],}; @@ -412,6 +562,22 @@ void main() { }); + test('test method getMFARecoveryCodes()', () async { + final Map data = { + 'recoveryCodes': [],}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.getMFARecoveryCodes( + ); + expect(response, isA()); + + }); + test('test method createMfaRecoveryCodes()', () async { final Map data = { 'recoveryCodes': [],}; @@ -428,6 +594,22 @@ void main() { }); + test('test method createMFARecoveryCodes()', () async { + final Map data = { + 'recoveryCodes': [],}; + + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.createMFARecoveryCodes( + ); + expect(response, isA()); + + }); + test('test method updateMfaRecoveryCodes()', () async { final Map data = { 'recoveryCodes': [],}; @@ -444,6 +626,22 @@ void main() { }); + test('test method updateMFARecoveryCodes()', () async { + final Map data = { + 'recoveryCodes': [],}; + + + when(client.call( + HttpMethod.patch, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await account.updateMFARecoveryCodes( + ); + expect(response, isA()); + + }); + test('test method updateName()', () async { final Map data = { '\$id': '5e5ea5c16897e', @@ -808,7 +1006,7 @@ void main() { final response = await account.createOAuth2Session( - provider: 'amazon', + provider: enums.OAuthProvider.amazon, ); }); @@ -1155,7 +1353,7 @@ void main() { final response = await account.createOAuth2Token( - provider: 'amazon', + provider: enums.OAuthProvider.amazon, ); }); diff --git a/test/services/avatars_test.dart b/test/services/avatars_test.dart index 0adcd7d0..0cd4b70d 100644 --- a/test/services/avatars_test.dart +++ b/test/services/avatars_test.dart @@ -1,6 +1,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:appwrite/models.dart' as models; +import 'package:appwrite/enums.dart' as enums; import 'package:appwrite/src/enums.dart'; import 'package:appwrite/src/response.dart'; import 'dart:typed_data'; @@ -23,7 +24,7 @@ class MockClient extends Mock implements Client { @override Future webAuth( - Uri? url, + Uri? url, { String? callbackUrlScheme, } @@ -62,7 +63,7 @@ void main() { final response = await avatars.getBrowser( - code: 'aa', + code: enums.Browser.avantBrowser, ); expect(response, isA()); @@ -76,7 +77,7 @@ void main() { final response = await avatars.getCreditCard( - code: 'amex', + code: enums.CreditCard.americanExpress, ); expect(response, isA()); @@ -104,7 +105,7 @@ void main() { final response = await avatars.getFlag( - code: 'af', + code: enums.Flag.afghanistan, ); expect(response, isA()); diff --git a/test/services/databases_test.dart b/test/services/databases_test.dart index 6e55dc29..aeceecf2 100644 --- a/test/services/databases_test.dart +++ b/test/services/databases_test.dart @@ -1,6 +1,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:appwrite/models.dart' as models; +import 'package:appwrite/enums.dart' as enums; import 'package:appwrite/src/enums.dart'; import 'package:appwrite/src/response.dart'; import 'dart:typed_data'; @@ -23,7 +24,7 @@ class MockClient extends Mock implements Client { @override Future webAuth( - Uri? url, + Uri? url, { String? callbackUrlScheme, } diff --git a/test/services/functions_test.dart b/test/services/functions_test.dart index 9f13895a..69b86785 100644 --- a/test/services/functions_test.dart +++ b/test/services/functions_test.dart @@ -1,6 +1,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:appwrite/models.dart' as models; +import 'package:appwrite/enums.dart' as enums; import 'package:appwrite/src/enums.dart'; import 'package:appwrite/src/response.dart'; import 'dart:typed_data'; @@ -23,7 +24,7 @@ class MockClient extends Mock implements Client { @override Future webAuth( - Uri? url, + Uri? url, { String? callbackUrlScheme, } @@ -79,6 +80,7 @@ void main() { '\$updatedAt': '2020-10-15T06:38:00.000+00:00', '\$permissions': [], 'functionId': '5e5ea6g16897e', + 'deploymentId': '5e5ea5c16897e', 'trigger': 'http', 'status': 'processing', 'requestMethod': 'GET', @@ -111,6 +113,7 @@ void main() { '\$updatedAt': '2020-10-15T06:38:00.000+00:00', '\$permissions': [], 'functionId': '5e5ea6g16897e', + 'deploymentId': '5e5ea5c16897e', 'trigger': 'http', 'status': 'processing', 'requestMethod': 'GET', diff --git a/test/services/graphql_test.dart b/test/services/graphql_test.dart index bb5e8eca..1c096784 100644 --- a/test/services/graphql_test.dart +++ b/test/services/graphql_test.dart @@ -1,6 +1,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:appwrite/models.dart' as models; +import 'package:appwrite/enums.dart' as enums; import 'package:appwrite/src/enums.dart'; import 'package:appwrite/src/response.dart'; import 'dart:typed_data'; @@ -23,7 +24,7 @@ class MockClient extends Mock implements Client { @override Future webAuth( - Uri? url, + Uri? url, { String? callbackUrlScheme, } diff --git a/test/services/locale_test.dart b/test/services/locale_test.dart index e1411336..ccdcb5d3 100644 --- a/test/services/locale_test.dart +++ b/test/services/locale_test.dart @@ -1,6 +1,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:appwrite/models.dart' as models; +import 'package:appwrite/enums.dart' as enums; import 'package:appwrite/src/enums.dart'; import 'package:appwrite/src/response.dart'; import 'dart:typed_data'; @@ -23,7 +24,7 @@ class MockClient extends Mock implements Client { @override Future webAuth( - Uri? url, + Uri? url, { String? callbackUrlScheme, } diff --git a/test/services/messaging_test.dart b/test/services/messaging_test.dart index ba3564ab..ddb93457 100644 --- a/test/services/messaging_test.dart +++ b/test/services/messaging_test.dart @@ -1,6 +1,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:appwrite/models.dart' as models; +import 'package:appwrite/enums.dart' as enums; import 'package:appwrite/src/enums.dart'; import 'package:appwrite/src/response.dart'; import 'dart:typed_data'; @@ -23,7 +24,7 @@ class MockClient extends Mock implements Client { @override Future webAuth( - Uri? url, + Uri? url, { String? callbackUrlScheme, } @@ -60,7 +61,16 @@ void main() { '\$createdAt': '2020-10-15T06:38:00.000+00:00', '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'targetId': '259125845563242502', - 'target': {}, + 'target': { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Apple iPhone 12', + 'userId': '259125845563242502', + 'providerType': 'email', + 'identifier': 'token', + 'expired': true, + }, 'userId': '5e5ea5c16897e', 'userName': 'Aegon Targaryen', 'topicId': '259125845563242502', diff --git a/test/services/storage_test.dart b/test/services/storage_test.dart index 0e153622..9d250109 100644 --- a/test/services/storage_test.dart +++ b/test/services/storage_test.dart @@ -1,6 +1,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:appwrite/models.dart' as models; +import 'package:appwrite/enums.dart' as enums; import 'package:appwrite/src/enums.dart'; import 'package:appwrite/src/response.dart'; import 'dart:typed_data'; @@ -23,7 +24,7 @@ class MockClient extends Mock implements Client { @override Future webAuth( - Uri? url, + Uri? url, { String? callbackUrlScheme, } diff --git a/test/services/tables_db_test.dart b/test/services/tables_db_test.dart new file mode 100644 index 00000000..9b11eb45 --- /dev/null +++ b/test/services/tables_db_test.dart @@ -0,0 +1,246 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:appwrite/models.dart' as models; +import 'package:appwrite/enums.dart' as enums; +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('TablesDB test', () { + late MockClient client; + late TablesDB tablesDB; + + setUp(() { + client = MockClient(); + tablesDB = TablesDB(client); + }); + + test('test method listRows()', () async { + final Map data = { + 'total': 5, + 'rows': [],}; + + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await tablesDB.listRows( + databaseId: '', + tableId: '', + ); + expect(response, isA()); + + }); + + test('test method createRow()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$sequence': 1, + '\$tableId': '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 tablesDB.createRow( + databaseId: '', + tableId: '', + rowId: '', + data: {}, + ); + expect(response, isA()); + + }); + + test('test method getRow()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$sequence': 1, + '\$tableId': '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 tablesDB.getRow( + databaseId: '', + tableId: '', + rowId: '', + ); + expect(response, isA()); + + }); + + test('test method upsertRow()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$sequence': 1, + '\$tableId': '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.put, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await tablesDB.upsertRow( + databaseId: '', + tableId: '', + rowId: '', + ); + expect(response, isA()); + + }); + + test('test method updateRow()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$sequence': 1, + '\$tableId': '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 tablesDB.updateRow( + databaseId: '', + tableId: '', + rowId: '', + ); + expect(response, isA()); + + }); + + test('test method deleteRow()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + + final response = await tablesDB.deleteRow( + databaseId: '', + tableId: '', + rowId: '', + ); + }); + + test('test method decrementRowColumn()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$sequence': 1, + '\$tableId': '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 tablesDB.decrementRowColumn( + databaseId: '', + tableId: '', + rowId: '', + column: '', + ); + expect(response, isA()); + + }); + + test('test method incrementRowColumn()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$sequence': 1, + '\$tableId': '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 tablesDB.incrementRowColumn( + databaseId: '', + tableId: '', + rowId: '', + column: '', + ); + expect(response, isA()); + + }); + + }); +} \ No newline at end of file diff --git a/test/services/teams_test.dart b/test/services/teams_test.dart index da943b25..c2e5ff04 100644 --- a/test/services/teams_test.dart +++ b/test/services/teams_test.dart @@ -1,6 +1,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:appwrite/models.dart' as models; +import 'package:appwrite/enums.dart' as enums; import 'package:appwrite/src/enums.dart'; import 'package:appwrite/src/response.dart'; import 'dart:typed_data'; @@ -23,7 +24,7 @@ class MockClient extends Mock implements Client { @override Future webAuth( - Uri? url, + Uri? url, { String? callbackUrlScheme, } diff --git a/test/src/cookie_manager_test.dart b/test/src/cookie_manager_test.dart index e29c284c..c6343f72 100644 --- a/test/src/cookie_manager_test.dart +++ b/test/src/cookie_manager_test.dart @@ -40,11 +40,11 @@ void main() { Cookie('name2', 'value2'), ]; cookieJar.saveFromResponse(uri, cookies); - + final request = Request('GET', uri); await cookieManager.onRequest(request); expect(request.headers, { - 'cookie': 'name=value; name2=value2' + 'cookie': 'name=value; name2=value2', }); }); }); @@ -82,11 +82,11 @@ void main() { 'body', 200, headers: { - 'set-cookie': 'name=value' + 'set-cookie': 'name=value', }, request: request, ); - + await cookieManager.onResponse(response); final cookies = await cookieJar.loadForRequest(uri); @@ -96,4 +96,4 @@ void main() { 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 index 6cd9ae0c..8c28b21d 100644 --- a/test/src/enums_test.dart +++ b/test/src/enums_test.dart @@ -4,9 +4,15 @@ 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()); - }); + 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 index 590ad289..c3de9fcb 100644 --- a/test/src/exception_test.dart +++ b/test/src/exception_test.dart @@ -8,10 +8,22 @@ void main() { expect(exception1.toString(), equals('AppwriteException')); final exception2 = AppwriteException('Some error message'); - expect(exception2.toString(), equals('AppwriteException: , Some error message (0)')); + 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)')); + 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 index ee7a82e7..3d301a85 100644 --- a/test/src/input_file_test.dart +++ b/test/src/input_file_test.dart @@ -36,7 +36,10 @@ void main() { }); test('creates InputFile from bytes', () { - final inputFile = InputFile.fromBytes(bytes: [1, 2, 3], filename: 'file.txt'); + final inputFile = InputFile.fromBytes( + bytes: [1, 2, 3], + filename: 'file.txt', + ); expect(inputFile.path, isNull); expect(inputFile.filename, 'file.txt'); diff --git a/test/src/models/algo_argon2_test.dart b/test/src/models/algo_argon2_test.dart index f82df4d3..15e85f5a 100644 --- a/test/src/models/algo_argon2_test.dart +++ b/test/src/models/algo_argon2_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('AlgoArgon2', () { - test('model', () { final model = AlgoArgon2( type: 'argon2', @@ -15,10 +14,10 @@ void main() { 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); - }); + 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 index d77bb459..87a3ca3c 100644 --- a/test/src/models/algo_bcrypt_test.dart +++ b/test/src/models/algo_bcrypt_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('AlgoBcrypt', () { - test('model', () { final model = AlgoBcrypt( type: 'bcrypt', @@ -12,7 +11,7 @@ void main() { final map = model.toMap(); final result = AlgoBcrypt.fromMap(map); - expect(result.type, 'bcrypt'); - }); + expect(result.type, 'bcrypt'); + }); }); } diff --git a/test/src/models/algo_md5_test.dart b/test/src/models/algo_md5_test.dart index b8b724ca..3b842e6c 100644 --- a/test/src/models/algo_md5_test.dart +++ b/test/src/models/algo_md5_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('AlgoMd5', () { - test('model', () { final model = AlgoMd5( type: 'md5', @@ -12,7 +11,7 @@ void main() { final map = model.toMap(); final result = AlgoMd5.fromMap(map); - expect(result.type, 'md5'); - }); + expect(result.type, 'md5'); + }); }); } diff --git a/test/src/models/algo_phpass_test.dart b/test/src/models/algo_phpass_test.dart index 65e15de0..49b1e22c 100644 --- a/test/src/models/algo_phpass_test.dart +++ b/test/src/models/algo_phpass_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('AlgoPhpass', () { - test('model', () { final model = AlgoPhpass( type: 'phpass', @@ -12,7 +11,7 @@ void main() { final map = model.toMap(); final result = AlgoPhpass.fromMap(map); - expect(result.type, 'phpass'); - }); + expect(result.type, 'phpass'); + }); }); } diff --git a/test/src/models/algo_scrypt_modified_test.dart b/test/src/models/algo_scrypt_modified_test.dart index 8e5c2741..dd7fa8c3 100644 --- a/test/src/models/algo_scrypt_modified_test.dart +++ b/test/src/models/algo_scrypt_modified_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('AlgoScryptModified', () { - test('model', () { final model = AlgoScryptModified( type: 'scryptMod', @@ -15,10 +14,10 @@ void main() { 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=='); - }); + 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 index 3e8c90b8..c7d9cdbf 100644 --- a/test/src/models/algo_scrypt_test.dart +++ b/test/src/models/algo_scrypt_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('AlgoScrypt', () { - test('model', () { final model = AlgoScrypt( type: 'scrypt', @@ -16,11 +15,11 @@ void main() { 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); - }); + 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 index 7d4a2b4c..ae58b57e 100644 --- a/test/src/models/algo_sha_test.dart +++ b/test/src/models/algo_sha_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('AlgoSha', () { - test('model', () { final model = AlgoSha( type: 'sha', @@ -12,7 +11,7 @@ void main() { final map = model.toMap(); final result = AlgoSha.fromMap(map); - expect(result.type, 'sha'); - }); + expect(result.type, 'sha'); + }); }); } diff --git a/test/src/models/continent_list_test.dart b/test/src/models/continent_list_test.dart index 0dc0597f..8de695b0 100644 --- a/test/src/models/continent_list_test.dart +++ b/test/src/models/continent_list_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('ContinentList', () { - test('model', () { final model = ContinentList( total: 5, @@ -13,8 +12,8 @@ void main() { final map = model.toMap(); final result = ContinentList.fromMap(map); - expect(result.total, 5); - expect(result.continents, []); - }); + expect(result.total, 5); + expect(result.continents, []); + }); }); } diff --git a/test/src/models/continent_test.dart b/test/src/models/continent_test.dart index 3e47afc8..d5242a4e 100644 --- a/test/src/models/continent_test.dart +++ b/test/src/models/continent_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('Continent', () { - test('model', () { final model = Continent( name: 'Europe', @@ -13,8 +12,8 @@ void main() { final map = model.toMap(); final result = Continent.fromMap(map); - expect(result.name, 'Europe'); - expect(result.code, 'EU'); - }); + 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 index f632136a..869f5db6 100644 --- a/test/src/models/country_list_test.dart +++ b/test/src/models/country_list_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('CountryList', () { - test('model', () { final model = CountryList( total: 5, @@ -13,8 +12,8 @@ void main() { final map = model.toMap(); final result = CountryList.fromMap(map); - expect(result.total, 5); - expect(result.countries, []); - }); + expect(result.total, 5); + expect(result.countries, []); + }); }); } diff --git a/test/src/models/country_test.dart b/test/src/models/country_test.dart index 9f644c06..bc66ab7b 100644 --- a/test/src/models/country_test.dart +++ b/test/src/models/country_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('Country', () { - test('model', () { final model = Country( name: 'United States', @@ -13,8 +12,8 @@ void main() { final map = model.toMap(); final result = Country.fromMap(map); - expect(result.name, 'United States'); - expect(result.code, 'US'); - }); + 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 index bfcc89ef..09da675c 100644 --- a/test/src/models/currency_list_test.dart +++ b/test/src/models/currency_list_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('CurrencyList', () { - test('model', () { final model = CurrencyList( total: 5, @@ -13,8 +12,8 @@ void main() { final map = model.toMap(); final result = CurrencyList.fromMap(map); - expect(result.total, 5); - expect(result.currencies, []); - }); + expect(result.total, 5); + expect(result.currencies, []); + }); }); } diff --git a/test/src/models/currency_test.dart b/test/src/models/currency_test.dart index 60c3ff14..29890008 100644 --- a/test/src/models/currency_test.dart +++ b/test/src/models/currency_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('Currency', () { - test('model', () { final model = Currency( symbol: '\$', @@ -18,13 +17,13 @@ void main() { 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'); - }); + 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 index 69918899..f1a5b3cc 100644 --- a/test/src/models/document_list_test.dart +++ b/test/src/models/document_list_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('DocumentList', () { - test('model', () { final model = DocumentList( total: 5, @@ -13,8 +12,8 @@ void main() { final map = model.toMap(); final result = DocumentList.fromMap(map); - expect(result.total, 5); - expect(result.documents, []); - }); + expect(result.total, 5); + expect(result.documents, []); + }); }); } diff --git a/test/src/models/document_test.dart b/test/src/models/document_test.dart index 3984287d..be617cc6 100644 --- a/test/src/models/document_test.dart +++ b/test/src/models/document_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('Document', () { - test('model', () { final model = Document( $id: '5e5ea5c16897e', @@ -19,13 +18,13 @@ void main() { final map = model.toMap(); final result = Document.fromMap(map); - expect(result.$id, '5e5ea5c16897e'); - expect(result.$sequence, 1); - 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, []); - }); + expect(result.$id, '5e5ea5c16897e'); + expect(result.$sequence, 1); + 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 index 17d304ca..fe74af58 100644 --- a/test/src/models/execution_list_test.dart +++ b/test/src/models/execution_list_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('ExecutionList', () { - test('model', () { final model = ExecutionList( total: 5, @@ -13,8 +12,8 @@ void main() { final map = model.toMap(); final result = ExecutionList.fromMap(map); - expect(result.total, 5); - expect(result.executions, []); - }); + expect(result.total, 5); + expect(result.executions, []); + }); }); } diff --git a/test/src/models/execution_test.dart b/test/src/models/execution_test.dart index 8160e51e..ed6fb8e2 100644 --- a/test/src/models/execution_test.dart +++ b/test/src/models/execution_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('Execution', () { - test('model', () { final model = Execution( $id: '5e5ea5c16897e', @@ -11,6 +10,7 @@ void main() { $updatedAt: '2020-10-15T06:38:00.000+00:00', $permissions: [], functionId: '5e5ea6g16897e', + deploymentId: '5e5ea5c16897e', trigger: 'http', status: 'processing', requestMethod: 'GET', @@ -27,22 +27,23 @@ void main() { 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.requestMethod, 'GET'); - expect(result.requestPath, '/articles?id=5'); - expect(result.requestHeaders, []); - expect(result.responseStatusCode, 200); - expect(result.responseBody, ''); - expect(result.responseHeaders, []); - expect(result.logs, ''); - expect(result.errors, ''); - expect(result.duration, 0.4); - }); + 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.deploymentId, '5e5ea5c16897e'); + expect(result.trigger, 'http'); + expect(result.status, 'processing'); + expect(result.requestMethod, 'GET'); + expect(result.requestPath, '/articles?id=5'); + expect(result.requestHeaders, []); + expect(result.responseStatusCode, 200); + expect(result.responseBody, ''); + expect(result.responseHeaders, []); + expect(result.logs, ''); + expect(result.errors, ''); + expect(result.duration, 0.4); + }); }); } diff --git a/test/src/models/file_list_test.dart b/test/src/models/file_list_test.dart index 529f5962..d8e6c95c 100644 --- a/test/src/models/file_list_test.dart +++ b/test/src/models/file_list_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('FileList', () { - test('model', () { final model = FileList( total: 5, @@ -13,8 +12,8 @@ void main() { final map = model.toMap(); final result = FileList.fromMap(map); - expect(result.total, 5); - expect(result.files, []); - }); + expect(result.total, 5); + expect(result.files, []); + }); }); } diff --git a/test/src/models/file_test.dart b/test/src/models/file_test.dart index 50b15592..08da5e9a 100644 --- a/test/src/models/file_test.dart +++ b/test/src/models/file_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('File', () { - test('model', () { final model = File( $id: '5e5ea5c16897e', @@ -22,17 +21,17 @@ void main() { 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); - }); + 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/headers_test.dart b/test/src/models/headers_test.dart index 2070462c..489891d4 100644 --- a/test/src/models/headers_test.dart +++ b/test/src/models/headers_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('Headers', () { - test('model', () { final model = Headers( name: 'Content-Type', @@ -13,8 +12,8 @@ void main() { final map = model.toMap(); final result = Headers.fromMap(map); - expect(result.name, 'Content-Type'); - expect(result.value, 'application/json'); - }); + expect(result.name, 'Content-Type'); + expect(result.value, 'application/json'); + }); }); } diff --git a/test/src/models/identity_list_test.dart b/test/src/models/identity_list_test.dart index 02486de9..65f562a7 100644 --- a/test/src/models/identity_list_test.dart +++ b/test/src/models/identity_list_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('IdentityList', () { - test('model', () { final model = IdentityList( total: 5, @@ -13,8 +12,8 @@ void main() { final map = model.toMap(); final result = IdentityList.fromMap(map); - expect(result.total, 5); - expect(result.identities, []); - }); + expect(result.total, 5); + expect(result.identities, []); + }); }); } diff --git a/test/src/models/identity_test.dart b/test/src/models/identity_test.dart index 0f92d802..708c8c60 100644 --- a/test/src/models/identity_test.dart +++ b/test/src/models/identity_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('Identity', () { - test('model', () { final model = Identity( $id: '5e5ea5c16897e', @@ -21,16 +20,16 @@ void main() { final map = model.toMap(); final result = Identity.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, '5e5bb8c16897e'); - expect(result.provider, 'email'); - expect(result.providerUid, '5e5bb8c16897e'); - expect(result.providerEmail, 'user@example.com'); - expect(result.providerAccessToken, 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3'); - expect(result.providerAccessTokenExpiry, '2020-10-15T06:38:00.000+00:00'); - expect(result.providerRefreshToken, 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3'); - }); + 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, '5e5bb8c16897e'); + expect(result.provider, 'email'); + expect(result.providerUid, '5e5bb8c16897e'); + expect(result.providerEmail, 'user@example.com'); + expect(result.providerAccessToken, 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3'); + expect(result.providerAccessTokenExpiry, '2020-10-15T06:38:00.000+00:00'); + expect(result.providerRefreshToken, 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3'); + }); }); } diff --git a/test/src/models/jwt_test.dart b/test/src/models/jwt_test.dart index 9f357e6a..e616a956 100644 --- a/test/src/models/jwt_test.dart +++ b/test/src/models/jwt_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('Jwt', () { - test('model', () { final model = Jwt( jwt: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c', @@ -12,7 +11,7 @@ void main() { final map = model.toMap(); final result = Jwt.fromMap(map); - expect(result.jwt, 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'); - }); + 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 index bff06c96..94c1e33f 100644 --- a/test/src/models/language_list_test.dart +++ b/test/src/models/language_list_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('LanguageList', () { - test('model', () { final model = LanguageList( total: 5, @@ -13,8 +12,8 @@ void main() { final map = model.toMap(); final result = LanguageList.fromMap(map); - expect(result.total, 5); - expect(result.languages, []); - }); + expect(result.total, 5); + expect(result.languages, []); + }); }); } diff --git a/test/src/models/language_test.dart b/test/src/models/language_test.dart index 0cddf22b..d4087d5e 100644 --- a/test/src/models/language_test.dart +++ b/test/src/models/language_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('Language', () { - test('model', () { final model = Language( name: 'Italian', @@ -14,9 +13,9 @@ void main() { final map = model.toMap(); final result = Language.fromMap(map); - expect(result.name, 'Italian'); - expect(result.code, 'it'); - expect(result.nativeName, 'Italiano'); - }); + expect(result.name, 'Italian'); + expect(result.code, 'it'); + expect(result.nativeName, 'Italiano'); + }); }); } diff --git a/test/src/models/locale_code_list_test.dart b/test/src/models/locale_code_list_test.dart index 85a003c0..b6de5137 100644 --- a/test/src/models/locale_code_list_test.dart +++ b/test/src/models/locale_code_list_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('LocaleCodeList', () { - test('model', () { final model = LocaleCodeList( total: 5, @@ -13,8 +12,8 @@ void main() { final map = model.toMap(); final result = LocaleCodeList.fromMap(map); - expect(result.total, 5); - expect(result.localeCodes, []); - }); + expect(result.total, 5); + expect(result.localeCodes, []); + }); }); } diff --git a/test/src/models/locale_code_test.dart b/test/src/models/locale_code_test.dart index 56828c5d..f0fcdbce 100644 --- a/test/src/models/locale_code_test.dart +++ b/test/src/models/locale_code_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('LocaleCode', () { - test('model', () { final model = LocaleCode( code: 'en-us', @@ -13,8 +12,8 @@ void main() { final map = model.toMap(); final result = LocaleCode.fromMap(map); - expect(result.code, 'en-us'); - expect(result.name, 'US'); - }); + expect(result.code, 'en-us'); + expect(result.name, 'US'); + }); }); } diff --git a/test/src/models/locale_test.dart b/test/src/models/locale_test.dart index 9a90c1c1..72102045 100644 --- a/test/src/models/locale_test.dart +++ b/test/src/models/locale_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('Locale', () { - test('model', () { final model = Locale( ip: '127.0.0.1', @@ -18,13 +17,13 @@ void main() { 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'); - }); + 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 index 82119539..84c560c8 100644 --- a/test/src/models/log_list_test.dart +++ b/test/src/models/log_list_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('LogList', () { - test('model', () { final model = LogList( total: 5, @@ -13,8 +12,8 @@ void main() { final map = model.toMap(); final result = LogList.fromMap(map); - expect(result.total, 5); - expect(result.logs, []); - }); + expect(result.total, 5); + expect(result.logs, []); + }); }); } diff --git a/test/src/models/log_test.dart b/test/src/models/log_test.dart index c82d9202..7724b875 100644 --- a/test/src/models/log_test.dart +++ b/test/src/models/log_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('Log', () { - test('model', () { final model = Log( event: 'account.sessions.create', @@ -32,27 +31,27 @@ void main() { 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'); - }); + 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 index 18eb01f8..bb1f0946 100644 --- a/test/src/models/membership_list_test.dart +++ b/test/src/models/membership_list_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('MembershipList', () { - test('model', () { final model = MembershipList( total: 5, @@ -13,8 +12,8 @@ void main() { final map = model.toMap(); final result = MembershipList.fromMap(map); - expect(result.total, 5); - expect(result.memberships, []); - }); + expect(result.total, 5); + expect(result.memberships, []); + }); }); } diff --git a/test/src/models/membership_test.dart b/test/src/models/membership_test.dart index 5e5033ec..32ba0f4e 100644 --- a/test/src/models/membership_test.dart +++ b/test/src/models/membership_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('Membership', () { - test('model', () { final model = Membership( $id: '5e5ea5c16897e', @@ -24,19 +23,19 @@ void main() { 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.mfa, true); - expect(result.roles, []); - }); + 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.mfa, true); + expect(result.roles, []); + }); }); } diff --git a/test/src/models/mfa_challenge_test.dart b/test/src/models/mfa_challenge_test.dart index 75afb97a..9410baa3 100644 --- a/test/src/models/mfa_challenge_test.dart +++ b/test/src/models/mfa_challenge_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('MfaChallenge', () { - test('model', () { final model = MfaChallenge( $id: 'bb8ea5c16897e', @@ -15,10 +14,10 @@ void main() { final map = model.toMap(); final result = MfaChallenge.fromMap(map); - expect(result.$id, 'bb8ea5c16897e'); - expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); - expect(result.userId, '5e5ea5c168bb8'); - expect(result.expire, '2020-10-15T06:38:00.000+00:00'); - }); + expect(result.$id, 'bb8ea5c16897e'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.userId, '5e5ea5c168bb8'); + expect(result.expire, '2020-10-15T06:38:00.000+00:00'); + }); }); } diff --git a/test/src/models/mfa_factors_test.dart b/test/src/models/mfa_factors_test.dart index e2bf133a..ed6467d3 100644 --- a/test/src/models/mfa_factors_test.dart +++ b/test/src/models/mfa_factors_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('MfaFactors', () { - test('model', () { final model = MfaFactors( totp: true, @@ -15,10 +14,10 @@ void main() { final map = model.toMap(); final result = MfaFactors.fromMap(map); - expect(result.totp, true); - expect(result.phone, true); - expect(result.email, true); - expect(result.recoveryCode, true); - }); + expect(result.totp, true); + expect(result.phone, true); + expect(result.email, true); + expect(result.recoveryCode, true); + }); }); } diff --git a/test/src/models/mfa_recovery_codes_test.dart b/test/src/models/mfa_recovery_codes_test.dart index 7153abb5..fa097a49 100644 --- a/test/src/models/mfa_recovery_codes_test.dart +++ b/test/src/models/mfa_recovery_codes_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('MfaRecoveryCodes', () { - test('model', () { final model = MfaRecoveryCodes( recoveryCodes: [], @@ -12,7 +11,7 @@ void main() { final map = model.toMap(); final result = MfaRecoveryCodes.fromMap(map); - expect(result.recoveryCodes, []); - }); + expect(result.recoveryCodes, []); + }); }); } diff --git a/test/src/models/mfa_type_test.dart b/test/src/models/mfa_type_test.dart index cab65e8e..dcee3fcb 100644 --- a/test/src/models/mfa_type_test.dart +++ b/test/src/models/mfa_type_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('MfaType', () { - test('model', () { final model = MfaType( secret: '1', @@ -13,8 +12,8 @@ void main() { final map = model.toMap(); final result = MfaType.fromMap(map); - expect(result.secret, '1'); - expect(result.uri, '1'); - }); + expect(result.secret, '1'); + expect(result.uri, '1'); + }); }); } diff --git a/test/src/models/phone_list_test.dart b/test/src/models/phone_list_test.dart index b8816c3f..6ca46a63 100644 --- a/test/src/models/phone_list_test.dart +++ b/test/src/models/phone_list_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('PhoneList', () { - test('model', () { final model = PhoneList( total: 5, @@ -13,8 +12,8 @@ void main() { final map = model.toMap(); final result = PhoneList.fromMap(map); - expect(result.total, 5); - expect(result.phones, []); - }); + expect(result.total, 5); + expect(result.phones, []); + }); }); } diff --git a/test/src/models/phone_test.dart b/test/src/models/phone_test.dart index 444a6f29..d0e5333b 100644 --- a/test/src/models/phone_test.dart +++ b/test/src/models/phone_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('Phone', () { - test('model', () { final model = Phone( code: '+1', @@ -14,9 +13,9 @@ void main() { final map = model.toMap(); final result = Phone.fromMap(map); - expect(result.code, '+1'); - expect(result.countryCode, 'US'); - expect(result.countryName, 'United States'); - }); + 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 index aaaec5c3..acde349c 100644 --- a/test/src/models/preferences_test.dart +++ b/test/src/models/preferences_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('Preferences', () { - test('model', () { final model = Preferences( data: {}, diff --git a/test/src/models/row_list_test.dart b/test/src/models/row_list_test.dart new file mode 100644 index 00000000..d4900dd4 --- /dev/null +++ b/test/src/models/row_list_test.dart @@ -0,0 +1,19 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('RowList', () { + test('model', () { + final model = RowList( + total: 5, + rows: [], + ); + + final map = model.toMap(); + final result = RowList.fromMap(map); + + expect(result.total, 5); + expect(result.rows, []); + }); + }); +} diff --git a/test/src/models/row_test.dart b/test/src/models/row_test.dart new file mode 100644 index 00000000..4c525e1b --- /dev/null +++ b/test/src/models/row_test.dart @@ -0,0 +1,30 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('Row', () { + test('model', () { + final model = Row( + $id: '5e5ea5c16897e', + $sequence: 1, + $tableId: '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 = Row.fromMap(map); + + expect(result.$id, '5e5ea5c16897e'); + expect(result.$sequence, 1); + expect(result.$tableId, '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/session_list_test.dart b/test/src/models/session_list_test.dart index cc718a15..eaab249e 100644 --- a/test/src/models/session_list_test.dart +++ b/test/src/models/session_list_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('SessionList', () { - test('model', () { final model = SessionList( total: 5, @@ -13,8 +12,8 @@ void main() { final map = model.toMap(); final result = SessionList.fromMap(map); - expect(result.total, 5); - expect(result.sessions, []); - }); + expect(result.total, 5); + expect(result.sessions, []); + }); }); } diff --git a/test/src/models/session_test.dart b/test/src/models/session_test.dart index a02b8196..0177e477 100644 --- a/test/src/models/session_test.dart +++ b/test/src/models/session_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('Session', () { - test('model', () { final model = Session( $id: '5e5ea5c16897e', @@ -40,35 +39,35 @@ void main() { 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.$updatedAt, '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); - expect(result.factors, []); - expect(result.secret, '5e5bb8c16897e'); - expect(result.mfaUpdatedAt, '2020-10-15T06:38:00.000+00:00'); - }); + 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, '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); + expect(result.factors, []); + expect(result.secret, '5e5bb8c16897e'); + expect(result.mfaUpdatedAt, '2020-10-15T06:38:00.000+00:00'); + }); }); } diff --git a/test/src/models/subscriber_test.dart b/test/src/models/subscriber_test.dart index 5401b863..94c6a502 100644 --- a/test/src/models/subscriber_test.dart +++ b/test/src/models/subscriber_test.dart @@ -3,14 +3,22 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('Subscriber', () { - test('model', () { final model = Subscriber( $id: '259125845563242502', $createdAt: '2020-10-15T06:38:00.000+00:00', $updatedAt: '2020-10-15T06:38:00.000+00:00', targetId: '259125845563242502', - target: {}, + target: Target( + $id: '259125845563242502', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + name: 'Apple iPhone 12', + userId: '259125845563242502', + providerType: 'email', + identifier: 'token', + expired: true, + ), userId: '5e5ea5c16897e', userName: 'Aegon Targaryen', topicId: '259125845563242502', @@ -20,15 +28,14 @@ void main() { final map = model.toMap(); final result = Subscriber.fromMap(map); - expect(result.$id, '259125845563242502'); - expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); - expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); - expect(result.targetId, '259125845563242502'); - expect(result.target, {}); - expect(result.userId, '5e5ea5c16897e'); - expect(result.userName, 'Aegon Targaryen'); - expect(result.topicId, '259125845563242502'); - expect(result.providerType, 'email'); - }); + expect(result.$id, '259125845563242502'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.targetId, '259125845563242502'); + expect(result.userId, '5e5ea5c16897e'); + expect(result.userName, 'Aegon Targaryen'); + expect(result.topicId, '259125845563242502'); + expect(result.providerType, 'email'); + }); }); } diff --git a/test/src/models/target_test.dart b/test/src/models/target_test.dart index 20b4dfeb..a49f3def 100644 --- a/test/src/models/target_test.dart +++ b/test/src/models/target_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('Target', () { - test('model', () { final model = Target( $id: '259125845563242502', @@ -19,14 +18,14 @@ void main() { final map = model.toMap(); final result = Target.fromMap(map); - expect(result.$id, '259125845563242502'); - 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, 'Apple iPhone 12'); - expect(result.userId, '259125845563242502'); - expect(result.providerType, 'email'); - expect(result.identifier, 'token'); - expect(result.expired, true); - }); + expect(result.$id, '259125845563242502'); + 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, 'Apple iPhone 12'); + expect(result.userId, '259125845563242502'); + expect(result.providerType, 'email'); + expect(result.identifier, 'token'); + expect(result.expired, true); + }); }); } diff --git a/test/src/models/team_list_test.dart b/test/src/models/team_list_test.dart index 6c71710f..a19b667d 100644 --- a/test/src/models/team_list_test.dart +++ b/test/src/models/team_list_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('TeamList', () { - test('model', () { final model = TeamList( total: 5, @@ -13,8 +12,8 @@ void main() { final map = model.toMap(); final result = TeamList.fromMap(map); - expect(result.total, 5); - expect(result.teams, []); - }); + expect(result.total, 5); + expect(result.teams, []); + }); }); } diff --git a/test/src/models/team_test.dart b/test/src/models/team_test.dart index 123b4581..43b2e45c 100644 --- a/test/src/models/team_test.dart +++ b/test/src/models/team_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('Team', () { - test('model', () { final model = Team( $id: '5e5ea5c16897e', @@ -17,12 +16,11 @@ void main() { 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": {}}); - }); + 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); + }); }); } diff --git a/test/src/models/token_test.dart b/test/src/models/token_test.dart index a2a694d9..7ee4b268 100644 --- a/test/src/models/token_test.dart +++ b/test/src/models/token_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('Token', () { - test('model', () { final model = Token( $id: 'bb8ea5c16897e', @@ -17,12 +16,12 @@ void main() { 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'); - expect(result.phrase, 'Golden Fox'); - }); + 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'); + expect(result.phrase, 'Golden Fox'); + }); }); } diff --git a/test/src/models/user_test.dart b/test/src/models/user_test.dart index 9b78a7db..c058ea26 100644 --- a/test/src/models/user_test.dart +++ b/test/src/models/user_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('User', () { - test('model', () { final model = User( $id: '5e5ea5c16897e', @@ -27,22 +26,21 @@ void main() { 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.labels, []); - 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.mfa, true); - expect(result.prefs.data, {"data": {}}); - expect(result.targets, []); - expect(result.accessedAt, '2020-10-15T06:38:00.000+00:00'); - }); + 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.labels, []); + 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.mfa, true); + expect(result.targets, []); + expect(result.accessedAt, '2020-10-15T06:38:00.000+00:00'); + }); }); } diff --git a/test/src/realtime_response_connected_test.dart b/test/src/realtime_response_connected_test.dart index 74331401..7c43878b 100644 --- a/test/src/realtime_response_connected_test.dart +++ b/test/src/realtime_response_connected_test.dart @@ -13,7 +13,10 @@ void main() { final newChannels = ['channel3', 'channel4']; final newUser = {'id': 456, 'name': 'Jane Smith'}; - final updatedResponse = response1.copyWith(channels: newChannels, user: newUser); + final updatedResponse = response1.copyWith( + channels: newChannels, + user: newUser, + ); expect(updatedResponse.channels, equals(newChannels)); expect(updatedResponse.user, equals(newUser)); @@ -47,11 +50,19 @@ void main() { test('toString should return a string representation of the response', () { final responseString = response1.toString(); - expect(responseString, equals('RealtimeResponseConnected(channels: $channels, user: $user)')); + expect( + responseString, + equals( + 'RealtimeResponseConnected(channels: $channels, user: $user)', + ), + ); }); test('equality operator should compare two instances', () { - final response2 = RealtimeResponseConnected(channels: channels, user: user); + final response2 = RealtimeResponseConnected( + channels: channels, + user: user, + ); expect(response1 == response2, isTrue); }); @@ -59,7 +70,10 @@ void main() { test('hashCode should return a unique hash value', () { final hashCode1 = response1.hashCode; - final response2 = RealtimeResponseConnected(channels: channels, user: user); + final response2 = RealtimeResponseConnected( + channels: channels, + user: user, + ); final hashCode2 = response2.hashCode; expect(hashCode1, equals(hashCode2)); diff --git a/test/src/response_test.dart b/test/src/response_test.dart index 33af0287..db9eaaac 100644 --- a/test/src/response_test.dart +++ b/test/src/response_test.dart @@ -15,4 +15,4 @@ void main() { expect(response.toString(), '{"x":1}'); }); }); -} \ No newline at end of file +}