diff --git a/CHANGELOG.md b/CHANGELOG.md index 503400a8..f4df186a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,24 @@ # Change Log -## 22.2.0 - -* Added ttl option to listDocuments for cached responses -* Added getConsolePausing health status endpoint in Health service -* Added Health.getConsolePausing overloads (object and positional) -* Added updateRelationshipAttribute for Databases to manage relationship attributes -* Added console pausing example to health docs -* Made activate optional in createDeployment object parameter +## 23.0.0 + +* [BREAKING] Changed `$sequence` type from `number` to `string` for `Row` and `Document` models +* [BREAKING] Renamed `IndexType` enum: split into `DatabasesIndexType` (with new `Spatial` value) and `TablesDBIndexType` +* [BREAKING] Replaced `specification` parameter with `buildSpecification` and `runtimeSpecification` in `Functions.create()`, `Functions.update()`, `Sites.create()`, `Sites.update()` +* Added new `Project` service with full CRUD for project-level environment variables +* Added new `Webhooks` service with full CRUD for project webhooks (including `updateSignature`) +* Added `Users.updateImpersonator()` method for enabling/disabling user impersonation +* Added impersonation support: `setImpersonateUserId()`, `setImpersonateUserEmail()`, `setImpersonateUserPhone()` on `Client` +* Added `impersonator` and `impersonatorUserId` optional fields to `User` model +* Added `deploymentRetention` parameter to Functions and Sites create/update +* Added `startCommand` parameter to Sites create/update +* Added `Webhook` and `WebhookList` models +* Added `Documentsdb`, `Vectorsdb` values to `BackupServices` and `DatabaseType` enums +* Added `WebhooksRead`, `WebhooksWrite`, `ProjectRead`, `ProjectWrite` scopes +* Added custom `toString()` on response data using `JSONbig.stringify` for BigInt support +* Removed `getQueueBillingProjectAggregation`, `getQueueBillingTeamAggregation`, `getQueuePriorityBuilds`, `getQueueRegionManager`, `getQueueThreats` from `Health` service +* Updated `Log` model field descriptions to clarify impersonation behavior +* Updated `X-Appwrite-Response-Format` header to `1.9.0` ## 22.1.2 diff --git a/README.md b/README.md index 4be156d7..08afc79c 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Appwrite Node.js SDK ![License](https://img.shields.io/github/license/appwrite/sdk-for-node.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.8.1-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.9.0-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.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-node/releases).** +**This SDK is compatible with Appwrite server version 1.9.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-node/releases).** > This is the Node.js SDK for integrating with Appwrite from your Node.js server-side code. If you're looking to integrate from the browser, you should check [appwrite/sdk-for-web](https://github.com/appwrite/sdk-for-web) diff --git a/docs/examples/databases/create-index.md b/docs/examples/databases/create-index.md index 1d0280d1..ba3bf3a6 100644 --- a/docs/examples/databases/create-index.md +++ b/docs/examples/databases/create-index.md @@ -12,7 +12,7 @@ const result = await databases.createIndex({ databaseId: '', collectionId: '', key: '', - type: sdk.IndexType.Key, + type: sdk.DatabasesIndexType.Key, attributes: [], orders: [sdk.OrderBy.Asc], // optional lengths: [] // optional diff --git a/docs/examples/functions/create.md b/docs/examples/functions/create.md index 292a0e40..b0004d85 100644 --- a/docs/examples/functions/create.md +++ b/docs/examples/functions/create.md @@ -26,6 +26,8 @@ const result = await functions.create({ providerBranch: '', // optional providerSilentMode: false, // optional providerRootDirectory: '', // optional - specification: '' // optional + buildSpecification: '', // optional + runtimeSpecification: '', // optional + deploymentRetention: 0 // optional }); ``` diff --git a/docs/examples/functions/update.md b/docs/examples/functions/update.md index 459b5f37..915037ff 100644 --- a/docs/examples/functions/update.md +++ b/docs/examples/functions/update.md @@ -26,6 +26,8 @@ const result = await functions.update({ providerBranch: '', // optional providerSilentMode: false, // optional providerRootDirectory: '', // optional - specification: '' // optional + buildSpecification: '', // optional + runtimeSpecification: '', // optional + deploymentRetention: 0 // optional }); ``` diff --git a/docs/examples/project/create-variable.md b/docs/examples/project/create-variable.md new file mode 100644 index 00000000..6333b935 --- /dev/null +++ b/docs/examples/project/create-variable.md @@ -0,0 +1,17 @@ +```javascript +const sdk = require('node-appwrite'); + +const client = new sdk.Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +const project = new sdk.Project(client); + +const result = await project.createVariable({ + variableId: '', + key: '', + value: '', + secret: false // optional +}); +``` diff --git a/docs/examples/project/delete-variable.md b/docs/examples/project/delete-variable.md new file mode 100644 index 00000000..c930811b --- /dev/null +++ b/docs/examples/project/delete-variable.md @@ -0,0 +1,14 @@ +```javascript +const sdk = require('node-appwrite'); + +const client = new sdk.Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +const project = new sdk.Project(client); + +const result = await project.deleteVariable({ + variableId: '' +}); +``` diff --git a/docs/examples/project/get-variable.md b/docs/examples/project/get-variable.md new file mode 100644 index 00000000..5232de86 --- /dev/null +++ b/docs/examples/project/get-variable.md @@ -0,0 +1,14 @@ +```javascript +const sdk = require('node-appwrite'); + +const client = new sdk.Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +const project = new sdk.Project(client); + +const result = await project.getVariable({ + variableId: '' +}); +``` diff --git a/docs/examples/project/list-variables.md b/docs/examples/project/list-variables.md new file mode 100644 index 00000000..3ffd1b95 --- /dev/null +++ b/docs/examples/project/list-variables.md @@ -0,0 +1,15 @@ +```javascript +const sdk = require('node-appwrite'); + +const client = new sdk.Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +const project = new sdk.Project(client); + +const result = await project.listVariables({ + queries: [], // optional + total: false // optional +}); +``` diff --git a/docs/examples/project/update-variable.md b/docs/examples/project/update-variable.md new file mode 100644 index 00000000..58e738ed --- /dev/null +++ b/docs/examples/project/update-variable.md @@ -0,0 +1,17 @@ +```javascript +const sdk = require('node-appwrite'); + +const client = new sdk.Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +const project = new sdk.Project(client); + +const result = await project.updateVariable({ + variableId: '', + key: '', // optional + value: '', // optional + secret: false // optional +}); +``` diff --git a/docs/examples/sites/create.md b/docs/examples/sites/create.md index fe5c2649..65e5c64c 100644 --- a/docs/examples/sites/create.md +++ b/docs/examples/sites/create.md @@ -18,6 +18,7 @@ const result = await sites.create({ timeout: 1, // optional installCommand: '', // optional buildCommand: '', // optional + startCommand: '', // optional outputDirectory: '', // optional adapter: sdk.Adapter.Static, // optional installationId: '', // optional @@ -26,6 +27,8 @@ const result = await sites.create({ providerBranch: '', // optional providerSilentMode: false, // optional providerRootDirectory: '', // optional - specification: '' // optional + buildSpecification: '', // optional + runtimeSpecification: '', // optional + deploymentRetention: 0 // optional }); ``` diff --git a/docs/examples/sites/update.md b/docs/examples/sites/update.md index 28f2e80f..0411752f 100644 --- a/docs/examples/sites/update.md +++ b/docs/examples/sites/update.md @@ -17,6 +17,7 @@ const result = await sites.update({ timeout: 1, // optional installCommand: '', // optional buildCommand: '', // optional + startCommand: '', // optional outputDirectory: '', // optional buildRuntime: sdk.BuildRuntime.Node145, // optional adapter: sdk.Adapter.Static, // optional @@ -26,6 +27,8 @@ const result = await sites.update({ providerBranch: '', // optional providerSilentMode: false, // optional providerRootDirectory: '', // optional - specification: '' // optional + buildSpecification: '', // optional + runtimeSpecification: '', // optional + deploymentRetention: 0 // optional }); ``` diff --git a/docs/examples/tablesdb/create-index.md b/docs/examples/tablesdb/create-index.md index 989110f2..6a7523ba 100644 --- a/docs/examples/tablesdb/create-index.md +++ b/docs/examples/tablesdb/create-index.md @@ -12,7 +12,7 @@ const result = await tablesDB.createIndex({ databaseId: '', tableId: '', key: '', - type: sdk.IndexType.Key, + type: sdk.TablesDBIndexType.Key, columns: [], orders: [sdk.OrderBy.Asc], // optional lengths: [] // optional diff --git a/docs/examples/users/update-impersonator.md b/docs/examples/users/update-impersonator.md new file mode 100644 index 00000000..a41d11dc --- /dev/null +++ b/docs/examples/users/update-impersonator.md @@ -0,0 +1,15 @@ +```javascript +const sdk = require('node-appwrite'); + +const client = new sdk.Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +const users = new sdk.Users(client); + +const result = await users.updateImpersonator({ + userId: '', + impersonator: false +}); +``` diff --git a/docs/examples/webhooks/create.md b/docs/examples/webhooks/create.md new file mode 100644 index 00000000..5641306f --- /dev/null +++ b/docs/examples/webhooks/create.md @@ -0,0 +1,21 @@ +```javascript +const sdk = require('node-appwrite'); + +const client = new sdk.Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +const webhooks = new sdk.Webhooks(client); + +const result = await webhooks.create({ + webhookId: '', + url: '', + name: '', + events: [], + enabled: false, // optional + security: false, // optional + httpUser: '', // optional + httpPass: '' // optional +}); +``` diff --git a/docs/examples/webhooks/delete.md b/docs/examples/webhooks/delete.md new file mode 100644 index 00000000..51639e22 --- /dev/null +++ b/docs/examples/webhooks/delete.md @@ -0,0 +1,14 @@ +```javascript +const sdk = require('node-appwrite'); + +const client = new sdk.Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +const webhooks = new sdk.Webhooks(client); + +const result = await webhooks.delete({ + webhookId: '' +}); +``` diff --git a/docs/examples/webhooks/get.md b/docs/examples/webhooks/get.md new file mode 100644 index 00000000..07d1ecda --- /dev/null +++ b/docs/examples/webhooks/get.md @@ -0,0 +1,14 @@ +```javascript +const sdk = require('node-appwrite'); + +const client = new sdk.Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +const webhooks = new sdk.Webhooks(client); + +const result = await webhooks.get({ + webhookId: '' +}); +``` diff --git a/docs/examples/webhooks/list.md b/docs/examples/webhooks/list.md new file mode 100644 index 00000000..f509df71 --- /dev/null +++ b/docs/examples/webhooks/list.md @@ -0,0 +1,15 @@ +```javascript +const sdk = require('node-appwrite'); + +const client = new sdk.Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +const webhooks = new sdk.Webhooks(client); + +const result = await webhooks.list({ + queries: [], // optional + total: false // optional +}); +``` diff --git a/docs/examples/webhooks/update-signature.md b/docs/examples/webhooks/update-signature.md new file mode 100644 index 00000000..6257ba58 --- /dev/null +++ b/docs/examples/webhooks/update-signature.md @@ -0,0 +1,14 @@ +```javascript +const sdk = require('node-appwrite'); + +const client = new sdk.Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +const webhooks = new sdk.Webhooks(client); + +const result = await webhooks.updateSignature({ + webhookId: '' +}); +``` diff --git a/docs/examples/webhooks/update.md b/docs/examples/webhooks/update.md new file mode 100644 index 00000000..acd6c9a3 --- /dev/null +++ b/docs/examples/webhooks/update.md @@ -0,0 +1,21 @@ +```javascript +const sdk = require('node-appwrite'); + +const client = new sdk.Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +const webhooks = new sdk.Webhooks(client); + +const result = await webhooks.update({ + webhookId: '', + name: '', + url: '', + events: [], + enabled: false, // optional + security: false, // optional + httpUser: '', // optional + httpPass: '' // optional +}); +``` diff --git a/package.json b/package.json index 940dbfd8..ba6c7eec 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,13 @@ "name": "node-appwrite", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API", - "version": "22.1.3", + "version": "23.0.0", "license": "BSD-3-Clause", "main": "dist/index.js", "type": "commonjs", "scripts": { - "build": "tsup" + "build": "tsup", + "test": "jest" }, "exports": { ".": { @@ -46,7 +47,8 @@ "tsup": "7.2.0", "esbuild-plugin-file-path-extensions": "^2.0.0", "tslib": "2.6.2", - "typescript": "5.4.2" + "typescript": "5.4.2", + "jest": "^29.7.0" }, "dependencies": { "json-bigint": "1.0.0", diff --git a/src/client.ts b/src/client.ts index 885c8f33..75a63a91 100644 --- a/src/client.ts +++ b/src/client.ts @@ -73,7 +73,7 @@ class AppwriteException extends Error { } function getUserAgent() { - let ua = 'AppwriteNodeJSSDK/22.1.3'; + let ua = 'AppwriteNodeJSSDK/23.0.0'; // `process` is a global in Node.js, but not fully available in all runtimes. const platform: string[] = []; @@ -117,14 +117,17 @@ class Client { locale: '', session: '', forwardeduseragent: '', + impersonateuserid: '', + impersonateuseremail: '', + impersonateuserphone: '', }; headers: Headers = { 'x-sdk-name': 'Node.js', 'x-sdk-platform': 'server', 'x-sdk-language': 'nodejs', - 'x-sdk-version': '22.1.3', + 'x-sdk-version': '23.0.0', 'user-agent' : getUserAgent(), - 'X-Appwrite-Response-Format': '1.8.0', + 'X-Appwrite-Response-Format': '1.9.0', }; /** @@ -263,6 +266,48 @@ class Client { this.config.forwardeduseragent = value; return this; } + /** + * Set ImpersonateUserId + * + * Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data. + * + * @param value string + * + * @return {this} + */ + setImpersonateUserId(value: string): this { + this.headers['X-Appwrite-Impersonate-User-Id'] = value; + this.config.impersonateuserid = value; + return this; + } + /** + * Set ImpersonateUserEmail + * + * Impersonate a user by email on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data. + * + * @param value string + * + * @return {this} + */ + setImpersonateUserEmail(value: string): this { + this.headers['X-Appwrite-Impersonate-User-Email'] = value; + this.config.impersonateuseremail = value; + return this; + } + /** + * Set ImpersonateUserPhone + * + * Impersonate a user by phone on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data. + * + * @param value string + * + * @return {this} + */ + setImpersonateUserPhone(value: string): this { + this.headers['X-Appwrite-Impersonate-User-Phone'] = value; + this.config.impersonateuserphone = value; + return this; + } prepareRequest(method: string, url: URL, headers: Headers = {}, params: Payload = {}): { uri: string, options: RequestInit } { method = method.toUpperCase(); @@ -408,6 +453,10 @@ class Client { throw new AppwriteException(data?.message, response.status, data?.type, responseText); } + if (data && typeof data === 'object') { + data.toString = () => JSONbig.stringify(data); + } + return data; } diff --git a/src/enums/backup-services.ts b/src/enums/backup-services.ts index f0f829ab..bd0582ce 100644 --- a/src/enums/backup-services.ts +++ b/src/enums/backup-services.ts @@ -1,5 +1,8 @@ export enum BackupServices { Databases = 'databases', + Tablesdb = 'tablesdb', + Documentsdb = 'documentsdb', + Vectorsdb = 'vectorsdb', Functions = 'functions', Storage = 'storage', } \ No newline at end of file diff --git a/src/enums/database-type.ts b/src/enums/database-type.ts index 71d1ed9d..8ccd9699 100644 --- a/src/enums/database-type.ts +++ b/src/enums/database-type.ts @@ -1,4 +1,6 @@ export enum DatabaseType { Legacy = 'legacy', Tablesdb = 'tablesdb', + Documentsdb = 'documentsdb', + Vectorsdb = 'vectorsdb', } \ No newline at end of file diff --git a/src/enums/databases-index-type.ts b/src/enums/databases-index-type.ts new file mode 100644 index 00000000..85ccf867 --- /dev/null +++ b/src/enums/databases-index-type.ts @@ -0,0 +1,6 @@ +export enum DatabasesIndexType { + Key = 'key', + Fulltext = 'fulltext', + Unique = 'unique', + Spatial = 'spatial', +} \ No newline at end of file diff --git a/src/enums/scopes.ts b/src/enums/scopes.ts index 083114b2..d85b2bb5 100644 --- a/src/enums/scopes.ts +++ b/src/enums/scopes.ts @@ -56,6 +56,10 @@ export enum Scopes { AssistantRead = 'assistant.read', TokensRead = 'tokens.read', TokensWrite = 'tokens.write', + WebhooksRead = 'webhooks.read', + WebhooksWrite = 'webhooks.write', + ProjectRead = 'project.read', + ProjectWrite = 'project.write', PoliciesWrite = 'policies.write', PoliciesRead = 'policies.read', ArchivesRead = 'archives.read', diff --git a/src/enums/index-type.ts b/src/enums/tables-db-index-type.ts similarity index 74% rename from src/enums/index-type.ts rename to src/enums/tables-db-index-type.ts index e5b5bbab..a199cd9c 100644 --- a/src/enums/index-type.ts +++ b/src/enums/tables-db-index-type.ts @@ -1,4 +1,4 @@ -export enum IndexType { +export enum TablesDBIndexType { Key = 'key', Fulltext = 'fulltext', Unique = 'unique', diff --git a/src/enums/template-reference-type.ts b/src/enums/template-reference-type.ts index c714c2c8..bd72cfb5 100644 --- a/src/enums/template-reference-type.ts +++ b/src/enums/template-reference-type.ts @@ -1,5 +1,5 @@ export enum TemplateReferenceType { - Branch = 'branch', Commit = 'commit', + Branch = 'branch', Tag = 'tag', } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 2e7ab5fc..99e694ad 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,12 +9,14 @@ export { Graphql } from './services/graphql'; export { Health } from './services/health'; export { Locale } from './services/locale'; export { Messaging } from './services/messaging'; +export { Project } from './services/project'; export { Sites } from './services/sites'; export { Storage } from './services/storage'; export { TablesDB } from './services/tables-db'; export { Teams } from './services/teams'; export { Tokens } from './services/tokens'; export { Users } from './services/users'; +export { Webhooks } from './services/webhooks'; export type { Models, Payload, UploadProgress } from './client'; export type { QueryTypes, QueryTypesList } from './query'; export { Permission } from './permission'; @@ -34,7 +36,7 @@ export { ImageFormat } from './enums/image-format'; export { BackupServices } from './enums/backup-services'; export { RelationshipType } from './enums/relationship-type'; export { RelationMutate } from './enums/relation-mutate'; -export { IndexType } from './enums/index-type'; +export { DatabasesIndexType } from './enums/databases-index-type'; export { OrderBy } from './enums/order-by'; export { Runtime } from './enums/runtime'; export { Scopes } from './enums/scopes'; @@ -50,6 +52,7 @@ export { BuildRuntime } from './enums/build-runtime'; export { Adapter } from './enums/adapter'; export { Compression } from './enums/compression'; export { ImageGravity } from './enums/image-gravity'; +export { TablesDBIndexType } from './enums/tables-db-index-type'; export { PasswordHash } from './enums/password-hash'; export { MessagingProviderType } from './enums/messaging-provider-type'; export { DatabaseType } from './enums/database-type'; diff --git a/src/models.ts b/src/models.ts index fea4da85..37c65933 100644 --- a/src/models.ts +++ b/src/models.ts @@ -324,6 +324,20 @@ export namespace Models { executions: Execution[]; } + /** + * Webhooks List + */ + export type WebhookList = { + /** + * Total number of webhooks that matched your query. + */ + total: number; + /** + * List of webhooks. + */ + webhooks: Webhook[]; + } + /** * Countries List */ @@ -2415,7 +2429,7 @@ export namespace Models { /** * Row sequence ID. */ - $sequence: number; + $sequence: string; /** * Table ID. */ @@ -2454,7 +2468,7 @@ export namespace Models { /** * Document sequence ID. */ - $sequence: number; + $sequence: string; /** * Collection ID. */ @@ -2491,15 +2505,15 @@ export namespace Models { */ event: string; /** - * User ID. + * User ID of the actor recorded for this log. During impersonation, this is the original impersonator, not the impersonated target user. */ userId: string; /** - * User Email. + * User email of the actor recorded for this log. During impersonation, this is the original impersonator. */ userEmail: string; /** - * User Name. + * User name of the actor recorded for this log. During impersonation, this is the original impersonator. */ userName: string; /** @@ -2652,6 +2666,14 @@ export namespace Models { * Most recent access date in ISO 8601 format. This attribute is only updated again after 24 hours. */ accessedAt: string; + /** + * Whether the user can impersonate other users. + */ + impersonator?: boolean; + /** + * ID of the original actor performing the impersonation. Present only when the current request is impersonating another user. Internal audit logs attribute the action to this user, while the impersonated target is recorded only in internal audit payload data. + */ + impersonatorUserId?: string; } /** @@ -3309,6 +3331,10 @@ export namespace Models { * Site framework. */ framework: string; + /** + * How many days to keep the non-active deployments before they will be automatically deleted. + */ + deploymentRetention: number; /** * Site's active deployment ID. */ @@ -3353,6 +3379,10 @@ export namespace Models { * The build command used to build the site. */ buildCommand: string; + /** + * Custom command to use when starting site runtime. + */ + startCommand: string; /** * The directory where the site build output is located. */ @@ -3378,9 +3408,13 @@ export namespace Models { */ providerSilentMode: boolean; /** - * Machine specification for builds and executions. + * Machine specification for deployment builds. */ - specification: string; + buildSpecification: string; + /** + * Machine specification for SSR executions. + */ + runtimeSpecification: string; /** * Site build runtime. */ @@ -3435,6 +3469,10 @@ export namespace Models { * Function execution and build runtime. */ runtime: string; + /** + * How many days to keep the non-active deployments before they will be automatically deleted. + */ + deploymentRetention: number; /** * Function's active deployment ID. */ @@ -3508,9 +3546,13 @@ export namespace Models { */ providerSilentMode: boolean; /** - * Machine specification for builds and executions. + * Machine specification for deployment builds. */ - specification: string; + buildSpecification: string; + /** + * Machine specification for executions. + */ + runtimeSpecification: string; } /** @@ -3795,6 +3837,64 @@ export namespace Models { scheduledAt?: string; } + /** + * Webhook + */ + export type Webhook = { + /** + * Webhook ID. + */ + $id: string; + /** + * Webhook creation date in ISO 8601 format. + */ + $createdAt: string; + /** + * Webhook update date in ISO 8601 format. + */ + $updatedAt: string; + /** + * Webhook name. + */ + name: string; + /** + * Webhook URL endpoint. + */ + url: string; + /** + * Webhook trigger events. + */ + events: string[]; + /** + * Indicated if SSL / TLS Certificate verification is enabled. + */ + security: boolean; + /** + * HTTP basic authentication username. + */ + httpUser: string; + /** + * HTTP basic authentication password. + */ + httpPass: string; + /** + * Signature key which can be used to validated incoming + */ + signatureKey: string; + /** + * Indicates if this webhook is enabled. + */ + enabled: boolean; + /** + * Webhook error logs from the most recent failure. + */ + logs: string; + /** + * Number of consecutive failed webhook attempts. + */ + attempts: number; + } + /** * Variable */ diff --git a/src/services/databases.ts b/src/services/databases.ts index b559e71e..54b2eb0f 100644 --- a/src/services/databases.ts +++ b/src/services/databases.ts @@ -3,7 +3,7 @@ import type { Models } from '../models'; import { RelationshipType } from '../enums/relationship-type'; import { RelationMutate } from '../enums/relation-mutate'; -import { IndexType } from '../enums/index-type'; +import { DatabasesIndexType } from '../enums/databases-index-type'; import { OrderBy } from '../enums/order-by'; export class Databases { @@ -5757,7 +5757,7 @@ export class Databases { * @param {string} params.databaseId - Database ID. * @param {string} params.collectionId - Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). * @param {string} params.key - Index Key. - * @param {IndexType} params.type - Index type. + * @param {DatabasesIndexType} params.type - Index type. * @param {string[]} params.attributes - Array of attributes to index. Maximum of 100 attributes are allowed, each 32 characters long. * @param {OrderBy[]} params.orders - Array of index orders. Maximum of 100 orders are allowed. * @param {number[]} params.lengths - Length of index. Maximum of 100 @@ -5765,7 +5765,7 @@ export class Databases { * @returns {Promise} * @deprecated This API has been deprecated since 1.8.0. Please use `TablesDB.createIndex` instead. */ - createIndex(params: { databaseId: string, collectionId: string, key: string, type: IndexType, attributes: string[], orders?: OrderBy[], lengths?: number[] }): Promise; + createIndex(params: { databaseId: string, collectionId: string, key: string, type: DatabasesIndexType, attributes: string[], orders?: OrderBy[], lengths?: number[] }): Promise; /** * Creates an index on the attributes listed. Your index should include all the attributes you will query in a single request. * Attributes can be `key`, `fulltext`, and `unique`. @@ -5773,7 +5773,7 @@ export class Databases { * @param {string} databaseId - Database ID. * @param {string} collectionId - Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). * @param {string} key - Index Key. - * @param {IndexType} type - Index type. + * @param {DatabasesIndexType} type - Index type. * @param {string[]} attributes - Array of attributes to index. Maximum of 100 attributes are allowed, each 32 characters long. * @param {OrderBy[]} orders - Array of index orders. Maximum of 100 orders are allowed. * @param {number[]} lengths - Length of index. Maximum of 100 @@ -5781,21 +5781,21 @@ export class Databases { * @returns {Promise} * @deprecated Use the object parameter style method for a better developer experience. */ - createIndex(databaseId: string, collectionId: string, key: string, type: IndexType, attributes: string[], orders?: OrderBy[], lengths?: number[]): Promise; + createIndex(databaseId: string, collectionId: string, key: string, type: DatabasesIndexType, attributes: string[], orders?: OrderBy[], lengths?: number[]): Promise; createIndex( - paramsOrFirst: { databaseId: string, collectionId: string, key: string, type: IndexType, attributes: string[], orders?: OrderBy[], lengths?: number[] } | string, - ...rest: [(string)?, (string)?, (IndexType)?, (string[])?, (OrderBy[])?, (number[])?] + paramsOrFirst: { databaseId: string, collectionId: string, key: string, type: DatabasesIndexType, attributes: string[], orders?: OrderBy[], lengths?: number[] } | string, + ...rest: [(string)?, (string)?, (DatabasesIndexType)?, (string[])?, (OrderBy[])?, (number[])?] ): Promise { - let params: { databaseId: string, collectionId: string, key: string, type: IndexType, attributes: string[], orders?: OrderBy[], lengths?: number[] }; + let params: { databaseId: string, collectionId: string, key: string, type: DatabasesIndexType, attributes: string[], orders?: OrderBy[], lengths?: number[] }; if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { - params = (paramsOrFirst || {}) as { databaseId: string, collectionId: string, key: string, type: IndexType, attributes: string[], orders?: OrderBy[], lengths?: number[] }; + params = (paramsOrFirst || {}) as { databaseId: string, collectionId: string, key: string, type: DatabasesIndexType, attributes: string[], orders?: OrderBy[], lengths?: number[] }; } else { params = { databaseId: paramsOrFirst as string, collectionId: rest[0] as string, key: rest[1] as string, - type: rest[2] as IndexType, + type: rest[2] as DatabasesIndexType, attributes: rest[3] as string[], orders: rest[4] as OrderBy[], lengths: rest[5] as number[] diff --git a/src/services/functions.ts b/src/services/functions.ts index 1daf8ba3..743acc04 100644 --- a/src/services/functions.ts +++ b/src/services/functions.ts @@ -101,11 +101,13 @@ export class Functions { * @param {string} params.providerBranch - Production branch for the repo linked to the function. * @param {boolean} params.providerSilentMode - Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests. * @param {string} params.providerRootDirectory - Path to function code in the linked repo. - * @param {string} params.specification - Runtime specification for the function and builds. + * @param {string} params.buildSpecification - Build specification for the function deployments. + * @param {string} params.runtimeSpecification - Runtime specification for the function executions. + * @param {number} params.deploymentRetention - Days to keep non-active deployments before deletion. Value 0 means all deployments will be kept. * @throws {AppwriteException} * @returns {Promise} */ - create(params: { functionId: string, name: string, runtime: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: Scopes[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, specification?: string }): Promise; + create(params: { functionId: string, name: string, runtime: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: Scopes[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, buildSpecification?: string, runtimeSpecification?: string, deploymentRetention?: number }): Promise; /** * Create a new function. You can pass a list of [permissions](https://appwrite.io/docs/permissions) to allow different project users or team with access to execute the function using the client API. * @@ -126,20 +128,22 @@ export class Functions { * @param {string} providerBranch - Production branch for the repo linked to the function. * @param {boolean} providerSilentMode - Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests. * @param {string} providerRootDirectory - Path to function code in the linked repo. - * @param {string} specification - Runtime specification for the function and builds. + * @param {string} buildSpecification - Build specification for the function deployments. + * @param {string} runtimeSpecification - Runtime specification for the function executions. + * @param {number} deploymentRetention - Days to keep non-active deployments before deletion. Value 0 means all deployments will be kept. * @throws {AppwriteException} * @returns {Promise} * @deprecated Use the object parameter style method for a better developer experience. */ - create(functionId: string, name: string, runtime: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: Scopes[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, specification?: string): Promise; + create(functionId: string, name: string, runtime: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: Scopes[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, buildSpecification?: string, runtimeSpecification?: string, deploymentRetention?: number): Promise; create( - paramsOrFirst: { functionId: string, name: string, runtime: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: Scopes[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, specification?: string } | string, - ...rest: [(string)?, (Runtime)?, (string[])?, (string[])?, (string)?, (number)?, (boolean)?, (boolean)?, (string)?, (string)?, (Scopes[])?, (string)?, (string)?, (string)?, (boolean)?, (string)?, (string)?] + paramsOrFirst: { functionId: string, name: string, runtime: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: Scopes[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, buildSpecification?: string, runtimeSpecification?: string, deploymentRetention?: number } | string, + ...rest: [(string)?, (Runtime)?, (string[])?, (string[])?, (string)?, (number)?, (boolean)?, (boolean)?, (string)?, (string)?, (Scopes[])?, (string)?, (string)?, (string)?, (boolean)?, (string)?, (string)?, (string)?, (number)?] ): Promise { - let params: { functionId: string, name: string, runtime: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: Scopes[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, specification?: string }; + let params: { functionId: string, name: string, runtime: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: Scopes[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, buildSpecification?: string, runtimeSpecification?: string, deploymentRetention?: number }; if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { - params = (paramsOrFirst || {}) as { functionId: string, name: string, runtime: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: Scopes[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, specification?: string }; + params = (paramsOrFirst || {}) as { functionId: string, name: string, runtime: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: Scopes[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, buildSpecification?: string, runtimeSpecification?: string, deploymentRetention?: number }; } else { params = { functionId: paramsOrFirst as string, @@ -159,7 +163,9 @@ export class Functions { providerBranch: rest[13] as string, providerSilentMode: rest[14] as boolean, providerRootDirectory: rest[15] as string, - specification: rest[16] as string + buildSpecification: rest[16] as string, + runtimeSpecification: rest[17] as string, + deploymentRetention: rest[18] as number }; } @@ -180,7 +186,9 @@ export class Functions { const providerBranch = params.providerBranch; const providerSilentMode = params.providerSilentMode; const providerRootDirectory = params.providerRootDirectory; - const specification = params.specification; + const buildSpecification = params.buildSpecification; + const runtimeSpecification = params.runtimeSpecification; + const deploymentRetention = params.deploymentRetention; if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); @@ -245,8 +253,14 @@ export class Functions { if (typeof providerRootDirectory !== 'undefined') { payload['providerRootDirectory'] = providerRootDirectory; } - if (typeof specification !== 'undefined') { - payload['specification'] = specification; + if (typeof buildSpecification !== 'undefined') { + payload['buildSpecification'] = buildSpecification; + } + if (typeof runtimeSpecification !== 'undefined') { + payload['runtimeSpecification'] = runtimeSpecification; + } + if (typeof deploymentRetention !== 'undefined') { + payload['deploymentRetention'] = deploymentRetention; } const uri = new URL(this.client.config.endpoint + apiPath); @@ -379,11 +393,13 @@ export class Functions { * @param {string} params.providerBranch - Production branch for the repo linked to the function * @param {boolean} params.providerSilentMode - Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests. * @param {string} params.providerRootDirectory - Path to function code in the linked repo. - * @param {string} params.specification - Runtime specification for the function and builds. + * @param {string} params.buildSpecification - Build specification for the function deployments. + * @param {string} params.runtimeSpecification - Runtime specification for the function executions. + * @param {number} params.deploymentRetention - Days to keep non-active deployments before deletion. Value 0 means all deployments will be kept. * @throws {AppwriteException} * @returns {Promise} */ - update(params: { functionId: string, name: string, runtime?: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: Scopes[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, specification?: string }): Promise; + update(params: { functionId: string, name: string, runtime?: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: Scopes[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, buildSpecification?: string, runtimeSpecification?: string, deploymentRetention?: number }): Promise; /** * Update function by its unique ID. * @@ -404,20 +420,22 @@ export class Functions { * @param {string} providerBranch - Production branch for the repo linked to the function * @param {boolean} providerSilentMode - Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests. * @param {string} providerRootDirectory - Path to function code in the linked repo. - * @param {string} specification - Runtime specification for the function and builds. + * @param {string} buildSpecification - Build specification for the function deployments. + * @param {string} runtimeSpecification - Runtime specification for the function executions. + * @param {number} deploymentRetention - Days to keep non-active deployments before deletion. Value 0 means all deployments will be kept. * @throws {AppwriteException} * @returns {Promise} * @deprecated Use the object parameter style method for a better developer experience. */ - update(functionId: string, name: string, runtime?: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: Scopes[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, specification?: string): Promise; + update(functionId: string, name: string, runtime?: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: Scopes[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, buildSpecification?: string, runtimeSpecification?: string, deploymentRetention?: number): Promise; update( - paramsOrFirst: { functionId: string, name: string, runtime?: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: Scopes[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, specification?: string } | string, - ...rest: [(string)?, (Runtime)?, (string[])?, (string[])?, (string)?, (number)?, (boolean)?, (boolean)?, (string)?, (string)?, (Scopes[])?, (string)?, (string)?, (string)?, (boolean)?, (string)?, (string)?] + paramsOrFirst: { functionId: string, name: string, runtime?: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: Scopes[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, buildSpecification?: string, runtimeSpecification?: string, deploymentRetention?: number } | string, + ...rest: [(string)?, (Runtime)?, (string[])?, (string[])?, (string)?, (number)?, (boolean)?, (boolean)?, (string)?, (string)?, (Scopes[])?, (string)?, (string)?, (string)?, (boolean)?, (string)?, (string)?, (string)?, (number)?] ): Promise { - let params: { functionId: string, name: string, runtime?: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: Scopes[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, specification?: string }; + let params: { functionId: string, name: string, runtime?: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: Scopes[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, buildSpecification?: string, runtimeSpecification?: string, deploymentRetention?: number }; if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { - params = (paramsOrFirst || {}) as { functionId: string, name: string, runtime?: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: Scopes[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, specification?: string }; + params = (paramsOrFirst || {}) as { functionId: string, name: string, runtime?: Runtime, execute?: string[], events?: string[], schedule?: string, timeout?: number, enabled?: boolean, logging?: boolean, entrypoint?: string, commands?: string, scopes?: Scopes[], installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, buildSpecification?: string, runtimeSpecification?: string, deploymentRetention?: number }; } else { params = { functionId: paramsOrFirst as string, @@ -437,7 +455,9 @@ export class Functions { providerBranch: rest[13] as string, providerSilentMode: rest[14] as boolean, providerRootDirectory: rest[15] as string, - specification: rest[16] as string + buildSpecification: rest[16] as string, + runtimeSpecification: rest[17] as string, + deploymentRetention: rest[18] as number }; } @@ -458,7 +478,9 @@ export class Functions { const providerBranch = params.providerBranch; const providerSilentMode = params.providerSilentMode; const providerRootDirectory = params.providerRootDirectory; - const specification = params.specification; + const buildSpecification = params.buildSpecification; + const runtimeSpecification = params.runtimeSpecification; + const deploymentRetention = params.deploymentRetention; if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); @@ -517,8 +539,14 @@ export class Functions { if (typeof providerRootDirectory !== 'undefined') { payload['providerRootDirectory'] = providerRootDirectory; } - if (typeof specification !== 'undefined') { - payload['specification'] = specification; + if (typeof buildSpecification !== 'undefined') { + payload['buildSpecification'] = buildSpecification; + } + if (typeof runtimeSpecification !== 'undefined') { + payload['runtimeSpecification'] = runtimeSpecification; + } + if (typeof deploymentRetention !== 'undefined') { + payload['deploymentRetention'] = deploymentRetention; } const uri = new URL(this.client.config.endpoint + apiPath); diff --git a/src/services/health.ts b/src/services/health.ts index e3d724c3..14111566 100644 --- a/src/services/health.ts +++ b/src/services/health.ts @@ -288,108 +288,6 @@ export class Health { ); } - /** - * Get billing project aggregation queue. - * - * @param {number} params.threshold - Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. - * @throws {AppwriteException} - * @returns {Promise} - */ - getQueueBillingProjectAggregation(params?: { threshold?: number }): Promise; - /** - * Get billing project aggregation queue. - * - * @param {number} threshold - Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. - * @throws {AppwriteException} - * @returns {Promise} - * @deprecated Use the object parameter style method for a better developer experience. - */ - getQueueBillingProjectAggregation(threshold?: number): Promise; - getQueueBillingProjectAggregation( - paramsOrFirst?: { threshold?: number } | number - ): Promise { - let params: { threshold?: number }; - - if (!paramsOrFirst || (paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { - params = (paramsOrFirst || {}) as { threshold?: number }; - } else { - params = { - threshold: paramsOrFirst as number - }; - } - - const threshold = params.threshold; - - - const apiPath = '/health/queue/billing-project-aggregation'; - const payload: Payload = {}; - if (typeof threshold !== 'undefined') { - payload['threshold'] = threshold; - } - const uri = new URL(this.client.config.endpoint + apiPath); - - const apiHeaders: { [header: string]: string } = { - } - - return this.client.call( - 'get', - uri, - apiHeaders, - payload, - ); - } - - /** - * Get billing team aggregation queue. - * - * @param {number} params.threshold - Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. - * @throws {AppwriteException} - * @returns {Promise} - */ - getQueueBillingTeamAggregation(params?: { threshold?: number }): Promise; - /** - * Get billing team aggregation queue. - * - * @param {number} threshold - Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000. - * @throws {AppwriteException} - * @returns {Promise} - * @deprecated Use the object parameter style method for a better developer experience. - */ - getQueueBillingTeamAggregation(threshold?: number): Promise; - getQueueBillingTeamAggregation( - paramsOrFirst?: { threshold?: number } | number - ): Promise { - let params: { threshold?: number }; - - if (!paramsOrFirst || (paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { - params = (paramsOrFirst || {}) as { threshold?: number }; - } else { - params = { - threshold: paramsOrFirst as number - }; - } - - const threshold = params.threshold; - - - const apiPath = '/health/queue/billing-team-aggregation'; - const payload: Payload = {}; - if (typeof threshold !== 'undefined') { - payload['threshold'] = threshold; - } - const uri = new URL(this.client.config.endpoint + apiPath); - - const apiHeaders: { [header: string]: string } = { - } - - return this.client.call( - 'get', - uri, - apiHeaders, - payload, - ); - } - /** * Get the number of builds that are waiting to be processed in the Appwrite internal queue server. * @@ -441,57 +339,6 @@ export class Health { ); } - /** - * Get the priority builds queue size. - * - * @param {number} params.threshold - Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 500. - * @throws {AppwriteException} - * @returns {Promise} - */ - getQueuePriorityBuilds(params?: { threshold?: number }): Promise; - /** - * Get the priority builds queue size. - * - * @param {number} threshold - Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 500. - * @throws {AppwriteException} - * @returns {Promise} - * @deprecated Use the object parameter style method for a better developer experience. - */ - getQueuePriorityBuilds(threshold?: number): Promise; - getQueuePriorityBuilds( - paramsOrFirst?: { threshold?: number } | number - ): Promise { - let params: { threshold?: number }; - - if (!paramsOrFirst || (paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { - params = (paramsOrFirst || {}) as { threshold?: number }; - } else { - params = { - threshold: paramsOrFirst as number - }; - } - - const threshold = params.threshold; - - - const apiPath = '/health/queue/builds-priority'; - const payload: Payload = {}; - if (typeof threshold !== 'undefined') { - payload['threshold'] = threshold; - } - const uri = new URL(this.client.config.endpoint + apiPath); - - const apiHeaders: { [header: string]: string } = { - } - - return this.client.call( - 'get', - uri, - apiHeaders, - payload, - ); - } - /** * Get the number of certificates that are waiting to be issued against [Letsencrypt](https://letsencrypt.org/) in the Appwrite internal queue server. * @@ -969,57 +816,6 @@ export class Health { ); } - /** - * Get region manager queue. - * - * @param {number} params.threshold - Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 100. - * @throws {AppwriteException} - * @returns {Promise} - */ - getQueueRegionManager(params?: { threshold?: number }): Promise; - /** - * Get region manager queue. - * - * @param {number} threshold - Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 100. - * @throws {AppwriteException} - * @returns {Promise} - * @deprecated Use the object parameter style method for a better developer experience. - */ - getQueueRegionManager(threshold?: number): Promise; - getQueueRegionManager( - paramsOrFirst?: { threshold?: number } | number - ): Promise { - let params: { threshold?: number }; - - if (!paramsOrFirst || (paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { - params = (paramsOrFirst || {}) as { threshold?: number }; - } else { - params = { - threshold: paramsOrFirst as number - }; - } - - const threshold = params.threshold; - - - const apiPath = '/health/queue/region-manager'; - const payload: Payload = {}; - if (typeof threshold !== 'undefined') { - payload['threshold'] = threshold; - } - const uri = new URL(this.client.config.endpoint + apiPath); - - const apiHeaders: { [header: string]: string } = { - } - - return this.client.call( - 'get', - uri, - apiHeaders, - payload, - ); - } - /** * Get the number of metrics that are waiting to be processed in the Appwrite stats resources queue. * @@ -1122,57 +918,6 @@ export class Health { ); } - /** - * Get threats queue. - * - * @param {number} params.threshold - Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 100. - * @throws {AppwriteException} - * @returns {Promise} - */ - getQueueThreats(params?: { threshold?: number }): Promise; - /** - * Get threats queue. - * - * @param {number} threshold - Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 100. - * @throws {AppwriteException} - * @returns {Promise} - * @deprecated Use the object parameter style method for a better developer experience. - */ - getQueueThreats(threshold?: number): Promise; - getQueueThreats( - paramsOrFirst?: { threshold?: number } | number - ): Promise { - let params: { threshold?: number }; - - if (!paramsOrFirst || (paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { - params = (paramsOrFirst || {}) as { threshold?: number }; - } else { - params = { - threshold: paramsOrFirst as number - }; - } - - const threshold = params.threshold; - - - const apiPath = '/health/queue/threats'; - const payload: Payload = {}; - if (typeof threshold !== 'undefined') { - payload['threshold'] = threshold; - } - const uri = new URL(this.client.config.endpoint + apiPath); - - const apiHeaders: { [header: string]: string } = { - } - - return this.client.call( - 'get', - uri, - apiHeaders, - payload, - ); - } - /** * Get the number of webhooks that are waiting to be processed in the Appwrite internal queue server. * diff --git a/src/services/project.ts b/src/services/project.ts new file mode 100644 index 00000000..ed6fcb19 --- /dev/null +++ b/src/services/project.ts @@ -0,0 +1,330 @@ +import { AppwriteException, Client, type Payload, UploadProgress } from '../client'; +import type { Models } from '../models'; + + +export class Project { + client: Client; + + constructor(client: Client) { + this.client = client; + } + + /** + * Get a list of all project environment variables. + * + * @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: key, resourceType, resourceId, secret + * @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated. + * @throws {AppwriteException} + * @returns {Promise} + */ + listVariables(params?: { queries?: string[], total?: boolean }): Promise; + /** + * Get a list of all project environment variables. + * + * @param {string[]} queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: key, resourceType, resourceId, secret + * @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated. + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + listVariables(queries?: string[], total?: boolean): Promise; + listVariables( + paramsOrFirst?: { queries?: string[], total?: boolean } | string[], + ...rest: [(boolean)?] + ): Promise { + let params: { queries?: string[], total?: boolean }; + + if (!paramsOrFirst || (paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { + params = (paramsOrFirst || {}) as { queries?: string[], total?: boolean }; + } else { + params = { + queries: paramsOrFirst as string[], + total: rest[0] as boolean + }; + } + + const queries = params.queries; + const total = params.total; + + + const apiPath = '/project/variables'; + const payload: Payload = {}; + if (typeof queries !== 'undefined') { + payload['queries'] = queries; + } + if (typeof total !== 'undefined') { + payload['total'] = total; + } + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + } + + return this.client.call( + 'get', + uri, + apiHeaders, + payload, + ); + } + + /** + * Create a new project environment variable. These variables can be accessed by all functions and sites in the project. + * + * @param {string} params.variableId - Variable ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. + * @param {string} params.key - Variable key. Max length: 255 chars. + * @param {string} params.value - Variable value. Max length: 8192 chars. + * @param {boolean} params.secret - Secret variables can be updated or deleted, but only projects can read them during build and runtime. + * @throws {AppwriteException} + * @returns {Promise} + */ + createVariable(params: { variableId: string, key: string, value: string, secret?: boolean }): Promise; + /** + * Create a new project environment variable. These variables can be accessed by all functions and sites in the project. + * + * @param {string} variableId - Variable ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. + * @param {string} key - Variable key. Max length: 255 chars. + * @param {string} value - Variable value. Max length: 8192 chars. + * @param {boolean} secret - Secret variables can be updated or deleted, but only projects can read them during build and runtime. + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + createVariable(variableId: string, key: string, value: string, secret?: boolean): Promise; + createVariable( + paramsOrFirst: { variableId: string, key: string, value: string, secret?: boolean } | string, + ...rest: [(string)?, (string)?, (boolean)?] + ): Promise { + let params: { variableId: string, key: string, value: string, secret?: boolean }; + + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { + params = (paramsOrFirst || {}) as { variableId: string, key: string, value: string, secret?: boolean }; + } else { + params = { + variableId: paramsOrFirst as string, + key: rest[0] as string, + value: rest[1] as string, + secret: rest[2] as boolean + }; + } + + const variableId = params.variableId; + const key = params.key; + const value = params.value; + const secret = params.secret; + + if (typeof variableId === 'undefined') { + throw new AppwriteException('Missing required parameter: "variableId"'); + } + if (typeof key === 'undefined') { + throw new AppwriteException('Missing required parameter: "key"'); + } + if (typeof value === 'undefined') { + throw new AppwriteException('Missing required parameter: "value"'); + } + + const apiPath = '/project/variables'; + const payload: Payload = {}; + if (typeof variableId !== 'undefined') { + payload['variableId'] = variableId; + } + if (typeof key !== 'undefined') { + payload['key'] = key; + } + if (typeof value !== 'undefined') { + payload['value'] = value; + } + if (typeof secret !== 'undefined') { + payload['secret'] = secret; + } + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'content-type': 'application/json', + } + + return this.client.call( + 'post', + uri, + apiHeaders, + payload, + ); + } + + /** + * Get a variable by its unique ID. + * + * @param {string} params.variableId - Variable ID. + * @throws {AppwriteException} + * @returns {Promise} + */ + getVariable(params: { variableId: string }): Promise; + /** + * Get a variable by its unique ID. + * + * @param {string} variableId - Variable ID. + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + getVariable(variableId: string): Promise; + getVariable( + paramsOrFirst: { variableId: string } | string + ): Promise { + let params: { variableId: string }; + + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { + params = (paramsOrFirst || {}) as { variableId: string }; + } else { + params = { + variableId: paramsOrFirst as string + }; + } + + const variableId = params.variableId; + + if (typeof variableId === 'undefined') { + throw new AppwriteException('Missing required parameter: "variableId"'); + } + + const apiPath = '/project/variables/{variableId}'.replace('{variableId}', variableId); + const payload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + } + + return this.client.call( + 'get', + uri, + apiHeaders, + payload, + ); + } + + /** + * Update variable by its unique ID. + * + * @param {string} params.variableId - Variable ID. + * @param {string} params.key - Variable key. Max length: 255 chars. + * @param {string} params.value - Variable value. Max length: 8192 chars. + * @param {boolean} params.secret - Secret variables can be updated or deleted, but only projects can read them during build and runtime. + * @throws {AppwriteException} + * @returns {Promise} + */ + updateVariable(params: { variableId: string, key?: string, value?: string, secret?: boolean }): Promise; + /** + * Update variable by its unique ID. + * + * @param {string} variableId - Variable ID. + * @param {string} key - Variable key. Max length: 255 chars. + * @param {string} value - Variable value. Max length: 8192 chars. + * @param {boolean} secret - Secret variables can be updated or deleted, but only projects can read them during build and runtime. + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + updateVariable(variableId: string, key?: string, value?: string, secret?: boolean): Promise; + updateVariable( + paramsOrFirst: { variableId: string, key?: string, value?: string, secret?: boolean } | string, + ...rest: [(string)?, (string)?, (boolean)?] + ): Promise { + let params: { variableId: string, key?: string, value?: string, secret?: boolean }; + + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { + params = (paramsOrFirst || {}) as { variableId: string, key?: string, value?: string, secret?: boolean }; + } else { + params = { + variableId: paramsOrFirst as string, + key: rest[0] as string, + value: rest[1] as string, + secret: rest[2] as boolean + }; + } + + const variableId = params.variableId; + const key = params.key; + const value = params.value; + const secret = params.secret; + + if (typeof variableId === 'undefined') { + throw new AppwriteException('Missing required parameter: "variableId"'); + } + + const apiPath = '/project/variables/{variableId}'.replace('{variableId}', variableId); + const payload: Payload = {}; + if (typeof key !== 'undefined') { + payload['key'] = key; + } + if (typeof value !== 'undefined') { + payload['value'] = value; + } + if (typeof secret !== 'undefined') { + payload['secret'] = secret; + } + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'content-type': 'application/json', + } + + return this.client.call( + 'put', + uri, + apiHeaders, + payload, + ); + } + + /** + * Delete a variable by its unique ID. + * + * @param {string} params.variableId - Variable ID. + * @throws {AppwriteException} + * @returns {Promise<{}>} + */ + deleteVariable(params: { variableId: string }): Promise<{}>; + /** + * Delete a variable by its unique ID. + * + * @param {string} variableId - Variable ID. + * @throws {AppwriteException} + * @returns {Promise<{}>} + * @deprecated Use the object parameter style method for a better developer experience. + */ + deleteVariable(variableId: string): Promise<{}>; + deleteVariable( + paramsOrFirst: { variableId: string } | string + ): Promise<{}> { + let params: { variableId: string }; + + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { + params = (paramsOrFirst || {}) as { variableId: string }; + } else { + params = { + variableId: paramsOrFirst as string + }; + } + + const variableId = params.variableId; + + if (typeof variableId === 'undefined') { + throw new AppwriteException('Missing required parameter: "variableId"'); + } + + const apiPath = '/project/variables/{variableId}'.replace('{variableId}', variableId); + const payload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'content-type': 'application/json', + } + + return this.client.call( + 'delete', + uri, + apiHeaders, + payload, + ); + } +} diff --git a/src/services/sites.ts b/src/services/sites.ts index 5018382a..4ae79aaf 100644 --- a/src/services/sites.ts +++ b/src/services/sites.ts @@ -93,6 +93,7 @@ export class Sites { * @param {number} params.timeout - Maximum request time in seconds. * @param {string} params.installCommand - Install Command. * @param {string} params.buildCommand - Build Command. + * @param {string} params.startCommand - Custom start command. Leave empty to use default. * @param {string} params.outputDirectory - Output Directory for site. * @param {Adapter} params.adapter - Framework adapter defining rendering strategy. Allowed values are: static, ssr * @param {string} params.installationId - Appwrite Installation ID for VCS (Version Control System) deployment. @@ -101,11 +102,13 @@ export class Sites { * @param {string} params.providerBranch - Production branch for the repo linked to the site. * @param {boolean} params.providerSilentMode - Is the VCS (Version Control System) connection in silent mode for the repo linked to the site? In silent mode, comments will not be made on commits and pull requests. * @param {string} params.providerRootDirectory - Path to site code in the linked repo. - * @param {string} params.specification - Framework specification for the site and builds. + * @param {string} params.buildSpecification - Build specification for the site deployments. + * @param {string} params.runtimeSpecification - Runtime specification for the SSR executions. + * @param {number} params.deploymentRetention - Days to keep non-active deployments before deletion. Value 0 means all deployments will be kept. * @throws {AppwriteException} * @returns {Promise} */ - create(params: { siteId: string, name: string, framework: Framework, buildRuntime: BuildRuntime, enabled?: boolean, logging?: boolean, timeout?: number, installCommand?: string, buildCommand?: string, outputDirectory?: string, adapter?: Adapter, installationId?: string, fallbackFile?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, specification?: string }): Promise; + create(params: { siteId: string, name: string, framework: Framework, buildRuntime: BuildRuntime, enabled?: boolean, logging?: boolean, timeout?: number, installCommand?: string, buildCommand?: string, startCommand?: string, outputDirectory?: string, adapter?: Adapter, installationId?: string, fallbackFile?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, buildSpecification?: string, runtimeSpecification?: string, deploymentRetention?: number }): Promise; /** * Create a new site. * @@ -118,6 +121,7 @@ export class Sites { * @param {number} timeout - Maximum request time in seconds. * @param {string} installCommand - Install Command. * @param {string} buildCommand - Build Command. + * @param {string} startCommand - Custom start command. Leave empty to use default. * @param {string} outputDirectory - Output Directory for site. * @param {Adapter} adapter - Framework adapter defining rendering strategy. Allowed values are: static, ssr * @param {string} installationId - Appwrite Installation ID for VCS (Version Control System) deployment. @@ -126,20 +130,22 @@ export class Sites { * @param {string} providerBranch - Production branch for the repo linked to the site. * @param {boolean} providerSilentMode - Is the VCS (Version Control System) connection in silent mode for the repo linked to the site? In silent mode, comments will not be made on commits and pull requests. * @param {string} providerRootDirectory - Path to site code in the linked repo. - * @param {string} specification - Framework specification for the site and builds. + * @param {string} buildSpecification - Build specification for the site deployments. + * @param {string} runtimeSpecification - Runtime specification for the SSR executions. + * @param {number} deploymentRetention - Days to keep non-active deployments before deletion. Value 0 means all deployments will be kept. * @throws {AppwriteException} * @returns {Promise} * @deprecated Use the object parameter style method for a better developer experience. */ - create(siteId: string, name: string, framework: Framework, buildRuntime: BuildRuntime, enabled?: boolean, logging?: boolean, timeout?: number, installCommand?: string, buildCommand?: string, outputDirectory?: string, adapter?: Adapter, installationId?: string, fallbackFile?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, specification?: string): Promise; + create(siteId: string, name: string, framework: Framework, buildRuntime: BuildRuntime, enabled?: boolean, logging?: boolean, timeout?: number, installCommand?: string, buildCommand?: string, startCommand?: string, outputDirectory?: string, adapter?: Adapter, installationId?: string, fallbackFile?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, buildSpecification?: string, runtimeSpecification?: string, deploymentRetention?: number): Promise; create( - paramsOrFirst: { siteId: string, name: string, framework: Framework, buildRuntime: BuildRuntime, enabled?: boolean, logging?: boolean, timeout?: number, installCommand?: string, buildCommand?: string, outputDirectory?: string, adapter?: Adapter, installationId?: string, fallbackFile?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, specification?: string } | string, - ...rest: [(string)?, (Framework)?, (BuildRuntime)?, (boolean)?, (boolean)?, (number)?, (string)?, (string)?, (string)?, (Adapter)?, (string)?, (string)?, (string)?, (string)?, (boolean)?, (string)?, (string)?] + paramsOrFirst: { siteId: string, name: string, framework: Framework, buildRuntime: BuildRuntime, enabled?: boolean, logging?: boolean, timeout?: number, installCommand?: string, buildCommand?: string, startCommand?: string, outputDirectory?: string, adapter?: Adapter, installationId?: string, fallbackFile?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, buildSpecification?: string, runtimeSpecification?: string, deploymentRetention?: number } | string, + ...rest: [(string)?, (Framework)?, (BuildRuntime)?, (boolean)?, (boolean)?, (number)?, (string)?, (string)?, (string)?, (string)?, (Adapter)?, (string)?, (string)?, (string)?, (string)?, (boolean)?, (string)?, (string)?, (string)?, (number)?] ): Promise { - let params: { siteId: string, name: string, framework: Framework, buildRuntime: BuildRuntime, enabled?: boolean, logging?: boolean, timeout?: number, installCommand?: string, buildCommand?: string, outputDirectory?: string, adapter?: Adapter, installationId?: string, fallbackFile?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, specification?: string }; + let params: { siteId: string, name: string, framework: Framework, buildRuntime: BuildRuntime, enabled?: boolean, logging?: boolean, timeout?: number, installCommand?: string, buildCommand?: string, startCommand?: string, outputDirectory?: string, adapter?: Adapter, installationId?: string, fallbackFile?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, buildSpecification?: string, runtimeSpecification?: string, deploymentRetention?: number }; if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { - params = (paramsOrFirst || {}) as { siteId: string, name: string, framework: Framework, buildRuntime: BuildRuntime, enabled?: boolean, logging?: boolean, timeout?: number, installCommand?: string, buildCommand?: string, outputDirectory?: string, adapter?: Adapter, installationId?: string, fallbackFile?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, specification?: string }; + params = (paramsOrFirst || {}) as { siteId: string, name: string, framework: Framework, buildRuntime: BuildRuntime, enabled?: boolean, logging?: boolean, timeout?: number, installCommand?: string, buildCommand?: string, startCommand?: string, outputDirectory?: string, adapter?: Adapter, installationId?: string, fallbackFile?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, buildSpecification?: string, runtimeSpecification?: string, deploymentRetention?: number }; } else { params = { siteId: paramsOrFirst as string, @@ -151,15 +157,18 @@ export class Sites { timeout: rest[5] as number, installCommand: rest[6] as string, buildCommand: rest[7] as string, - outputDirectory: rest[8] as string, - adapter: rest[9] as Adapter, - installationId: rest[10] as string, - fallbackFile: rest[11] as string, - providerRepositoryId: rest[12] as string, - providerBranch: rest[13] as string, - providerSilentMode: rest[14] as boolean, - providerRootDirectory: rest[15] as string, - specification: rest[16] as string + startCommand: rest[8] as string, + outputDirectory: rest[9] as string, + adapter: rest[10] as Adapter, + installationId: rest[11] as string, + fallbackFile: rest[12] as string, + providerRepositoryId: rest[13] as string, + providerBranch: rest[14] as string, + providerSilentMode: rest[15] as boolean, + providerRootDirectory: rest[16] as string, + buildSpecification: rest[17] as string, + runtimeSpecification: rest[18] as string, + deploymentRetention: rest[19] as number }; } @@ -172,6 +181,7 @@ export class Sites { const timeout = params.timeout; const installCommand = params.installCommand; const buildCommand = params.buildCommand; + const startCommand = params.startCommand; const outputDirectory = params.outputDirectory; const adapter = params.adapter; const installationId = params.installationId; @@ -180,7 +190,9 @@ export class Sites { const providerBranch = params.providerBranch; const providerSilentMode = params.providerSilentMode; const providerRootDirectory = params.providerRootDirectory; - const specification = params.specification; + const buildSpecification = params.buildSpecification; + const runtimeSpecification = params.runtimeSpecification; + const deploymentRetention = params.deploymentRetention; if (typeof siteId === 'undefined') { throw new AppwriteException('Missing required parameter: "siteId"'); @@ -221,6 +233,9 @@ export class Sites { if (typeof buildCommand !== 'undefined') { payload['buildCommand'] = buildCommand; } + if (typeof startCommand !== 'undefined') { + payload['startCommand'] = startCommand; + } if (typeof outputDirectory !== 'undefined') { payload['outputDirectory'] = outputDirectory; } @@ -248,8 +263,14 @@ export class Sites { if (typeof providerRootDirectory !== 'undefined') { payload['providerRootDirectory'] = providerRootDirectory; } - if (typeof specification !== 'undefined') { - payload['specification'] = specification; + if (typeof buildSpecification !== 'undefined') { + payload['buildSpecification'] = buildSpecification; + } + if (typeof runtimeSpecification !== 'undefined') { + payload['runtimeSpecification'] = runtimeSpecification; + } + if (typeof deploymentRetention !== 'undefined') { + payload['deploymentRetention'] = deploymentRetention; } const uri = new URL(this.client.config.endpoint + apiPath); @@ -373,6 +394,7 @@ export class Sites { * @param {number} params.timeout - Maximum request time in seconds. * @param {string} params.installCommand - Install Command. * @param {string} params.buildCommand - Build Command. + * @param {string} params.startCommand - Custom start command. Leave empty to use default. * @param {string} params.outputDirectory - Output Directory for site. * @param {BuildRuntime} params.buildRuntime - Runtime to use during build step. * @param {Adapter} params.adapter - Framework adapter defining rendering strategy. Allowed values are: static, ssr @@ -382,11 +404,13 @@ export class Sites { * @param {string} params.providerBranch - Production branch for the repo linked to the site. * @param {boolean} params.providerSilentMode - Is the VCS (Version Control System) connection in silent mode for the repo linked to the site? In silent mode, comments will not be made on commits and pull requests. * @param {string} params.providerRootDirectory - Path to site code in the linked repo. - * @param {string} params.specification - Framework specification for the site and builds. + * @param {string} params.buildSpecification - Build specification for the site deployments. + * @param {string} params.runtimeSpecification - Runtime specification for the SSR executions. + * @param {number} params.deploymentRetention - Days to keep non-active deployments before deletion. Value 0 means all deployments will be kept. * @throws {AppwriteException} * @returns {Promise} */ - update(params: { siteId: string, name: string, framework: Framework, enabled?: boolean, logging?: boolean, timeout?: number, installCommand?: string, buildCommand?: string, outputDirectory?: string, buildRuntime?: BuildRuntime, adapter?: Adapter, fallbackFile?: string, installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, specification?: string }): Promise; + update(params: { siteId: string, name: string, framework: Framework, enabled?: boolean, logging?: boolean, timeout?: number, installCommand?: string, buildCommand?: string, startCommand?: string, outputDirectory?: string, buildRuntime?: BuildRuntime, adapter?: Adapter, fallbackFile?: string, installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, buildSpecification?: string, runtimeSpecification?: string, deploymentRetention?: number }): Promise; /** * Update site by its unique ID. * @@ -398,6 +422,7 @@ export class Sites { * @param {number} timeout - Maximum request time in seconds. * @param {string} installCommand - Install Command. * @param {string} buildCommand - Build Command. + * @param {string} startCommand - Custom start command. Leave empty to use default. * @param {string} outputDirectory - Output Directory for site. * @param {BuildRuntime} buildRuntime - Runtime to use during build step. * @param {Adapter} adapter - Framework adapter defining rendering strategy. Allowed values are: static, ssr @@ -407,20 +432,22 @@ export class Sites { * @param {string} providerBranch - Production branch for the repo linked to the site. * @param {boolean} providerSilentMode - Is the VCS (Version Control System) connection in silent mode for the repo linked to the site? In silent mode, comments will not be made on commits and pull requests. * @param {string} providerRootDirectory - Path to site code in the linked repo. - * @param {string} specification - Framework specification for the site and builds. + * @param {string} buildSpecification - Build specification for the site deployments. + * @param {string} runtimeSpecification - Runtime specification for the SSR executions. + * @param {number} deploymentRetention - Days to keep non-active deployments before deletion. Value 0 means all deployments will be kept. * @throws {AppwriteException} * @returns {Promise} * @deprecated Use the object parameter style method for a better developer experience. */ - update(siteId: string, name: string, framework: Framework, enabled?: boolean, logging?: boolean, timeout?: number, installCommand?: string, buildCommand?: string, outputDirectory?: string, buildRuntime?: BuildRuntime, adapter?: Adapter, fallbackFile?: string, installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, specification?: string): Promise; + update(siteId: string, name: string, framework: Framework, enabled?: boolean, logging?: boolean, timeout?: number, installCommand?: string, buildCommand?: string, startCommand?: string, outputDirectory?: string, buildRuntime?: BuildRuntime, adapter?: Adapter, fallbackFile?: string, installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, buildSpecification?: string, runtimeSpecification?: string, deploymentRetention?: number): Promise; update( - paramsOrFirst: { siteId: string, name: string, framework: Framework, enabled?: boolean, logging?: boolean, timeout?: number, installCommand?: string, buildCommand?: string, outputDirectory?: string, buildRuntime?: BuildRuntime, adapter?: Adapter, fallbackFile?: string, installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, specification?: string } | string, - ...rest: [(string)?, (Framework)?, (boolean)?, (boolean)?, (number)?, (string)?, (string)?, (string)?, (BuildRuntime)?, (Adapter)?, (string)?, (string)?, (string)?, (string)?, (boolean)?, (string)?, (string)?] + paramsOrFirst: { siteId: string, name: string, framework: Framework, enabled?: boolean, logging?: boolean, timeout?: number, installCommand?: string, buildCommand?: string, startCommand?: string, outputDirectory?: string, buildRuntime?: BuildRuntime, adapter?: Adapter, fallbackFile?: string, installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, buildSpecification?: string, runtimeSpecification?: string, deploymentRetention?: number } | string, + ...rest: [(string)?, (Framework)?, (boolean)?, (boolean)?, (number)?, (string)?, (string)?, (string)?, (string)?, (BuildRuntime)?, (Adapter)?, (string)?, (string)?, (string)?, (string)?, (boolean)?, (string)?, (string)?, (string)?, (number)?] ): Promise { - let params: { siteId: string, name: string, framework: Framework, enabled?: boolean, logging?: boolean, timeout?: number, installCommand?: string, buildCommand?: string, outputDirectory?: string, buildRuntime?: BuildRuntime, adapter?: Adapter, fallbackFile?: string, installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, specification?: string }; + let params: { siteId: string, name: string, framework: Framework, enabled?: boolean, logging?: boolean, timeout?: number, installCommand?: string, buildCommand?: string, startCommand?: string, outputDirectory?: string, buildRuntime?: BuildRuntime, adapter?: Adapter, fallbackFile?: string, installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, buildSpecification?: string, runtimeSpecification?: string, deploymentRetention?: number }; if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { - params = (paramsOrFirst || {}) as { siteId: string, name: string, framework: Framework, enabled?: boolean, logging?: boolean, timeout?: number, installCommand?: string, buildCommand?: string, outputDirectory?: string, buildRuntime?: BuildRuntime, adapter?: Adapter, fallbackFile?: string, installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, specification?: string }; + params = (paramsOrFirst || {}) as { siteId: string, name: string, framework: Framework, enabled?: boolean, logging?: boolean, timeout?: number, installCommand?: string, buildCommand?: string, startCommand?: string, outputDirectory?: string, buildRuntime?: BuildRuntime, adapter?: Adapter, fallbackFile?: string, installationId?: string, providerRepositoryId?: string, providerBranch?: string, providerSilentMode?: boolean, providerRootDirectory?: string, buildSpecification?: string, runtimeSpecification?: string, deploymentRetention?: number }; } else { params = { siteId: paramsOrFirst as string, @@ -431,16 +458,19 @@ export class Sites { timeout: rest[4] as number, installCommand: rest[5] as string, buildCommand: rest[6] as string, - outputDirectory: rest[7] as string, - buildRuntime: rest[8] as BuildRuntime, - adapter: rest[9] as Adapter, - fallbackFile: rest[10] as string, - installationId: rest[11] as string, - providerRepositoryId: rest[12] as string, - providerBranch: rest[13] as string, - providerSilentMode: rest[14] as boolean, - providerRootDirectory: rest[15] as string, - specification: rest[16] as string + startCommand: rest[7] as string, + outputDirectory: rest[8] as string, + buildRuntime: rest[9] as BuildRuntime, + adapter: rest[10] as Adapter, + fallbackFile: rest[11] as string, + installationId: rest[12] as string, + providerRepositoryId: rest[13] as string, + providerBranch: rest[14] as string, + providerSilentMode: rest[15] as boolean, + providerRootDirectory: rest[16] as string, + buildSpecification: rest[17] as string, + runtimeSpecification: rest[18] as string, + deploymentRetention: rest[19] as number }; } @@ -452,6 +482,7 @@ export class Sites { const timeout = params.timeout; const installCommand = params.installCommand; const buildCommand = params.buildCommand; + const startCommand = params.startCommand; const outputDirectory = params.outputDirectory; const buildRuntime = params.buildRuntime; const adapter = params.adapter; @@ -461,7 +492,9 @@ export class Sites { const providerBranch = params.providerBranch; const providerSilentMode = params.providerSilentMode; const providerRootDirectory = params.providerRootDirectory; - const specification = params.specification; + const buildSpecification = params.buildSpecification; + const runtimeSpecification = params.runtimeSpecification; + const deploymentRetention = params.deploymentRetention; if (typeof siteId === 'undefined') { throw new AppwriteException('Missing required parameter: "siteId"'); @@ -496,6 +529,9 @@ export class Sites { if (typeof buildCommand !== 'undefined') { payload['buildCommand'] = buildCommand; } + if (typeof startCommand !== 'undefined') { + payload['startCommand'] = startCommand; + } if (typeof outputDirectory !== 'undefined') { payload['outputDirectory'] = outputDirectory; } @@ -523,8 +559,14 @@ export class Sites { if (typeof providerRootDirectory !== 'undefined') { payload['providerRootDirectory'] = providerRootDirectory; } - if (typeof specification !== 'undefined') { - payload['specification'] = specification; + if (typeof buildSpecification !== 'undefined') { + payload['buildSpecification'] = buildSpecification; + } + if (typeof runtimeSpecification !== 'undefined') { + payload['runtimeSpecification'] = runtimeSpecification; + } + if (typeof deploymentRetention !== 'undefined') { + payload['deploymentRetention'] = deploymentRetention; } const uri = new URL(this.client.config.endpoint + apiPath); diff --git a/src/services/tables-db.ts b/src/services/tables-db.ts index af1fa996..509e7554 100644 --- a/src/services/tables-db.ts +++ b/src/services/tables-db.ts @@ -3,7 +3,7 @@ import type { Models } from '../models'; import { RelationshipType } from '../enums/relationship-type'; import { RelationMutate } from '../enums/relation-mutate'; -import { IndexType } from '../enums/index-type'; +import { TablesDBIndexType } from '../enums/tables-db-index-type'; import { OrderBy } from '../enums/order-by'; export class TablesDB { @@ -4693,14 +4693,14 @@ export class TablesDB { * @param {string} params.databaseId - Database ID. * @param {string} params.tableId - Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable). * @param {string} params.key - Index Key. - * @param {IndexType} params.type - Index type. + * @param {TablesDBIndexType} params.type - Index type. * @param {string[]} params.columns - Array of columns to index. Maximum of 100 columns are allowed, each 32 characters long. * @param {OrderBy[]} params.orders - Array of index orders. Maximum of 100 orders are allowed. * @param {number[]} params.lengths - Length of index. Maximum of 100 * @throws {AppwriteException} * @returns {Promise} */ - createIndex(params: { databaseId: string, tableId: string, key: string, type: IndexType, columns: string[], orders?: OrderBy[], lengths?: number[] }): Promise; + createIndex(params: { databaseId: string, tableId: string, key: string, type: TablesDBIndexType, columns: string[], orders?: OrderBy[], lengths?: number[] }): Promise; /** * Creates an index on the columns listed. Your index should include all the columns you will query in a single request. * Type can be `key`, `fulltext`, or `unique`. @@ -4708,7 +4708,7 @@ export class TablesDB { * @param {string} databaseId - Database ID. * @param {string} tableId - Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable). * @param {string} key - Index Key. - * @param {IndexType} type - Index type. + * @param {TablesDBIndexType} type - Index type. * @param {string[]} columns - Array of columns to index. Maximum of 100 columns are allowed, each 32 characters long. * @param {OrderBy[]} orders - Array of index orders. Maximum of 100 orders are allowed. * @param {number[]} lengths - Length of index. Maximum of 100 @@ -4716,21 +4716,21 @@ export class TablesDB { * @returns {Promise} * @deprecated Use the object parameter style method for a better developer experience. */ - createIndex(databaseId: string, tableId: string, key: string, type: IndexType, columns: string[], orders?: OrderBy[], lengths?: number[]): Promise; + createIndex(databaseId: string, tableId: string, key: string, type: TablesDBIndexType, columns: string[], orders?: OrderBy[], lengths?: number[]): Promise; createIndex( - paramsOrFirst: { databaseId: string, tableId: string, key: string, type: IndexType, columns: string[], orders?: OrderBy[], lengths?: number[] } | string, - ...rest: [(string)?, (string)?, (IndexType)?, (string[])?, (OrderBy[])?, (number[])?] + paramsOrFirst: { databaseId: string, tableId: string, key: string, type: TablesDBIndexType, columns: string[], orders?: OrderBy[], lengths?: number[] } | string, + ...rest: [(string)?, (string)?, (TablesDBIndexType)?, (string[])?, (OrderBy[])?, (number[])?] ): Promise { - let params: { databaseId: string, tableId: string, key: string, type: IndexType, columns: string[], orders?: OrderBy[], lengths?: number[] }; + let params: { databaseId: string, tableId: string, key: string, type: TablesDBIndexType, columns: string[], orders?: OrderBy[], lengths?: number[] }; if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { - params = (paramsOrFirst || {}) as { databaseId: string, tableId: string, key: string, type: IndexType, columns: string[], orders?: OrderBy[], lengths?: number[] }; + params = (paramsOrFirst || {}) as { databaseId: string, tableId: string, key: string, type: TablesDBIndexType, columns: string[], orders?: OrderBy[], lengths?: number[] }; } else { params = { databaseId: paramsOrFirst as string, tableId: rest[0] as string, key: rest[1] as string, - type: rest[2] as IndexType, + type: rest[2] as TablesDBIndexType, columns: rest[3] as string[], orders: rest[4] as OrderBy[], lengths: rest[5] as number[] diff --git a/src/services/users.ts b/src/services/users.ts index a837dcb9..7bef1693 100644 --- a/src/services/users.ts +++ b/src/services/users.ts @@ -15,7 +15,7 @@ export class Users { /** * Get a list of all the project's users. You can use the query params to filter your results. * - * @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, email, phone, status, passwordUpdate, registration, emailVerification, phoneVerification, labels + * @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, email, phone, status, passwordUpdate, registration, emailVerification, phoneVerification, labels, impersonator * @param {string} params.search - Search term to filter your list results. Max length: 256 chars. * @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated. * @throws {AppwriteException} @@ -25,7 +25,7 @@ export class Users { /** * Get a list of all the project's users. You can use the query params to filter your results. * - * @param {string[]} queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, email, phone, status, passwordUpdate, registration, emailVerification, phoneVerification, labels + * @param {string[]} queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, email, phone, status, passwordUpdate, registration, emailVerification, phoneVerification, labels, impersonator * @param {string} search - Search term to filter your list results. Max length: 256 chars. * @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated. * @throws {AppwriteException} @@ -1114,6 +1114,71 @@ export class Users { ); } + /** + * Enable or disable whether a user can impersonate other users. When impersonation headers are used, the request runs as the target user for API behavior, while internal audit logs still attribute the action to the original impersonator and store the impersonated target details only in internal audit payload data. + * + * + * @param {string} params.userId - User ID. + * @param {boolean} params.impersonator - Whether the user can impersonate other users. When true, the user can browse project users to choose a target and can pass impersonation headers to act as that user. Internal audit logs still attribute impersonated actions to the original impersonator and store the target user details only in internal audit payload data. + * @throws {AppwriteException} + * @returns {Promise>} + */ + updateImpersonator(params: { userId: string, impersonator: boolean }): Promise>; + /** + * Enable or disable whether a user can impersonate other users. When impersonation headers are used, the request runs as the target user for API behavior, while internal audit logs still attribute the action to the original impersonator and store the impersonated target details only in internal audit payload data. + * + * + * @param {string} userId - User ID. + * @param {boolean} impersonator - Whether the user can impersonate other users. When true, the user can browse project users to choose a target and can pass impersonation headers to act as that user. Internal audit logs still attribute impersonated actions to the original impersonator and store the target user details only in internal audit payload data. + * @throws {AppwriteException} + * @returns {Promise>} + * @deprecated Use the object parameter style method for a better developer experience. + */ + updateImpersonator(userId: string, impersonator: boolean): Promise>; + updateImpersonator( + paramsOrFirst: { userId: string, impersonator: boolean } | string, + ...rest: [(boolean)?] + ): Promise> { + let params: { userId: string, impersonator: boolean }; + + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { + params = (paramsOrFirst || {}) as { userId: string, impersonator: boolean }; + } else { + params = { + userId: paramsOrFirst as string, + impersonator: rest[0] as boolean + }; + } + + const userId = params.userId; + const impersonator = params.impersonator; + + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + if (typeof impersonator === 'undefined') { + throw new AppwriteException('Missing required parameter: "impersonator"'); + } + + const apiPath = '/users/{userId}/impersonator'.replace('{userId}', userId); + const payload: Payload = {}; + if (typeof impersonator !== 'undefined') { + payload['impersonator'] = impersonator; + } + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'content-type': 'application/json', + } + + return this.client.call( + 'patch', + uri, + apiHeaders, + payload, + ); + } + /** * Use this endpoint to create a JSON Web Token for user by its unique ID. You can use the resulting JWT to authenticate on behalf of the user. The JWT secret will become invalid if the session it uses gets deleted. * diff --git a/src/services/webhooks.ts b/src/services/webhooks.ts new file mode 100644 index 00000000..daa78ce0 --- /dev/null +++ b/src/services/webhooks.ts @@ -0,0 +1,450 @@ +import { AppwriteException, Client, type Payload, UploadProgress } from '../client'; +import type { Models } from '../models'; + + +export class Webhooks { + client: Client; + + constructor(client: Client) { + this.client = client; + } + + /** + * Get a list of all webhooks belonging to the project. You can use the query params to filter your results. + * + * @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, url, httpUser, security, events, enabled, logs, attempts + * @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated. + * @throws {AppwriteException} + * @returns {Promise} + */ + list(params?: { queries?: string[], total?: boolean }): Promise; + /** + * Get a list of all webhooks belonging to the project. You can use the query params to filter your results. + * + * @param {string[]} queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, url, httpUser, security, events, enabled, logs, attempts + * @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated. + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + list(queries?: string[], total?: boolean): Promise; + list( + paramsOrFirst?: { queries?: string[], total?: boolean } | string[], + ...rest: [(boolean)?] + ): Promise { + let params: { queries?: string[], total?: boolean }; + + if (!paramsOrFirst || (paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { + params = (paramsOrFirst || {}) as { queries?: string[], total?: boolean }; + } else { + params = { + queries: paramsOrFirst as string[], + total: rest[0] as boolean + }; + } + + const queries = params.queries; + const total = params.total; + + + const apiPath = '/webhooks'; + const payload: Payload = {}; + if (typeof queries !== 'undefined') { + payload['queries'] = queries; + } + if (typeof total !== 'undefined') { + payload['total'] = total; + } + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + } + + return this.client.call( + 'get', + uri, + apiHeaders, + payload, + ); + } + + /** + * Create a new webhook. Use this endpoint to configure a URL that will receive events from Appwrite when specific events occur. + * + * @param {string} params.webhookId - Webhook ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. + * @param {string} params.url - Webhook URL. + * @param {string} params.name - Webhook name. Max length: 128 chars. + * @param {string[]} params.events - Events list. Maximum of 100 events are allowed. + * @param {boolean} params.enabled - Enable or disable a webhook. + * @param {boolean} params.security - Certificate verification, false for disabled or true for enabled. + * @param {string} params.httpUser - Webhook HTTP user. Max length: 256 chars. + * @param {string} params.httpPass - Webhook HTTP password. Max length: 256 chars. + * @throws {AppwriteException} + * @returns {Promise} + */ + create(params: { webhookId: string, url: string, name: string, events: string[], enabled?: boolean, security?: boolean, httpUser?: string, httpPass?: string }): Promise; + /** + * Create a new webhook. Use this endpoint to configure a URL that will receive events from Appwrite when specific events occur. + * + * @param {string} webhookId - Webhook ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. + * @param {string} url - Webhook URL. + * @param {string} name - Webhook name. Max length: 128 chars. + * @param {string[]} events - Events list. Maximum of 100 events are allowed. + * @param {boolean} enabled - Enable or disable a webhook. + * @param {boolean} security - Certificate verification, false for disabled or true for enabled. + * @param {string} httpUser - Webhook HTTP user. Max length: 256 chars. + * @param {string} httpPass - Webhook HTTP password. Max length: 256 chars. + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + create(webhookId: string, url: string, name: string, events: string[], enabled?: boolean, security?: boolean, httpUser?: string, httpPass?: string): Promise; + create( + paramsOrFirst: { webhookId: string, url: string, name: string, events: string[], enabled?: boolean, security?: boolean, httpUser?: string, httpPass?: string } | string, + ...rest: [(string)?, (string)?, (string[])?, (boolean)?, (boolean)?, (string)?, (string)?] + ): Promise { + let params: { webhookId: string, url: string, name: string, events: string[], enabled?: boolean, security?: boolean, httpUser?: string, httpPass?: string }; + + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { + params = (paramsOrFirst || {}) as { webhookId: string, url: string, name: string, events: string[], enabled?: boolean, security?: boolean, httpUser?: string, httpPass?: string }; + } else { + params = { + webhookId: paramsOrFirst as string, + url: rest[0] as string, + name: rest[1] as string, + events: rest[2] as string[], + enabled: rest[3] as boolean, + security: rest[4] as boolean, + httpUser: rest[5] as string, + httpPass: rest[6] as string + }; + } + + const webhookId = params.webhookId; + const url = params.url; + const name = params.name; + const events = params.events; + const enabled = params.enabled; + const security = params.security; + const httpUser = params.httpUser; + const httpPass = params.httpPass; + + if (typeof webhookId === 'undefined') { + throw new AppwriteException('Missing required parameter: "webhookId"'); + } + if (typeof url === 'undefined') { + throw new AppwriteException('Missing required parameter: "url"'); + } + if (typeof name === 'undefined') { + throw new AppwriteException('Missing required parameter: "name"'); + } + if (typeof events === 'undefined') { + throw new AppwriteException('Missing required parameter: "events"'); + } + + const apiPath = '/webhooks'; + const payload: Payload = {}; + if (typeof webhookId !== 'undefined') { + payload['webhookId'] = webhookId; + } + if (typeof url !== 'undefined') { + payload['url'] = url; + } + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof events !== 'undefined') { + payload['events'] = events; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + if (typeof security !== 'undefined') { + payload['security'] = security; + } + if (typeof httpUser !== 'undefined') { + payload['httpUser'] = httpUser; + } + if (typeof httpPass !== 'undefined') { + payload['httpPass'] = httpPass; + } + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'content-type': 'application/json', + } + + return this.client.call( + 'post', + uri, + apiHeaders, + payload, + ); + } + + /** + * Get a webhook by its unique ID. This endpoint returns details about a specific webhook configured for a project. + * + * @param {string} params.webhookId - Webhook ID. + * @throws {AppwriteException} + * @returns {Promise} + */ + get(params: { webhookId: string }): Promise; + /** + * Get a webhook by its unique ID. This endpoint returns details about a specific webhook configured for a project. + * + * @param {string} webhookId - Webhook ID. + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + get(webhookId: string): Promise; + get( + paramsOrFirst: { webhookId: string } | string + ): Promise { + let params: { webhookId: string }; + + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { + params = (paramsOrFirst || {}) as { webhookId: string }; + } else { + params = { + webhookId: paramsOrFirst as string + }; + } + + const webhookId = params.webhookId; + + if (typeof webhookId === 'undefined') { + throw new AppwriteException('Missing required parameter: "webhookId"'); + } + + const apiPath = '/webhooks/{webhookId}'.replace('{webhookId}', webhookId); + const payload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + } + + return this.client.call( + 'get', + uri, + apiHeaders, + payload, + ); + } + + /** + * Update a webhook by its unique ID. Use this endpoint to update the URL, events, or status of an existing webhook. + * + * @param {string} params.webhookId - Webhook ID. + * @param {string} params.name - Webhook name. Max length: 128 chars. + * @param {string} params.url - Webhook URL. + * @param {string[]} params.events - Events list. Maximum of 100 events are allowed. + * @param {boolean} params.enabled - Enable or disable a webhook. + * @param {boolean} params.security - Certificate verification, false for disabled or true for enabled. + * @param {string} params.httpUser - Webhook HTTP user. Max length: 256 chars. + * @param {string} params.httpPass - Webhook HTTP password. Max length: 256 chars. + * @throws {AppwriteException} + * @returns {Promise} + */ + update(params: { webhookId: string, name: string, url: string, events: string[], enabled?: boolean, security?: boolean, httpUser?: string, httpPass?: string }): Promise; + /** + * Update a webhook by its unique ID. Use this endpoint to update the URL, events, or status of an existing webhook. + * + * @param {string} webhookId - Webhook ID. + * @param {string} name - Webhook name. Max length: 128 chars. + * @param {string} url - Webhook URL. + * @param {string[]} events - Events list. Maximum of 100 events are allowed. + * @param {boolean} enabled - Enable or disable a webhook. + * @param {boolean} security - Certificate verification, false for disabled or true for enabled. + * @param {string} httpUser - Webhook HTTP user. Max length: 256 chars. + * @param {string} httpPass - Webhook HTTP password. Max length: 256 chars. + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + update(webhookId: string, name: string, url: string, events: string[], enabled?: boolean, security?: boolean, httpUser?: string, httpPass?: string): Promise; + update( + paramsOrFirst: { webhookId: string, name: string, url: string, events: string[], enabled?: boolean, security?: boolean, httpUser?: string, httpPass?: string } | string, + ...rest: [(string)?, (string)?, (string[])?, (boolean)?, (boolean)?, (string)?, (string)?] + ): Promise { + let params: { webhookId: string, name: string, url: string, events: string[], enabled?: boolean, security?: boolean, httpUser?: string, httpPass?: string }; + + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { + params = (paramsOrFirst || {}) as { webhookId: string, name: string, url: string, events: string[], enabled?: boolean, security?: boolean, httpUser?: string, httpPass?: string }; + } else { + params = { + webhookId: paramsOrFirst as string, + name: rest[0] as string, + url: rest[1] as string, + events: rest[2] as string[], + enabled: rest[3] as boolean, + security: rest[4] as boolean, + httpUser: rest[5] as string, + httpPass: rest[6] as string + }; + } + + const webhookId = params.webhookId; + const name = params.name; + const url = params.url; + const events = params.events; + const enabled = params.enabled; + const security = params.security; + const httpUser = params.httpUser; + const httpPass = params.httpPass; + + if (typeof webhookId === 'undefined') { + throw new AppwriteException('Missing required parameter: "webhookId"'); + } + if (typeof name === 'undefined') { + throw new AppwriteException('Missing required parameter: "name"'); + } + if (typeof url === 'undefined') { + throw new AppwriteException('Missing required parameter: "url"'); + } + if (typeof events === 'undefined') { + throw new AppwriteException('Missing required parameter: "events"'); + } + + const apiPath = '/webhooks/{webhookId}'.replace('{webhookId}', webhookId); + const payload: Payload = {}; + if (typeof name !== 'undefined') { + payload['name'] = name; + } + if (typeof url !== 'undefined') { + payload['url'] = url; + } + if (typeof events !== 'undefined') { + payload['events'] = events; + } + if (typeof enabled !== 'undefined') { + payload['enabled'] = enabled; + } + if (typeof security !== 'undefined') { + payload['security'] = security; + } + if (typeof httpUser !== 'undefined') { + payload['httpUser'] = httpUser; + } + if (typeof httpPass !== 'undefined') { + payload['httpPass'] = httpPass; + } + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'content-type': 'application/json', + } + + return this.client.call( + 'put', + uri, + apiHeaders, + payload, + ); + } + + /** + * Delete a webhook by its unique ID. Once deleted, the webhook will no longer receive project events. + * + * @param {string} params.webhookId - Webhook ID. + * @throws {AppwriteException} + * @returns {Promise<{}>} + */ + delete(params: { webhookId: string }): Promise<{}>; + /** + * Delete a webhook by its unique ID. Once deleted, the webhook will no longer receive project events. + * + * @param {string} webhookId - Webhook ID. + * @throws {AppwriteException} + * @returns {Promise<{}>} + * @deprecated Use the object parameter style method for a better developer experience. + */ + delete(webhookId: string): Promise<{}>; + delete( + paramsOrFirst: { webhookId: string } | string + ): Promise<{}> { + let params: { webhookId: string }; + + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { + params = (paramsOrFirst || {}) as { webhookId: string }; + } else { + params = { + webhookId: paramsOrFirst as string + }; + } + + const webhookId = params.webhookId; + + if (typeof webhookId === 'undefined') { + throw new AppwriteException('Missing required parameter: "webhookId"'); + } + + const apiPath = '/webhooks/{webhookId}'.replace('{webhookId}', webhookId); + const payload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'content-type': 'application/json', + } + + return this.client.call( + 'delete', + uri, + apiHeaders, + payload, + ); + } + + /** + * Update the webhook signature key. This endpoint can be used to regenerate the signature key used to sign and validate payload deliveries for a specific webhook. + * + * @param {string} params.webhookId - Webhook ID. + * @throws {AppwriteException} + * @returns {Promise} + */ + updateSignature(params: { webhookId: string }): Promise; + /** + * Update the webhook signature key. This endpoint can be used to regenerate the signature key used to sign and validate payload deliveries for a specific webhook. + * + * @param {string} webhookId - Webhook ID. + * @throws {AppwriteException} + * @returns {Promise} + * @deprecated Use the object parameter style method for a better developer experience. + */ + updateSignature(webhookId: string): Promise; + updateSignature( + paramsOrFirst: { webhookId: string } | string + ): Promise { + let params: { webhookId: string }; + + if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) { + params = (paramsOrFirst || {}) as { webhookId: string }; + } else { + params = { + webhookId: paramsOrFirst as string + }; + } + + const webhookId = params.webhookId; + + if (typeof webhookId === 'undefined') { + throw new AppwriteException('Missing required parameter: "webhookId"'); + } + + const apiPath = '/webhooks/{webhookId}/signature'.replace('{webhookId}', webhookId); + const payload: Payload = {}; + const uri = new URL(this.client.config.endpoint + apiPath); + + const apiHeaders: { [header: string]: string } = { + 'content-type': 'application/json', + } + + return this.client.call( + 'patch', + uri, + apiHeaders, + payload, + ); + } +} diff --git a/test/id.test.js b/test/id.test.js new file mode 100644 index 00000000..0a648bc1 --- /dev/null +++ b/test/id.test.js @@ -0,0 +1,6 @@ +const { ID } = require("../dist/id"); + +describe("ID", () => { + test('unique', () => expect(ID.unique()).toHaveLength(20)); + test('custom', () => expect(ID.custom('custom')).toEqual('custom')); +}); diff --git a/test/operator.test.js b/test/operator.test.js new file mode 100644 index 00000000..a14910cd --- /dev/null +++ b/test/operator.test.js @@ -0,0 +1,99 @@ +const { Condition, Operator } = require("../dist/operator"); + +describe('Operator', () => { + test('returns increment', () => { + expect(Operator.increment(1)).toEqual(`{"method":"increment","values":[1]}`); + }); + + test('returns increment with max', () => { + expect(Operator.increment(5, 100)).toEqual(`{"method":"increment","values":[5,100]}`); + }); + + test('returns decrement', () => { + expect(Operator.decrement(1)).toEqual(`{"method":"decrement","values":[1]}`); + }); + + test('returns decrement with min', () => { + expect(Operator.decrement(3, 0)).toEqual(`{"method":"decrement","values":[3,0]}`); + }); + + test('returns multiply', () => { + expect(Operator.multiply(2)).toEqual(`{"method":"multiply","values":[2]}`); + }); + + test('returns multiply with max', () => { + expect(Operator.multiply(3, 1000)).toEqual(`{"method":"multiply","values":[3,1000]}`); + }); + + test('returns divide', () => { + expect(Operator.divide(2)).toEqual(`{"method":"divide","values":[2]}`); + }); + + test('returns divide with min', () => { + expect(Operator.divide(4, 1)).toEqual(`{"method":"divide","values":[4,1]}`); + }); + + test('returns modulo', () => { + expect(Operator.modulo(5)).toEqual(`{"method":"modulo","values":[5]}`); + }); + + test('returns power', () => { + expect(Operator.power(2)).toEqual(`{"method":"power","values":[2]}`); + }); + + test('returns arrayAppend', () => { + expect(Operator.arrayAppend(['item1', 'item2'])).toEqual('{"method":"arrayAppend","values":["item1","item2"]}'); + }); + + test('returns arrayPrepend', () => { + expect(Operator.arrayPrepend(['first', 'second'])).toEqual('{"method":"arrayPrepend","values":["first","second"]}'); + }); + + test('returns arrayInsert', () => { + expect(Operator.arrayInsert(0, 'newItem')).toEqual('{"method":"arrayInsert","values":[0,"newItem"]}'); + }); + + test('returns arrayRemove', () => { + expect(Operator.arrayRemove('oldItem')).toEqual('{"method":"arrayRemove","values":["oldItem"]}'); + }); + + test('returns arrayUnique', () => { + expect(Operator.arrayUnique()).toEqual('{"method":"arrayUnique","values":[]}'); + }); + + test('returns arrayIntersect', () => { + expect(Operator.arrayIntersect(['a', 'b', 'c'])).toEqual('{"method":"arrayIntersect","values":["a","b","c"]}'); + }); + + test('returns arrayDiff', () => { + expect(Operator.arrayDiff(['x', 'y'])).toEqual('{"method":"arrayDiff","values":["x","y"]}'); + }); + + test('returns arrayFilter', () => { + expect(Operator.arrayFilter(Condition.Equal, 'test')).toEqual('{"method":"arrayFilter","values":["equal","test"]}'); + }); + + test('returns stringConcat', () => { + expect(Operator.stringConcat('suffix')).toEqual('{"method":"stringConcat","values":["suffix"]}'); + }); + + test('returns stringReplace', () => { + expect(Operator.stringReplace('old', 'new')).toEqual('{"method":"stringReplace","values":["old","new"]}'); + }); + + test('returns toggle', () => { + expect(Operator.toggle()).toEqual('{"method":"toggle","values":[]}'); + }); + + test('returns dateAddDays', () => { + expect(Operator.dateAddDays(7)).toEqual('{"method":"dateAddDays","values":[7]}'); + }); + + test('returns dateSubDays', () => { + expect(Operator.dateSubDays(7)).toEqual('{"method":"dateSubDays","values":[7]}'); + }); + + test('returns dateSetNow', () => { + expect(Operator.dateSetNow()).toEqual('{"method":"dateSetNow","values":[]}'); + }); +}); diff --git a/test/permission.test.js b/test/permission.test.js new file mode 100644 index 00000000..7f972d3b --- /dev/null +++ b/test/permission.test.js @@ -0,0 +1,10 @@ +const { Permission } = require("../dist/permission"); +const { Role } = require("../dist/role"); + +describe('Permission', () => { + test('read', () => expect(Permission.read(Role.any())).toEqual('read("any")')); + test('write', () => expect(Permission.write(Role.any())).toEqual('write("any")')); + test('create', () => expect(Permission.create(Role.any())).toEqual('create("any")')); + test('update', () => expect(Permission.update(Role.any())).toEqual('update("any")')); + test('delete', () => expect(Permission.delete(Role.any())).toEqual('delete("any")')); +}) diff --git a/test/query.test.js b/test/query.test.js new file mode 100644 index 00000000..e539a1f6 --- /dev/null +++ b/test/query.test.js @@ -0,0 +1,155 @@ +const { Query } = require("../dist/query"); + +const tests = [ + { + description: 'with a string', + value: 's', + expectedValues: '["s"]' + }, + { + description: 'with a integer', + value: 1, + expectedValues: '[1]' + }, + { + description: 'with a double', + value: 1.2, + expectedValues: '[1.2]' + }, + { + description: 'with a whole number double', + value: 1.0, + expectedValues: '[1]' + }, + { + description: 'with a bool', + value: false, + expectedValues: '[false]' + }, + { + description: 'with a list', + value: ['a', 'b', 'c'], + expectedValues: '["a","b","c"]' + } +]; + +describe('Query', () => { + describe('basic filter equal', () => { + for (const t of tests) { + test(t.description, () => + expect(Query.equal("attr", t.value)) + .toEqual(`{"method":"equal","attribute":"attr","values":${t.expectedValues}}`) + ) + } + }) + + describe('basic filter notEqual', () => { + for (const t of tests) { + test(t.description, () => + expect(Query.notEqual("attr", t.value)) + .toEqual(`{"method":"notEqual","attribute":"attr","values":${t.expectedValues}}`) + ) + } + }); + + describe('basic filter lessThan', () => { + for (const t of tests) { + test(t.description, () => + expect(Query.lessThan("attr", t.value)) + .toEqual(`{"method":"lessThan","attribute":"attr","values":${t.expectedValues}}`) + ) + } + }); + + describe('basic filter lessThanEqual', () => { + for (const t of tests) { + test(t.description, () => + expect(Query.lessThanEqual("attr", t.value)) + .toEqual(`{"method":"lessThanEqual","attribute":"attr","values":${t.expectedValues}}`) + ) + } + }); + + describe('basic filter greaterThan', () => { + for (const t of tests) { + test(t.description, () => + expect(Query.greaterThan("attr", t.value)) + .toEqual(`{"method":"greaterThan","attribute":"attr","values":${t.expectedValues}}`) + ) + } + }); + + describe('basic filter greaterThanEqual', () => { + for (const t of tests) { + test(t.description, () => + expect(Query.greaterThanEqual("attr", t.value)) + .toEqual(`{"method":"greaterThanEqual","attribute":"attr","values":${t.expectedValues}}`) + ) + } + }); + + test('search', () => + expect(Query.search('attr', 'keyword1 keyword2')) + .toEqual(`{"method":"search","attribute":"attr","values":["keyword1 keyword2"]}`) + ); + + test('isNull', () => + expect(Query.isNull('attr')) + .toEqual(`{"method":"isNull","attribute":"attr"}`) + ); + + test('isNotNull', () => + expect(Query.isNotNull('attr')) + .toEqual(`{"method":"isNotNull","attribute":"attr"}`) + ); + + describe('between', () => { + test('with integers', () => + expect(Query.between('attr', 1, 2)) + .toEqual(`{"method":"between","attribute":"attr","values":[1,2]}`) + ); + test('with doubles', () => + expect(Query.between('attr', 1.2, 2.2)) + .toEqual(`{"method":"between","attribute":"attr","values":[1.2,2.2]}`) + ); + test('with strings', () => + expect(Query.between('attr',"a","z")) + .toEqual(`{"method":"between","attribute":"attr","values":["a","z"]}`) + ); + }); + + test('select', () => + expect(Query.select(['attr1', 'attr2'])) + .toEqual(`{"method":"select","values":["attr1","attr2"]}`) + ); + + test('orderAsc', () => + expect(Query.orderAsc('attr')) + .toEqual(`{"method":"orderAsc","attribute":"attr"}`) + ); + + test('orderDesc', () => + expect(Query.orderDesc('attr')) + .toEqual(`{"method":"orderDesc","attribute":"attr"}`) + ); + + test('cursorBefore', () => + expect(Query.cursorBefore('attr')) + .toEqual('{"method":"cursorBefore","values":["attr"]}') + ); + + test('cursorAfter', () => + expect(Query.cursorAfter('attr')) + .toEqual('{"method":"cursorAfter","values":["attr"]}') + ); + + test('limit', () => + expect(Query.limit(1)) + .toEqual('{"method":"limit","values":[1]}') + ); + + test('offset', () => + expect(Query.offset(1)) + .toEqual('{"method":"offset","values":[1]}') + ); +}) diff --git a/test/role.test.js b/test/role.test.js new file mode 100644 index 00000000..8f7420bd --- /dev/null +++ b/test/role.test.js @@ -0,0 +1,14 @@ +const { Role } = require("../dist/role"); + +describe('Role', () => { + test('any', () => expect(Role.any()).toEqual('any')); + test('user without status', () => expect(Role.user('custom')).toEqual('user:custom')); + test('user with status', () => expect(Role.user('custom', 'verified')).toEqual('user:custom/verified')); + test('users without status', () => expect(Role.users()).toEqual('users')); + test('users with status', () => expect(Role.users('verified')).toEqual('users/verified')); + test('guests', () => expect(Role.guests()).toEqual('guests')); + test('team without role', () => expect(Role.team('custom')).toEqual('team:custom')) + test('team with role', () => expect(Role.team('custom', 'owner')).toEqual('team:custom/owner')) + test('member', () => expect(Role.member('custom')).toEqual('member:custom')) + test('label', () => expect(Role.label('admin')).toEqual('label:admin')) +}) diff --git a/test/services/account.test.js b/test/services/account.test.js new file mode 100644 index 00000000..ec447a86 --- /dev/null +++ b/test/services/account.test.js @@ -0,0 +1,1307 @@ +const { Client } = require("../../dist/client"); +const { InputFile } = require("../../dist/inputFile"); +const { Account } = require("../../dist/services/account"); + +const { fetch: mockedFetch, Response } = require("node-fetch-native-with-agent"); +jest.mock('node-fetch-native-with-agent', () => ({ ...jest.requireActual('node-fetch-native-with-agent'), fetch: jest.fn() })); + +describe('Account', () => { + const client = new Client(); + const account = new Account(client); + + + test('test method get()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.get( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method create()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.create( + '', + 'email@example.com', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateEmail()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.updateEmail( + 'email@example.com', + 'password', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listIdentities()', async () => { + const data = { + 'total': 5, + 'identities': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.listIdentities( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteIdentity()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.deleteIdentity( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createJWT()', async () => { + const data = { + 'jwt': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.createJWT( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listLogs()', async () => { + const data = { + 'total': 5, + 'logs': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.listLogs( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateMFA()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.updateMFA( + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createMfaAuthenticator()', async () => { + const data = { + 'secret': '1', + 'uri': '1',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.createMfaAuthenticator( + 'totp', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createMFAAuthenticator()', async () => { + const data = { + 'secret': '1', + 'uri': '1',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.createMFAAuthenticator( + 'totp', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateMfaAuthenticator()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.updateMfaAuthenticator( + 'totp', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateMFAAuthenticator()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.updateMFAAuthenticator( + 'totp', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteMfaAuthenticator()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.deleteMfaAuthenticator( + 'totp', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteMFAAuthenticator()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.deleteMFAAuthenticator( + 'totp', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createMfaChallenge()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'expire': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.createMfaChallenge( + 'email', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createMFAChallenge()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'expire': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.createMFAChallenge( + 'email', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateMfaChallenge()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.updateMfaChallenge( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateMFAChallenge()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.updateMFAChallenge( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listMfaFactors()', async () => { + const data = { + 'totp': true, + 'phone': true, + 'email': true, + 'recoveryCode': true,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.listMfaFactors( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listMFAFactors()', async () => { + const data = { + 'totp': true, + 'phone': true, + 'email': true, + 'recoveryCode': true,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.listMFAFactors( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getMfaRecoveryCodes()', async () => { + const data = { + 'recoveryCodes': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.getMfaRecoveryCodes( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getMFARecoveryCodes()', async () => { + const data = { + 'recoveryCodes': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.getMFARecoveryCodes( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createMfaRecoveryCodes()', async () => { + const data = { + 'recoveryCodes': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.createMfaRecoveryCodes( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createMFARecoveryCodes()', async () => { + const data = { + 'recoveryCodes': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.createMFARecoveryCodes( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateMfaRecoveryCodes()', async () => { + const data = { + 'recoveryCodes': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.updateMfaRecoveryCodes( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateMFARecoveryCodes()', async () => { + const data = { + 'recoveryCodes': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.updateMFARecoveryCodes( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateName()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.updateName( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updatePassword()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.updatePassword( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updatePhone()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.updatePhone( + '+12065550100', + 'password', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getPrefs()', async () => { + const data = {}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.getPrefs( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updatePrefs()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.updatePrefs( + {}, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createRecovery()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.createRecovery( + 'email@example.com', + 'https://example.com', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateRecovery()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.updateRecovery( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listSessions()', async () => { + const data = { + 'total': 5, + 'sessions': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.listSessions( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteSessions()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.deleteSessions( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createAnonymousSession()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.createAnonymousSession( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createEmailPasswordSession()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.createEmailPasswordSession( + 'email@example.com', + 'password', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateMagicURLSession()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.updateMagicURLSession( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updatePhoneSession()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.updatePhoneSession( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createSession()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.createSession( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getSession()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.getSession( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateSession()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.updateSession( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteSession()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.deleteSession( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateStatus()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.updateStatus( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createEmailToken()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.createEmailToken( + '', + 'email@example.com', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createMagicURLToken()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.createMagicURLToken( + '', + 'email@example.com', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createOAuth2Token()', async () => { + const data = 'https://example.com/'; + mockedFetch.mockImplementation(() => Response.redirect(data)); + + const response = await account.createOAuth2Token( + 'amazon', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createPhoneToken()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.createPhoneToken( + '', + '+12065550100', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createEmailVerification()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.createEmailVerification( + 'https://example.com', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createVerification()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.createVerification( + 'https://example.com', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateEmailVerification()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.updateEmailVerification( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateVerification()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.updateVerification( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createPhoneVerification()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.createPhoneVerification( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updatePhoneVerification()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await account.updatePhoneVerification( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + }) diff --git a/test/services/activities.test.js b/test/services/activities.test.js new file mode 100644 index 00000000..fcf8e46e --- /dev/null +++ b/test/services/activities.test.js @@ -0,0 +1,73 @@ +const { Client } = require("../../dist/client"); +const { InputFile } = require("../../dist/inputFile"); +const { Activities } = require("../../dist/services/activities"); + +const { fetch: mockedFetch, Response } = require("node-fetch-native-with-agent"); +jest.mock('node-fetch-native-with-agent', () => ({ ...jest.requireActual('node-fetch-native-with-agent'), fetch: jest.fn() })); + +describe('Activities', () => { + const client = new Client(); + const activities = new Activities(client); + + + test('test method listEvents()', async () => { + const data = { + 'total': 5, + 'events': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await activities.listEvents( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getEvent()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + 'userType': 'user', + 'userId': '610fc2f985ee0', + 'userEmail': 'john@appwrite.io', + 'userName': 'John Doe', + 'resourceParent': 'database/ID', + 'resourceType': 'collection', + 'resourceId': '610fc2f985ee0', + 'resource': 'collections/610fc2f985ee0', + 'event': 'account.sessions.create', + 'userAgent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36', + 'ip': '127.0.0.1', + 'mode': 'admin', + 'country': 'US', + 'time': '2020-10-15T06:38:00.000+00:00', + 'projectId': '610fc2f985ee0', + 'teamId': '610fc2f985ee0', + 'hostname': 'appwrite.io', + '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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await activities.getEvent( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + }) diff --git a/test/services/avatars.test.js b/test/services/avatars.test.js new file mode 100644 index 00000000..ea4f3798 --- /dev/null +++ b/test/services/avatars.test.js @@ -0,0 +1,123 @@ +const { Client } = require("../../dist/client"); +const { InputFile } = require("../../dist/inputFile"); +const { Avatars } = require("../../dist/services/avatars"); + +const { fetch: mockedFetch, Response } = require("node-fetch-native-with-agent"); +jest.mock('node-fetch-native-with-agent', () => ({ ...jest.requireActual('node-fetch-native-with-agent'), fetch: jest.fn() })); + +describe('Avatars', () => { + const client = new Client(); + const avatars = new Avatars(client); + + + test('test method getBrowser()', async () => { + const data = new ArrayBuffer(0); + mockedFetch.mockImplementation(() => new Response(data)); + + const response = await avatars.getBrowser( + 'aa', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getCreditCard()', async () => { + const data = new ArrayBuffer(0); + mockedFetch.mockImplementation(() => new Response(data)); + + const response = await avatars.getCreditCard( + 'amex', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getFavicon()', async () => { + const data = new ArrayBuffer(0); + mockedFetch.mockImplementation(() => new Response(data)); + + const response = await avatars.getFavicon( + 'https://example.com', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getFlag()', async () => { + const data = new ArrayBuffer(0); + mockedFetch.mockImplementation(() => new Response(data)); + + const response = await avatars.getFlag( + 'af', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getImage()', async () => { + const data = new ArrayBuffer(0); + mockedFetch.mockImplementation(() => new Response(data)); + + const response = await avatars.getImage( + 'https://example.com', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getInitials()', async () => { + const data = new ArrayBuffer(0); + mockedFetch.mockImplementation(() => new Response(data)); + + const response = await avatars.getInitials( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getQR()', async () => { + const data = new ArrayBuffer(0); + mockedFetch.mockImplementation(() => new Response(data)); + + const response = await avatars.getQR( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getScreenshot()', async () => { + const data = new ArrayBuffer(0); + mockedFetch.mockImplementation(() => new Response(data)); + + const response = await avatars.getScreenshot( + 'https://example.com', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + }) diff --git a/test/services/backups.test.js b/test/services/backups.test.js new file mode 100644 index 00000000..b87b1c08 --- /dev/null +++ b/test/services/backups.test.js @@ -0,0 +1,256 @@ +const { Client } = require("../../dist/client"); +const { InputFile } = require("../../dist/inputFile"); +const { Backups } = require("../../dist/services/backups"); + +const { fetch: mockedFetch, Response } = require("node-fetch-native-with-agent"); +jest.mock('node-fetch-native-with-agent', () => ({ ...jest.requireActual('node-fetch-native-with-agent'), fetch: jest.fn() })); + +describe('Backups', () => { + const client = new Client(); + const backups = new Backups(client); + + + test('test method listArchives()', async () => { + const data = { + 'total': 5, + 'archives': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await backups.listArchives( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createArchive()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'policyId': 'did8jx6ws45jana098ab7', + 'size': 100000, + 'status': 'completed', + 'startedAt': '2020-10-15T06:38:00.000+00:00', + 'migrationId': 'did8jx6ws45jana098ab7', + 'services': [], + 'resources': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await backups.createArchive( + [], + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getArchive()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'policyId': 'did8jx6ws45jana098ab7', + 'size': 100000, + 'status': 'completed', + 'startedAt': '2020-10-15T06:38:00.000+00:00', + 'migrationId': 'did8jx6ws45jana098ab7', + 'services': [], + 'resources': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await backups.getArchive( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteArchive()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await backups.deleteArchive( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listPolicies()', async () => { + const data = { + 'total': 5, + 'policies': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await backups.listPolicies( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createPolicy()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + 'name': 'Hourly backups', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'services': [], + 'resources': [], + 'retention': 7, + 'schedule': '0 * * * *', + 'enabled': true,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await backups.createPolicy( + '', + [], + 1, + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getPolicy()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + 'name': 'Hourly backups', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'services': [], + 'resources': [], + 'retention': 7, + 'schedule': '0 * * * *', + 'enabled': true,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await backups.getPolicy( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updatePolicy()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + 'name': 'Hourly backups', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'services': [], + 'resources': [], + 'retention': 7, + 'schedule': '0 * * * *', + 'enabled': true,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await backups.updatePolicy( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deletePolicy()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await backups.deletePolicy( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createRestoration()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'archiveId': 'did8jx6ws45jana098ab7', + 'policyId': 'did8jx6ws45jana098ab7', + 'status': 'completed', + 'startedAt': '2020-10-15T06:38:00.000+00:00', + 'migrationId': 'did8jx6ws45jana098ab7', + 'services': [], + 'resources': [], + 'options': '{databases.database[{oldId, newId, newName}]}',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await backups.createRestoration( + '', + [], + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listRestorations()', async () => { + const data = { + 'total': 5, + 'restorations': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await backups.listRestorations( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getRestoration()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'archiveId': 'did8jx6ws45jana098ab7', + 'policyId': 'did8jx6ws45jana098ab7', + 'status': 'completed', + 'startedAt': '2020-10-15T06:38:00.000+00:00', + 'migrationId': 'did8jx6ws45jana098ab7', + 'services': [], + 'resources': [], + 'options': '{databases.database[{oldId, newId, newName}]}',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await backups.getRestoration( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + }) diff --git a/test/services/databases.test.js b/test/services/databases.test.js new file mode 100644 index 00000000..ff809d28 --- /dev/null +++ b/test/services/databases.test.js @@ -0,0 +1,1574 @@ +const { Client } = require("../../dist/client"); +const { InputFile } = require("../../dist/inputFile"); +const { Databases } = require("../../dist/services/databases"); + +const { fetch: mockedFetch, Response } = require("node-fetch-native-with-agent"); +jest.mock('node-fetch-native-with-agent', () => ({ ...jest.requireActual('node-fetch-native-with-agent'), fetch: jest.fn() })); + +describe('Databases', () => { + const client = new Client(); + const databases = new Databases(client); + + + test('test method list()', async () => { + const data = { + 'total': 5, + 'databases': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.list( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method create()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + 'name': 'My Database', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'enabled': true, + 'type': 'legacy', + 'policies': [], + 'archives': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.create( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listTransactions()', async () => { + const data = { + 'total': 5, + 'transactions': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.listTransactions( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createTransaction()', async () => { + const data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'status': 'pending', + 'operations': 5, + 'expiresAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createTransaction( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getTransaction()', async () => { + const data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'status': 'pending', + 'operations': 5, + 'expiresAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.getTransaction( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateTransaction()', async () => { + const data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'status': 'pending', + 'operations': 5, + 'expiresAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.updateTransaction( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteTransaction()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.deleteTransaction( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createOperations()', async () => { + const data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'status': 'pending', + 'operations': 5, + 'expiresAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createOperations( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method get()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + 'name': 'My Database', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'enabled': true, + 'type': 'legacy', + 'policies': [], + 'archives': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.get( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method update()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + 'name': 'My Database', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'enabled': true, + 'type': 'legacy', + 'policies': [], + 'archives': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.update( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method delete()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.delete( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listCollections()', async () => { + const data = { + 'total': 5, + 'collections': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.listCollections( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createCollection()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'databaseId': '5e5ea5c16897e', + 'name': 'My Collection', + 'enabled': true, + 'documentSecurity': true, + 'attributes': [], + 'indexes': [], + 'bytesMax': 65535, + 'bytesUsed': 1500,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createCollection( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getCollection()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'databaseId': '5e5ea5c16897e', + 'name': 'My Collection', + 'enabled': true, + 'documentSecurity': true, + 'attributes': [], + 'indexes': [], + 'bytesMax': 65535, + 'bytesUsed': 1500,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.getCollection( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateCollection()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'databaseId': '5e5ea5c16897e', + 'name': 'My Collection', + 'enabled': true, + 'documentSecurity': true, + 'attributes': [], + 'indexes': [], + 'bytesMax': 65535, + 'bytesUsed': 1500,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.updateCollection( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteCollection()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.deleteCollection( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listAttributes()', async () => { + const data = { + 'total': 5, + 'attributes': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.listAttributes( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createBooleanAttribute()', async () => { + const data = { + 'key': 'isEnabled', + 'type': 'boolean', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createBooleanAttribute( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateBooleanAttribute()', async () => { + const data = { + 'key': 'isEnabled', + 'type': 'boolean', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.updateBooleanAttribute( + '', + '', + '', + true, + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createDatetimeAttribute()', async () => { + const data = { + 'key': 'birthDay', + 'type': 'datetime', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'format': 'datetime',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createDatetimeAttribute( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateDatetimeAttribute()', async () => { + const data = { + 'key': 'birthDay', + 'type': 'datetime', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'format': 'datetime',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.updateDatetimeAttribute( + '', + '', + '', + true, + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createEmailAttribute()', async () => { + const data = { + 'key': 'userEmail', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'format': 'email',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createEmailAttribute( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateEmailAttribute()', async () => { + const data = { + 'key': 'userEmail', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'format': 'email',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.updateEmailAttribute( + '', + '', + '', + true, + 'email@example.com', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createEnumAttribute()', async () => { + const data = { + 'key': 'status', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'elements': [], + 'format': 'enum',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createEnumAttribute( + '', + '', + '', + [], + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateEnumAttribute()', async () => { + const data = { + 'key': 'status', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'elements': [], + 'format': 'enum',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.updateEnumAttribute( + '', + '', + '', + [], + true, + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createFloatAttribute()', async () => { + const data = { + 'key': 'percentageCompleted', + 'type': 'double', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createFloatAttribute( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateFloatAttribute()', async () => { + const data = { + 'key': 'percentageCompleted', + 'type': 'double', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.updateFloatAttribute( + '', + '', + '', + true, + 1.0, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createIntegerAttribute()', async () => { + const data = { + 'key': 'count', + 'type': 'integer', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createIntegerAttribute( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateIntegerAttribute()', async () => { + const data = { + 'key': 'count', + 'type': 'integer', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.updateIntegerAttribute( + '', + '', + '', + true, + 1, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createIpAttribute()', async () => { + const data = { + 'key': 'ipAddress', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'format': 'ip',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createIpAttribute( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateIpAttribute()', async () => { + const data = { + 'key': 'ipAddress', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'format': 'ip',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.updateIpAttribute( + '', + '', + '', + true, + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createLineAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createLineAttribute( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateLineAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.updateLineAttribute( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createLongtextAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createLongtextAttribute( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateLongtextAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.updateLongtextAttribute( + '', + '', + '', + true, + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createMediumtextAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createMediumtextAttribute( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateMediumtextAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.updateMediumtextAttribute( + '', + '', + '', + true, + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createPointAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createPointAttribute( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updatePointAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.updatePointAttribute( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createPolygonAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createPolygonAttribute( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updatePolygonAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.updatePolygonAttribute( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createRelationshipAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'relatedCollection': 'collection', + 'relationType': 'oneToOne|oneToMany|manyToOne|manyToMany', + 'twoWay': true, + 'twoWayKey': 'string', + 'onDelete': 'restrict|cascade|setNull', + 'side': 'parent|child',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createRelationshipAttribute( + '', + '', + '', + 'oneToOne', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateRelationshipAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'relatedCollection': 'collection', + 'relationType': 'oneToOne|oneToMany|manyToOne|manyToMany', + 'twoWay': true, + 'twoWayKey': 'string', + 'onDelete': 'restrict|cascade|setNull', + 'side': 'parent|child',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.updateRelationshipAttribute( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createStringAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'size': 128,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createStringAttribute( + '', + '', + '', + 1, + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateStringAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'size': 128,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.updateStringAttribute( + '', + '', + '', + true, + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createTextAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createTextAttribute( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateTextAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.updateTextAttribute( + '', + '', + '', + true, + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createUrlAttribute()', async () => { + const data = { + 'key': 'githubUrl', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'format': 'url',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createUrlAttribute( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateUrlAttribute()', async () => { + const data = { + 'key': 'githubUrl', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'format': 'url',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.updateUrlAttribute( + '', + '', + '', + true, + 'https://example.com', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createVarcharAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'size': 128,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createVarcharAttribute( + '', + '', + '', + 1, + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateVarcharAttribute()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'size': 128,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.updateVarcharAttribute( + '', + '', + '', + true, + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getAttribute()', async () => { + const data = { + 'key': 'isEnabled', + 'type': 'boolean', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.getAttribute( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteAttribute()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.deleteAttribute( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listDocuments()', async () => { + const data = { + 'total': 5, + 'documents': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.listDocuments( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createDocument()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$sequence': '1', + '\$collectionId': '5e5ea5c15117e', + '\$databaseId': '5e5ea5c15117e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createDocument( + '', + '', + '', + {}, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createDocuments()', async () => { + const data = { + 'total': 5, + 'documents': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createDocuments( + '', + '', + [], + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method upsertDocuments()', async () => { + const data = { + 'total': 5, + 'documents': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.upsertDocuments( + '', + '', + [], + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateDocuments()', async () => { + const data = { + 'total': 5, + 'documents': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.updateDocuments( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteDocuments()', async () => { + const data = { + 'total': 5, + 'documents': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.deleteDocuments( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getDocument()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$sequence': '1', + '\$collectionId': '5e5ea5c15117e', + '\$databaseId': '5e5ea5c15117e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.getDocument( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method upsertDocument()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$sequence': '1', + '\$collectionId': '5e5ea5c15117e', + '\$databaseId': '5e5ea5c15117e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.upsertDocument( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateDocument()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$sequence': '1', + '\$collectionId': '5e5ea5c15117e', + '\$databaseId': '5e5ea5c15117e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.updateDocument( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteDocument()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.deleteDocument( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method decrementDocumentAttribute()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$sequence': '1', + '\$collectionId': '5e5ea5c15117e', + '\$databaseId': '5e5ea5c15117e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.decrementDocumentAttribute( + '', + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method incrementDocumentAttribute()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$sequence': '1', + '\$collectionId': '5e5ea5c15117e', + '\$databaseId': '5e5ea5c15117e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.incrementDocumentAttribute( + '', + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listIndexes()', async () => { + const data = { + 'total': 5, + 'indexes': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.listIndexes( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createIndex()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'key': 'index1', + 'type': 'primary', + 'status': 'available', + 'error': 'string', + 'attributes': [], + 'lengths': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.createIndex( + '', + '', + '', + 'key', + [], + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getIndex()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'key': 'index1', + 'type': 'primary', + 'status': 'available', + 'error': 'string', + 'attributes': [], + 'lengths': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.getIndex( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteIndex()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await databases.deleteIndex( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + }) diff --git a/test/services/functions.test.js b/test/services/functions.test.js new file mode 100644 index 00000000..b057cd62 --- /dev/null +++ b/test/services/functions.test.js @@ -0,0 +1,751 @@ +const { Client } = require("../../dist/client"); +const { InputFile } = require("../../dist/inputFile"); +const { Functions } = require("../../dist/services/functions"); + +const { fetch: mockedFetch, Response } = require("node-fetch-native-with-agent"); +jest.mock('node-fetch-native-with-agent', () => ({ ...jest.requireActual('node-fetch-native-with-agent'), fetch: jest.fn() })); + +describe('Functions', () => { + const client = new Client(); + const functions = new Functions(client); + + + test('test method list()', async () => { + const data = { + 'total': 5, + 'functions': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.list( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method create()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'execute': [], + 'name': 'My Function', + 'enabled': true, + 'live': true, + 'logging': true, + 'runtime': 'python-3.8', + 'deploymentRetention': 7, + 'deploymentId': '5e5ea5c16897e', + 'deploymentCreatedAt': '2020-10-15T06:38:00.000+00:00', + 'latestDeploymentId': '5e5ea5c16897e', + 'latestDeploymentCreatedAt': '2020-10-15T06:38:00.000+00:00', + 'latestDeploymentStatus': 'ready', + 'scopes': [], + 'vars': [], + 'events': [], + 'schedule': '5 4 * * *', + 'timeout': 300, + 'entrypoint': 'index.js', + 'commands': 'npm install', + 'version': 'v2', + 'installationId': '6m40at4ejk5h2u9s1hboo', + 'providerRepositoryId': 'appwrite', + 'providerBranch': 'main', + 'providerRootDirectory': 'functions/helloWorld', + 'providerSilentMode': true, + 'buildSpecification': 's-1vcpu-512mb', + 'runtimeSpecification': 's-1vcpu-512mb',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.create( + '', + '', + 'node-14.5', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listRuntimes()', async () => { + const data = { + 'total': 5, + 'runtimes': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.listRuntimes( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listSpecifications()', async () => { + const data = { + 'total': 5, + 'specifications': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.listSpecifications( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method get()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'execute': [], + 'name': 'My Function', + 'enabled': true, + 'live': true, + 'logging': true, + 'runtime': 'python-3.8', + 'deploymentRetention': 7, + 'deploymentId': '5e5ea5c16897e', + 'deploymentCreatedAt': '2020-10-15T06:38:00.000+00:00', + 'latestDeploymentId': '5e5ea5c16897e', + 'latestDeploymentCreatedAt': '2020-10-15T06:38:00.000+00:00', + 'latestDeploymentStatus': 'ready', + 'scopes': [], + 'vars': [], + 'events': [], + 'schedule': '5 4 * * *', + 'timeout': 300, + 'entrypoint': 'index.js', + 'commands': 'npm install', + 'version': 'v2', + 'installationId': '6m40at4ejk5h2u9s1hboo', + 'providerRepositoryId': 'appwrite', + 'providerBranch': 'main', + 'providerRootDirectory': 'functions/helloWorld', + 'providerSilentMode': true, + 'buildSpecification': 's-1vcpu-512mb', + 'runtimeSpecification': 's-1vcpu-512mb',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.get( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method update()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'execute': [], + 'name': 'My Function', + 'enabled': true, + 'live': true, + 'logging': true, + 'runtime': 'python-3.8', + 'deploymentRetention': 7, + 'deploymentId': '5e5ea5c16897e', + 'deploymentCreatedAt': '2020-10-15T06:38:00.000+00:00', + 'latestDeploymentId': '5e5ea5c16897e', + 'latestDeploymentCreatedAt': '2020-10-15T06:38:00.000+00:00', + 'latestDeploymentStatus': 'ready', + 'scopes': [], + 'vars': [], + 'events': [], + 'schedule': '5 4 * * *', + 'timeout': 300, + 'entrypoint': 'index.js', + 'commands': 'npm install', + 'version': 'v2', + 'installationId': '6m40at4ejk5h2u9s1hboo', + 'providerRepositoryId': 'appwrite', + 'providerBranch': 'main', + 'providerRootDirectory': 'functions/helloWorld', + 'providerSilentMode': true, + 'buildSpecification': 's-1vcpu-512mb', + 'runtimeSpecification': 's-1vcpu-512mb',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.update( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method delete()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.delete( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateFunctionDeployment()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'execute': [], + 'name': 'My Function', + 'enabled': true, + 'live': true, + 'logging': true, + 'runtime': 'python-3.8', + 'deploymentRetention': 7, + 'deploymentId': '5e5ea5c16897e', + 'deploymentCreatedAt': '2020-10-15T06:38:00.000+00:00', + 'latestDeploymentId': '5e5ea5c16897e', + 'latestDeploymentCreatedAt': '2020-10-15T06:38:00.000+00:00', + 'latestDeploymentStatus': 'ready', + 'scopes': [], + 'vars': [], + 'events': [], + 'schedule': '5 4 * * *', + 'timeout': 300, + 'entrypoint': 'index.js', + 'commands': 'npm install', + 'version': 'v2', + 'installationId': '6m40at4ejk5h2u9s1hboo', + 'providerRepositoryId': 'appwrite', + 'providerBranch': 'main', + 'providerRootDirectory': 'functions/helloWorld', + 'providerSilentMode': true, + 'buildSpecification': 's-1vcpu-512mb', + 'runtimeSpecification': 's-1vcpu-512mb',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.updateFunctionDeployment( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listDeployments()', async () => { + const data = { + 'total': 5, + 'deployments': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.listDeployments( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createDeployment()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'type': 'vcs', + 'resourceId': '5e5ea6g16897e', + 'resourceType': 'functions', + 'entrypoint': 'index.js', + 'sourceSize': 128, + 'buildSize': 128, + 'totalSize': 128, + 'buildId': '5e5ea5c16897e', + 'activate': true, + 'screenshotLight': '5e5ea5c16897e', + 'screenshotDark': '5e5ea5c16897e', + 'status': 'ready', + 'buildLogs': 'Compiling source files...', + 'buildDuration': 128, + 'providerRepositoryName': 'database', + 'providerRepositoryOwner': 'utopia', + 'providerRepositoryUrl': 'https://github.com/vermakhushboo/g4-node-function', + 'providerCommitHash': '7c3f25d', + 'providerCommitAuthorUrl': 'https://github.com/vermakhushboo', + 'providerCommitAuthor': 'Khushboo Verma', + 'providerCommitMessage': 'Update index.js', + 'providerCommitUrl': 'https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb', + 'providerBranch': '0.7.x', + 'providerBranchUrl': 'https://github.com/vermakhushboo/appwrite/tree/0.7.x',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.createDeployment( + '', + InputFile.fromBuffer(new Uint8Array(0), 'image.png'), + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createDuplicateDeployment()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'type': 'vcs', + 'resourceId': '5e5ea6g16897e', + 'resourceType': 'functions', + 'entrypoint': 'index.js', + 'sourceSize': 128, + 'buildSize': 128, + 'totalSize': 128, + 'buildId': '5e5ea5c16897e', + 'activate': true, + 'screenshotLight': '5e5ea5c16897e', + 'screenshotDark': '5e5ea5c16897e', + 'status': 'ready', + 'buildLogs': 'Compiling source files...', + 'buildDuration': 128, + 'providerRepositoryName': 'database', + 'providerRepositoryOwner': 'utopia', + 'providerRepositoryUrl': 'https://github.com/vermakhushboo/g4-node-function', + 'providerCommitHash': '7c3f25d', + 'providerCommitAuthorUrl': 'https://github.com/vermakhushboo', + 'providerCommitAuthor': 'Khushboo Verma', + 'providerCommitMessage': 'Update index.js', + 'providerCommitUrl': 'https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb', + 'providerBranch': '0.7.x', + 'providerBranchUrl': 'https://github.com/vermakhushboo/appwrite/tree/0.7.x',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.createDuplicateDeployment( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createTemplateDeployment()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'type': 'vcs', + 'resourceId': '5e5ea6g16897e', + 'resourceType': 'functions', + 'entrypoint': 'index.js', + 'sourceSize': 128, + 'buildSize': 128, + 'totalSize': 128, + 'buildId': '5e5ea5c16897e', + 'activate': true, + 'screenshotLight': '5e5ea5c16897e', + 'screenshotDark': '5e5ea5c16897e', + 'status': 'ready', + 'buildLogs': 'Compiling source files...', + 'buildDuration': 128, + 'providerRepositoryName': 'database', + 'providerRepositoryOwner': 'utopia', + 'providerRepositoryUrl': 'https://github.com/vermakhushboo/g4-node-function', + 'providerCommitHash': '7c3f25d', + 'providerCommitAuthorUrl': 'https://github.com/vermakhushboo', + 'providerCommitAuthor': 'Khushboo Verma', + 'providerCommitMessage': 'Update index.js', + 'providerCommitUrl': 'https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb', + 'providerBranch': '0.7.x', + 'providerBranchUrl': 'https://github.com/vermakhushboo/appwrite/tree/0.7.x',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.createTemplateDeployment( + '', + '', + '', + '', + 'commit', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createVcsDeployment()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'type': 'vcs', + 'resourceId': '5e5ea6g16897e', + 'resourceType': 'functions', + 'entrypoint': 'index.js', + 'sourceSize': 128, + 'buildSize': 128, + 'totalSize': 128, + 'buildId': '5e5ea5c16897e', + 'activate': true, + 'screenshotLight': '5e5ea5c16897e', + 'screenshotDark': '5e5ea5c16897e', + 'status': 'ready', + 'buildLogs': 'Compiling source files...', + 'buildDuration': 128, + 'providerRepositoryName': 'database', + 'providerRepositoryOwner': 'utopia', + 'providerRepositoryUrl': 'https://github.com/vermakhushboo/g4-node-function', + 'providerCommitHash': '7c3f25d', + 'providerCommitAuthorUrl': 'https://github.com/vermakhushboo', + 'providerCommitAuthor': 'Khushboo Verma', + 'providerCommitMessage': 'Update index.js', + 'providerCommitUrl': 'https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb', + 'providerBranch': '0.7.x', + 'providerBranchUrl': 'https://github.com/vermakhushboo/appwrite/tree/0.7.x',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.createVcsDeployment( + '', + 'branch', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getDeployment()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'type': 'vcs', + 'resourceId': '5e5ea6g16897e', + 'resourceType': 'functions', + 'entrypoint': 'index.js', + 'sourceSize': 128, + 'buildSize': 128, + 'totalSize': 128, + 'buildId': '5e5ea5c16897e', + 'activate': true, + 'screenshotLight': '5e5ea5c16897e', + 'screenshotDark': '5e5ea5c16897e', + 'status': 'ready', + 'buildLogs': 'Compiling source files...', + 'buildDuration': 128, + 'providerRepositoryName': 'database', + 'providerRepositoryOwner': 'utopia', + 'providerRepositoryUrl': 'https://github.com/vermakhushboo/g4-node-function', + 'providerCommitHash': '7c3f25d', + 'providerCommitAuthorUrl': 'https://github.com/vermakhushboo', + 'providerCommitAuthor': 'Khushboo Verma', + 'providerCommitMessage': 'Update index.js', + 'providerCommitUrl': 'https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb', + 'providerBranch': '0.7.x', + 'providerBranchUrl': 'https://github.com/vermakhushboo/appwrite/tree/0.7.x',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.getDeployment( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteDeployment()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.deleteDeployment( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getDeploymentDownload()', async () => { + const data = new ArrayBuffer(0); + mockedFetch.mockImplementation(() => new Response(data)); + + const response = await functions.getDeploymentDownload( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateDeploymentStatus()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'type': 'vcs', + 'resourceId': '5e5ea6g16897e', + 'resourceType': 'functions', + 'entrypoint': 'index.js', + 'sourceSize': 128, + 'buildSize': 128, + 'totalSize': 128, + 'buildId': '5e5ea5c16897e', + 'activate': true, + 'screenshotLight': '5e5ea5c16897e', + 'screenshotDark': '5e5ea5c16897e', + 'status': 'ready', + 'buildLogs': 'Compiling source files...', + 'buildDuration': 128, + 'providerRepositoryName': 'database', + 'providerRepositoryOwner': 'utopia', + 'providerRepositoryUrl': 'https://github.com/vermakhushboo/g4-node-function', + 'providerCommitHash': '7c3f25d', + 'providerCommitAuthorUrl': 'https://github.com/vermakhushboo', + 'providerCommitAuthor': 'Khushboo Verma', + 'providerCommitMessage': 'Update index.js', + 'providerCommitUrl': 'https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb', + 'providerBranch': '0.7.x', + 'providerBranchUrl': 'https://github.com/vermakhushboo/appwrite/tree/0.7.x',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.updateDeploymentStatus( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listExecutions()', async () => { + const data = { + 'total': 5, + 'executions': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.listExecutions( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createExecution()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'functionId': '5e5ea6g16897e', + 'deploymentId': '5e5ea5c16897e', + 'trigger': 'http', + 'status': 'processing', + 'requestMethod': 'GET', + 'requestPath': '/articles?id=5', + 'requestHeaders': [], + 'responseStatusCode': 200, + 'responseBody': '', + 'responseHeaders': [], + 'logs': '', + 'errors': '', + 'duration': 0.4,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.createExecution( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getExecution()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'functionId': '5e5ea6g16897e', + 'deploymentId': '5e5ea5c16897e', + 'trigger': 'http', + 'status': 'processing', + 'requestMethod': 'GET', + 'requestPath': '/articles?id=5', + 'requestHeaders': [], + 'responseStatusCode': 200, + 'responseBody': '', + 'responseHeaders': [], + 'logs': '', + 'errors': '', + 'duration': 0.4,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.getExecution( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteExecution()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.deleteExecution( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listVariables()', async () => { + const data = { + 'total': 5, + 'variables': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.listVariables( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createVariable()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'key': 'API_KEY', + 'value': 'myPa\$\$word1', + 'secret': true, + 'resourceType': 'function', + 'resourceId': 'myAwesomeFunction',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.createVariable( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getVariable()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'key': 'API_KEY', + 'value': 'myPa\$\$word1', + 'secret': true, + 'resourceType': 'function', + 'resourceId': 'myAwesomeFunction',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.getVariable( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateVariable()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'key': 'API_KEY', + 'value': 'myPa\$\$word1', + 'secret': true, + 'resourceType': 'function', + 'resourceId': 'myAwesomeFunction',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.updateVariable( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteVariable()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await functions.deleteVariable( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + }) diff --git a/test/services/graphql.test.js b/test/services/graphql.test.js new file mode 100644 index 00000000..3ff83bbd --- /dev/null +++ b/test/services/graphql.test.js @@ -0,0 +1,40 @@ +const { Client } = require("../../dist/client"); +const { InputFile } = require("../../dist/inputFile"); +const { Graphql } = require("../../dist/services/graphql"); + +const { fetch: mockedFetch, Response } = require("node-fetch-native-with-agent"); +jest.mock('node-fetch-native-with-agent', () => ({ ...jest.requireActual('node-fetch-native-with-agent'), fetch: jest.fn() })); + +describe('Graphql', () => { + const client = new Client(); + const graphql = new Graphql(client); + + + test('test method query()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await graphql.query( + {}, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method mutation()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await graphql.mutation( + {}, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + }) diff --git a/test/services/health.test.js b/test/services/health.test.js new file mode 100644 index 00000000..75178b52 --- /dev/null +++ b/test/services/health.test.js @@ -0,0 +1,368 @@ +const { Client } = require("../../dist/client"); +const { InputFile } = require("../../dist/inputFile"); +const { Health } = require("../../dist/services/health"); + +const { fetch: mockedFetch, Response } = require("node-fetch-native-with-agent"); +jest.mock('node-fetch-native-with-agent', () => ({ ...jest.requireActual('node-fetch-native-with-agent'), fetch: jest.fn() })); + +describe('Health', () => { + const client = new Client(); + const health = new Health(client); + + + test('test method get()', async () => { + const data = { + 'name': 'database', + 'ping': 128, + 'status': 'pass',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.get( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getAntivirus()', async () => { + const data = { + 'version': '1.0.0', + 'status': 'online',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getAntivirus( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getCache()', async () => { + const data = { + 'total': 5, + 'statuses': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getCache( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getCertificate()', async () => { + const data = { + 'name': '/CN=www.google.com', + 'subjectSN': '', + 'issuerOrganisation': '', + 'validFrom': '1704200998', + 'validTo': '1711458597', + 'signatureTypeSN': 'RSA-SHA256',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getCertificate( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getConsolePausing()', async () => { + const data = { + 'name': 'database', + 'ping': 128, + 'status': 'pass',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getConsolePausing( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getDB()', async () => { + const data = { + 'total': 5, + 'statuses': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getDB( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getPubSub()', async () => { + const data = { + 'total': 5, + 'statuses': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getPubSub( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getQueueAudits()', async () => { + const data = { + 'size': 8,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getQueueAudits( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getQueueBuilds()', async () => { + const data = { + 'size': 8,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getQueueBuilds( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getQueueCertificates()', async () => { + const data = { + 'size': 8,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getQueueCertificates( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getQueueDatabases()', async () => { + const data = { + 'size': 8,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getQueueDatabases( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getQueueDeletes()', async () => { + const data = { + 'size': 8,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getQueueDeletes( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getFailedJobs()', async () => { + const data = { + 'size': 8,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getFailedJobs( + 'v1-database', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getQueueFunctions()', async () => { + const data = { + 'size': 8,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getQueueFunctions( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getQueueLogs()', async () => { + const data = { + 'size': 8,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getQueueLogs( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getQueueMails()', async () => { + const data = { + 'size': 8,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getQueueMails( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getQueueMessaging()', async () => { + const data = { + 'size': 8,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getQueueMessaging( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getQueueMigrations()', async () => { + const data = { + 'size': 8,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getQueueMigrations( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getQueueStatsResources()', async () => { + const data = { + 'size': 8,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getQueueStatsResources( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getQueueUsage()', async () => { + const data = { + 'size': 8,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getQueueUsage( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getQueueWebhooks()', async () => { + const data = { + 'size': 8,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getQueueWebhooks( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getStorage()', async () => { + const data = { + 'name': 'database', + 'ping': 128, + 'status': 'pass',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getStorage( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getStorageLocal()', async () => { + const data = { + 'name': 'database', + 'ping': 128, + 'status': 'pass',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getStorageLocal( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getTime()', async () => { + const data = { + 'remoteTime': 1639490751, + 'localTime': 1639490844, + 'diff': 93,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await health.getTime( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + }) diff --git a/test/services/locale.test.js b/test/services/locale.test.js new file mode 100644 index 00000000..4667641d --- /dev/null +++ b/test/services/locale.test.js @@ -0,0 +1,137 @@ +const { Client } = require("../../dist/client"); +const { InputFile } = require("../../dist/inputFile"); +const { Locale } = require("../../dist/services/locale"); + +const { fetch: mockedFetch, Response } = require("node-fetch-native-with-agent"); +jest.mock('node-fetch-native-with-agent', () => ({ ...jest.requireActual('node-fetch-native-with-agent'), fetch: jest.fn() })); + +describe('Locale', () => { + const client = new Client(); + const locale = new Locale(client); + + + test('test method get()', async () => { + const data = { + 'ip': '127.0.0.1', + 'countryCode': 'US', + 'country': 'United States', + 'continentCode': 'NA', + 'continent': 'North America', + 'eu': true, + 'currency': 'USD',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await locale.get( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listCodes()', async () => { + const data = { + 'total': 5, + 'localeCodes': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await locale.listCodes( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listContinents()', async () => { + const data = { + 'total': 5, + 'continents': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await locale.listContinents( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listCountries()', async () => { + const data = { + 'total': 5, + 'countries': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await locale.listCountries( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listCountriesEU()', async () => { + const data = { + 'total': 5, + 'countries': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await locale.listCountriesEU( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listCountriesPhones()', async () => { + const data = { + 'total': 5, + 'phones': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await locale.listCountriesPhones( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listCurrencies()', async () => { + const data = { + 'total': 5, + 'currencies': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await locale.listCurrencies( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listLanguages()', async () => { + const data = { + 'total': 5, + 'languages': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await locale.listLanguages( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + }) diff --git a/test/services/messaging.test.js b/test/services/messaging.test.js new file mode 100644 index 00000000..40931583 --- /dev/null +++ b/test/services/messaging.test.js @@ -0,0 +1,1200 @@ +const { Client } = require("../../dist/client"); +const { InputFile } = require("../../dist/inputFile"); +const { Messaging } = require("../../dist/services/messaging"); + +const { fetch: mockedFetch, Response } = require("node-fetch-native-with-agent"); +jest.mock('node-fetch-native-with-agent', () => ({ ...jest.requireActual('node-fetch-native-with-agent'), fetch: jest.fn() })); + +describe('Messaging', () => { + const client = new Client(); + const messaging = new Messaging(client); + + + test('test method listMessages()', async () => { + const data = { + 'total': 5, + 'messages': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.listMessages( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createEmail()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'providerType': 'email', + 'topics': [], + 'users': [], + 'targets': [], + 'deliveredTotal': 1, + 'data': {}, + 'status': 'processing',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.createEmail( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateEmail()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'providerType': 'email', + 'topics': [], + 'users': [], + 'targets': [], + 'deliveredTotal': 1, + 'data': {}, + 'status': 'processing',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.updateEmail( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createPush()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'providerType': 'email', + 'topics': [], + 'users': [], + 'targets': [], + 'deliveredTotal': 1, + 'data': {}, + 'status': 'processing',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.createPush( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updatePush()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'providerType': 'email', + 'topics': [], + 'users': [], + 'targets': [], + 'deliveredTotal': 1, + 'data': {}, + 'status': 'processing',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.updatePush( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createSms()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'providerType': 'email', + 'topics': [], + 'users': [], + 'targets': [], + 'deliveredTotal': 1, + 'data': {}, + 'status': 'processing',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.createSms( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createSMS()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'providerType': 'email', + 'topics': [], + 'users': [], + 'targets': [], + 'deliveredTotal': 1, + 'data': {}, + 'status': 'processing',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.createSMS( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateSms()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'providerType': 'email', + 'topics': [], + 'users': [], + 'targets': [], + 'deliveredTotal': 1, + 'data': {}, + 'status': 'processing',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.updateSms( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateSMS()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'providerType': 'email', + 'topics': [], + 'users': [], + 'targets': [], + 'deliveredTotal': 1, + 'data': {}, + 'status': 'processing',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.updateSMS( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getMessage()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'providerType': 'email', + 'topics': [], + 'users': [], + 'targets': [], + 'deliveredTotal': 1, + 'data': {}, + 'status': 'processing',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.getMessage( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method delete()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.delete( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listMessageLogs()', async () => { + const data = { + 'total': 5, + 'logs': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.listMessageLogs( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listTargets()', async () => { + const data = { + 'total': 5, + 'targets': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.listTargets( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listProviders()', async () => { + const data = { + 'total': 5, + 'providers': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.listProviders( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createApnsProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.createApnsProvider( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createAPNSProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.createAPNSProvider( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateApnsProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.updateApnsProvider( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateAPNSProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.updateAPNSProvider( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createFcmProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.createFcmProvider( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createFCMProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.createFCMProvider( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateFcmProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.updateFcmProvider( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateFCMProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.updateFCMProvider( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createMailgunProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.createMailgunProvider( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateMailgunProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.updateMailgunProvider( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createMsg91Provider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.createMsg91Provider( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateMsg91Provider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.updateMsg91Provider( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createResendProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.createResendProvider( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateResendProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.updateResendProvider( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createSendgridProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.createSendgridProvider( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateSendgridProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.updateSendgridProvider( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createSmtpProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.createSmtpProvider( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createSMTPProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.createSMTPProvider( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateSmtpProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.updateSmtpProvider( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateSMTPProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.updateSMTPProvider( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createTelesignProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.createTelesignProvider( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateTelesignProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.updateTelesignProvider( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createTextmagicProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.createTextmagicProvider( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateTextmagicProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.updateTextmagicProvider( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createTwilioProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.createTwilioProvider( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateTwilioProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.updateTwilioProvider( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createVonageProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.createVonageProvider( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateVonageProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.updateVonageProvider( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getProvider()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'Mailgun', + 'provider': 'mailgun', + 'enabled': true, + 'type': 'sms', + 'credentials': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.getProvider( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteProvider()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.deleteProvider( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listProviderLogs()', async () => { + const data = { + 'total': 5, + 'logs': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.listProviderLogs( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listSubscriberLogs()', async () => { + const data = { + 'total': 5, + 'logs': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.listSubscriberLogs( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listTopics()', async () => { + const data = { + 'total': 5, + 'topics': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.listTopics( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createTopic()', async () => { + const data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'events', + 'emailTotal': 100, + 'smsTotal': 100, + 'pushTotal': 100, + 'subscribe': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.createTopic( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getTopic()', async () => { + const data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'events', + 'emailTotal': 100, + 'smsTotal': 100, + 'pushTotal': 100, + 'subscribe': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.getTopic( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateTopic()', async () => { + const data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'events', + 'emailTotal': 100, + 'smsTotal': 100, + 'pushTotal': 100, + 'subscribe': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.updateTopic( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteTopic()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.deleteTopic( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listTopicLogs()', async () => { + const data = { + 'total': 5, + 'logs': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.listTopicLogs( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listSubscribers()', async () => { + const data = { + 'total': 5, + 'subscribers': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.listSubscribers( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createSubscriber()', async () => { + const data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'targetId': '259125845563242502', + 'target': {}, + 'userId': '5e5ea5c16897e', + 'userName': 'Aegon Targaryen', + 'topicId': '259125845563242502', + 'providerType': 'email',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.createSubscriber( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getSubscriber()', async () => { + const data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'targetId': '259125845563242502', + 'target': {}, + 'userId': '5e5ea5c16897e', + 'userName': 'Aegon Targaryen', + 'topicId': '259125845563242502', + 'providerType': 'email',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.getSubscriber( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteSubscriber()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await messaging.deleteSubscriber( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + }) diff --git a/test/services/project.test.js b/test/services/project.test.js new file mode 100644 index 00000000..81c53b5e --- /dev/null +++ b/test/services/project.test.js @@ -0,0 +1,109 @@ +const { Client } = require("../../dist/client"); +const { InputFile } = require("../../dist/inputFile"); +const { Project } = require("../../dist/services/project"); + +const { fetch: mockedFetch, Response } = require("node-fetch-native-with-agent"); +jest.mock('node-fetch-native-with-agent', () => ({ ...jest.requireActual('node-fetch-native-with-agent'), fetch: jest.fn() })); + +describe('Project', () => { + const client = new Client(); + const project = new Project(client); + + + test('test method listVariables()', async () => { + const data = { + 'total': 5, + 'variables': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await project.listVariables( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createVariable()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'key': 'API_KEY', + 'value': 'myPa\$\$word1', + 'secret': true, + 'resourceType': 'function', + 'resourceId': 'myAwesomeFunction',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await project.createVariable( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getVariable()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'key': 'API_KEY', + 'value': 'myPa\$\$word1', + 'secret': true, + 'resourceType': 'function', + 'resourceId': 'myAwesomeFunction',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await project.getVariable( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateVariable()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'key': 'API_KEY', + 'value': 'myPa\$\$word1', + 'secret': true, + 'resourceType': 'function', + 'resourceId': 'myAwesomeFunction',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await project.updateVariable( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteVariable()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await project.deleteVariable( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + }) diff --git a/test/services/sites.test.js b/test/services/sites.test.js new file mode 100644 index 00000000..75f88054 --- /dev/null +++ b/test/services/sites.test.js @@ -0,0 +1,729 @@ +const { Client } = require("../../dist/client"); +const { InputFile } = require("../../dist/inputFile"); +const { Sites } = require("../../dist/services/sites"); + +const { fetch: mockedFetch, Response } = require("node-fetch-native-with-agent"); +jest.mock('node-fetch-native-with-agent', () => ({ ...jest.requireActual('node-fetch-native-with-agent'), fetch: jest.fn() })); + +describe('Sites', () => { + const client = new Client(); + const sites = new Sites(client); + + + test('test method list()', async () => { + const data = { + 'total': 5, + 'sites': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.list( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method create()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'My Site', + 'enabled': true, + 'live': true, + 'logging': true, + 'framework': 'react', + 'deploymentRetention': 7, + 'deploymentId': '5e5ea5c16897e', + 'deploymentCreatedAt': '2020-10-15T06:38:00.000+00:00', + 'deploymentScreenshotLight': '5e5ea5c16897e', + 'deploymentScreenshotDark': '5e5ea5c16897e', + 'latestDeploymentId': '5e5ea5c16897e', + 'latestDeploymentCreatedAt': '2020-10-15T06:38:00.000+00:00', + 'latestDeploymentStatus': 'ready', + 'vars': [], + 'timeout': 300, + 'installCommand': 'npm install', + 'buildCommand': 'npm run build', + 'startCommand': 'node custom-server.mjs', + 'outputDirectory': 'build', + 'installationId': '6m40at4ejk5h2u9s1hboo', + 'providerRepositoryId': 'appwrite', + 'providerBranch': 'main', + 'providerRootDirectory': 'sites/helloWorld', + 'providerSilentMode': true, + 'buildSpecification': 's-1vcpu-512mb', + 'runtimeSpecification': 's-1vcpu-512mb', + 'buildRuntime': 'node-22', + 'adapter': 'static', + 'fallbackFile': 'index.html',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.create( + '', + '', + 'analog', + 'node-14.5', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listFrameworks()', async () => { + const data = { + 'total': 5, + 'frameworks': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.listFrameworks( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listSpecifications()', async () => { + const data = { + 'total': 5, + 'specifications': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.listSpecifications( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method get()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'My Site', + 'enabled': true, + 'live': true, + 'logging': true, + 'framework': 'react', + 'deploymentRetention': 7, + 'deploymentId': '5e5ea5c16897e', + 'deploymentCreatedAt': '2020-10-15T06:38:00.000+00:00', + 'deploymentScreenshotLight': '5e5ea5c16897e', + 'deploymentScreenshotDark': '5e5ea5c16897e', + 'latestDeploymentId': '5e5ea5c16897e', + 'latestDeploymentCreatedAt': '2020-10-15T06:38:00.000+00:00', + 'latestDeploymentStatus': 'ready', + 'vars': [], + 'timeout': 300, + 'installCommand': 'npm install', + 'buildCommand': 'npm run build', + 'startCommand': 'node custom-server.mjs', + 'outputDirectory': 'build', + 'installationId': '6m40at4ejk5h2u9s1hboo', + 'providerRepositoryId': 'appwrite', + 'providerBranch': 'main', + 'providerRootDirectory': 'sites/helloWorld', + 'providerSilentMode': true, + 'buildSpecification': 's-1vcpu-512mb', + 'runtimeSpecification': 's-1vcpu-512mb', + 'buildRuntime': 'node-22', + 'adapter': 'static', + 'fallbackFile': 'index.html',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.get( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method update()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'My Site', + 'enabled': true, + 'live': true, + 'logging': true, + 'framework': 'react', + 'deploymentRetention': 7, + 'deploymentId': '5e5ea5c16897e', + 'deploymentCreatedAt': '2020-10-15T06:38:00.000+00:00', + 'deploymentScreenshotLight': '5e5ea5c16897e', + 'deploymentScreenshotDark': '5e5ea5c16897e', + 'latestDeploymentId': '5e5ea5c16897e', + 'latestDeploymentCreatedAt': '2020-10-15T06:38:00.000+00:00', + 'latestDeploymentStatus': 'ready', + 'vars': [], + 'timeout': 300, + 'installCommand': 'npm install', + 'buildCommand': 'npm run build', + 'startCommand': 'node custom-server.mjs', + 'outputDirectory': 'build', + 'installationId': '6m40at4ejk5h2u9s1hboo', + 'providerRepositoryId': 'appwrite', + 'providerBranch': 'main', + 'providerRootDirectory': 'sites/helloWorld', + 'providerSilentMode': true, + 'buildSpecification': 's-1vcpu-512mb', + 'runtimeSpecification': 's-1vcpu-512mb', + 'buildRuntime': 'node-22', + 'adapter': 'static', + 'fallbackFile': 'index.html',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.update( + '', + '', + 'analog', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method delete()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.delete( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateSiteDeployment()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'My Site', + 'enabled': true, + 'live': true, + 'logging': true, + 'framework': 'react', + 'deploymentRetention': 7, + 'deploymentId': '5e5ea5c16897e', + 'deploymentCreatedAt': '2020-10-15T06:38:00.000+00:00', + 'deploymentScreenshotLight': '5e5ea5c16897e', + 'deploymentScreenshotDark': '5e5ea5c16897e', + 'latestDeploymentId': '5e5ea5c16897e', + 'latestDeploymentCreatedAt': '2020-10-15T06:38:00.000+00:00', + 'latestDeploymentStatus': 'ready', + 'vars': [], + 'timeout': 300, + 'installCommand': 'npm install', + 'buildCommand': 'npm run build', + 'startCommand': 'node custom-server.mjs', + 'outputDirectory': 'build', + 'installationId': '6m40at4ejk5h2u9s1hboo', + 'providerRepositoryId': 'appwrite', + 'providerBranch': 'main', + 'providerRootDirectory': 'sites/helloWorld', + 'providerSilentMode': true, + 'buildSpecification': 's-1vcpu-512mb', + 'runtimeSpecification': 's-1vcpu-512mb', + 'buildRuntime': 'node-22', + 'adapter': 'static', + 'fallbackFile': 'index.html',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.updateSiteDeployment( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listDeployments()', async () => { + const data = { + 'total': 5, + 'deployments': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.listDeployments( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createDeployment()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'type': 'vcs', + 'resourceId': '5e5ea6g16897e', + 'resourceType': 'functions', + 'entrypoint': 'index.js', + 'sourceSize': 128, + 'buildSize': 128, + 'totalSize': 128, + 'buildId': '5e5ea5c16897e', + 'activate': true, + 'screenshotLight': '5e5ea5c16897e', + 'screenshotDark': '5e5ea5c16897e', + 'status': 'ready', + 'buildLogs': 'Compiling source files...', + 'buildDuration': 128, + 'providerRepositoryName': 'database', + 'providerRepositoryOwner': 'utopia', + 'providerRepositoryUrl': 'https://github.com/vermakhushboo/g4-node-function', + 'providerCommitHash': '7c3f25d', + 'providerCommitAuthorUrl': 'https://github.com/vermakhushboo', + 'providerCommitAuthor': 'Khushboo Verma', + 'providerCommitMessage': 'Update index.js', + 'providerCommitUrl': 'https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb', + 'providerBranch': '0.7.x', + 'providerBranchUrl': 'https://github.com/vermakhushboo/appwrite/tree/0.7.x',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.createDeployment( + '', + InputFile.fromBuffer(new Uint8Array(0), 'image.png'), + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createDuplicateDeployment()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'type': 'vcs', + 'resourceId': '5e5ea6g16897e', + 'resourceType': 'functions', + 'entrypoint': 'index.js', + 'sourceSize': 128, + 'buildSize': 128, + 'totalSize': 128, + 'buildId': '5e5ea5c16897e', + 'activate': true, + 'screenshotLight': '5e5ea5c16897e', + 'screenshotDark': '5e5ea5c16897e', + 'status': 'ready', + 'buildLogs': 'Compiling source files...', + 'buildDuration': 128, + 'providerRepositoryName': 'database', + 'providerRepositoryOwner': 'utopia', + 'providerRepositoryUrl': 'https://github.com/vermakhushboo/g4-node-function', + 'providerCommitHash': '7c3f25d', + 'providerCommitAuthorUrl': 'https://github.com/vermakhushboo', + 'providerCommitAuthor': 'Khushboo Verma', + 'providerCommitMessage': 'Update index.js', + 'providerCommitUrl': 'https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb', + 'providerBranch': '0.7.x', + 'providerBranchUrl': 'https://github.com/vermakhushboo/appwrite/tree/0.7.x',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.createDuplicateDeployment( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createTemplateDeployment()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'type': 'vcs', + 'resourceId': '5e5ea6g16897e', + 'resourceType': 'functions', + 'entrypoint': 'index.js', + 'sourceSize': 128, + 'buildSize': 128, + 'totalSize': 128, + 'buildId': '5e5ea5c16897e', + 'activate': true, + 'screenshotLight': '5e5ea5c16897e', + 'screenshotDark': '5e5ea5c16897e', + 'status': 'ready', + 'buildLogs': 'Compiling source files...', + 'buildDuration': 128, + 'providerRepositoryName': 'database', + 'providerRepositoryOwner': 'utopia', + 'providerRepositoryUrl': 'https://github.com/vermakhushboo/g4-node-function', + 'providerCommitHash': '7c3f25d', + 'providerCommitAuthorUrl': 'https://github.com/vermakhushboo', + 'providerCommitAuthor': 'Khushboo Verma', + 'providerCommitMessage': 'Update index.js', + 'providerCommitUrl': 'https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb', + 'providerBranch': '0.7.x', + 'providerBranchUrl': 'https://github.com/vermakhushboo/appwrite/tree/0.7.x',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.createTemplateDeployment( + '', + '', + '', + '', + 'branch', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createVcsDeployment()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'type': 'vcs', + 'resourceId': '5e5ea6g16897e', + 'resourceType': 'functions', + 'entrypoint': 'index.js', + 'sourceSize': 128, + 'buildSize': 128, + 'totalSize': 128, + 'buildId': '5e5ea5c16897e', + 'activate': true, + 'screenshotLight': '5e5ea5c16897e', + 'screenshotDark': '5e5ea5c16897e', + 'status': 'ready', + 'buildLogs': 'Compiling source files...', + 'buildDuration': 128, + 'providerRepositoryName': 'database', + 'providerRepositoryOwner': 'utopia', + 'providerRepositoryUrl': 'https://github.com/vermakhushboo/g4-node-function', + 'providerCommitHash': '7c3f25d', + 'providerCommitAuthorUrl': 'https://github.com/vermakhushboo', + 'providerCommitAuthor': 'Khushboo Verma', + 'providerCommitMessage': 'Update index.js', + 'providerCommitUrl': 'https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb', + 'providerBranch': '0.7.x', + 'providerBranchUrl': 'https://github.com/vermakhushboo/appwrite/tree/0.7.x',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.createVcsDeployment( + '', + 'branch', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getDeployment()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'type': 'vcs', + 'resourceId': '5e5ea6g16897e', + 'resourceType': 'functions', + 'entrypoint': 'index.js', + 'sourceSize': 128, + 'buildSize': 128, + 'totalSize': 128, + 'buildId': '5e5ea5c16897e', + 'activate': true, + 'screenshotLight': '5e5ea5c16897e', + 'screenshotDark': '5e5ea5c16897e', + 'status': 'ready', + 'buildLogs': 'Compiling source files...', + 'buildDuration': 128, + 'providerRepositoryName': 'database', + 'providerRepositoryOwner': 'utopia', + 'providerRepositoryUrl': 'https://github.com/vermakhushboo/g4-node-function', + 'providerCommitHash': '7c3f25d', + 'providerCommitAuthorUrl': 'https://github.com/vermakhushboo', + 'providerCommitAuthor': 'Khushboo Verma', + 'providerCommitMessage': 'Update index.js', + 'providerCommitUrl': 'https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb', + 'providerBranch': '0.7.x', + 'providerBranchUrl': 'https://github.com/vermakhushboo/appwrite/tree/0.7.x',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.getDeployment( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteDeployment()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.deleteDeployment( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getDeploymentDownload()', async () => { + const data = new ArrayBuffer(0); + mockedFetch.mockImplementation(() => new Response(data)); + + const response = await sites.getDeploymentDownload( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateDeploymentStatus()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'type': 'vcs', + 'resourceId': '5e5ea6g16897e', + 'resourceType': 'functions', + 'entrypoint': 'index.js', + 'sourceSize': 128, + 'buildSize': 128, + 'totalSize': 128, + 'buildId': '5e5ea5c16897e', + 'activate': true, + 'screenshotLight': '5e5ea5c16897e', + 'screenshotDark': '5e5ea5c16897e', + 'status': 'ready', + 'buildLogs': 'Compiling source files...', + 'buildDuration': 128, + 'providerRepositoryName': 'database', + 'providerRepositoryOwner': 'utopia', + 'providerRepositoryUrl': 'https://github.com/vermakhushboo/g4-node-function', + 'providerCommitHash': '7c3f25d', + 'providerCommitAuthorUrl': 'https://github.com/vermakhushboo', + 'providerCommitAuthor': 'Khushboo Verma', + 'providerCommitMessage': 'Update index.js', + 'providerCommitUrl': 'https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb', + 'providerBranch': '0.7.x', + 'providerBranchUrl': 'https://github.com/vermakhushboo/appwrite/tree/0.7.x',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.updateDeploymentStatus( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listLogs()', async () => { + const data = { + 'total': 5, + 'executions': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.listLogs( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getLog()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'functionId': '5e5ea6g16897e', + 'deploymentId': '5e5ea5c16897e', + 'trigger': 'http', + 'status': 'processing', + 'requestMethod': 'GET', + 'requestPath': '/articles?id=5', + 'requestHeaders': [], + 'responseStatusCode': 200, + 'responseBody': '', + 'responseHeaders': [], + 'logs': '', + 'errors': '', + 'duration': 0.4,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.getLog( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteLog()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.deleteLog( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listVariables()', async () => { + const data = { + 'total': 5, + 'variables': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.listVariables( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createVariable()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'key': 'API_KEY', + 'value': 'myPa\$\$word1', + 'secret': true, + 'resourceType': 'function', + 'resourceId': 'myAwesomeFunction',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.createVariable( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getVariable()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'key': 'API_KEY', + 'value': 'myPa\$\$word1', + 'secret': true, + 'resourceType': 'function', + 'resourceId': 'myAwesomeFunction',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.getVariable( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateVariable()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'key': 'API_KEY', + 'value': 'myPa\$\$word1', + 'secret': true, + 'resourceType': 'function', + 'resourceId': 'myAwesomeFunction',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.updateVariable( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteVariable()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await sites.deleteVariable( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + }) diff --git a/test/services/storage.test.js b/test/services/storage.test.js new file mode 100644 index 00000000..43f5d0c7 --- /dev/null +++ b/test/services/storage.test.js @@ -0,0 +1,288 @@ +const { Client } = require("../../dist/client"); +const { InputFile } = require("../../dist/inputFile"); +const { Storage } = require("../../dist/services/storage"); + +const { fetch: mockedFetch, Response } = require("node-fetch-native-with-agent"); +jest.mock('node-fetch-native-with-agent', () => ({ ...jest.requireActual('node-fetch-native-with-agent'), fetch: jest.fn() })); + +describe('Storage', () => { + const client = new Client(); + const storage = new Storage(client); + + + test('test method listBuckets()', async () => { + const data = { + 'total': 5, + 'buckets': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await storage.listBuckets( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createBucket()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'fileSecurity': true, + 'name': 'Documents', + 'enabled': true, + 'maximumFileSize': 100, + 'allowedFileExtensions': [], + 'compression': 'gzip', + 'encryption': true, + 'antivirus': true, + 'transformations': true, + 'totalSize': 128,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await storage.createBucket( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getBucket()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'fileSecurity': true, + 'name': 'Documents', + 'enabled': true, + 'maximumFileSize': 100, + 'allowedFileExtensions': [], + 'compression': 'gzip', + 'encryption': true, + 'antivirus': true, + 'transformations': true, + 'totalSize': 128,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await storage.getBucket( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateBucket()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'fileSecurity': true, + 'name': 'Documents', + 'enabled': true, + 'maximumFileSize': 100, + 'allowedFileExtensions': [], + 'compression': 'gzip', + 'encryption': true, + 'antivirus': true, + 'transformations': true, + 'totalSize': 128,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await storage.updateBucket( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteBucket()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await storage.deleteBucket( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listFiles()', async () => { + const data = { + 'total': 5, + 'files': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await storage.listFiles( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createFile()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + 'bucketId': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'name': 'Pink.png', + 'signature': '5d529fd02b544198ae075bd57c1762bb', + 'mimeType': 'image/png', + 'sizeOriginal': 17890, + 'chunksTotal': 17890, + 'chunksUploaded': 17890, + 'encryption': true, + 'compression': 'gzip',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await storage.createFile( + '', + '', + InputFile.fromBuffer(new Uint8Array(0), 'image.png'), + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getFile()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + 'bucketId': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'name': 'Pink.png', + 'signature': '5d529fd02b544198ae075bd57c1762bb', + 'mimeType': 'image/png', + 'sizeOriginal': 17890, + 'chunksTotal': 17890, + 'chunksUploaded': 17890, + 'encryption': true, + 'compression': 'gzip',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await storage.getFile( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateFile()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + 'bucketId': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'name': 'Pink.png', + 'signature': '5d529fd02b544198ae075bd57c1762bb', + 'mimeType': 'image/png', + 'sizeOriginal': 17890, + 'chunksTotal': 17890, + 'chunksUploaded': 17890, + 'encryption': true, + 'compression': 'gzip',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await storage.updateFile( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteFile()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await storage.deleteFile( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getFileDownload()', async () => { + const data = new ArrayBuffer(0); + mockedFetch.mockImplementation(() => new Response(data)); + + const response = await storage.getFileDownload( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getFilePreview()', async () => { + const data = new ArrayBuffer(0); + mockedFetch.mockImplementation(() => new Response(data)); + + const response = await storage.getFilePreview( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getFileView()', async () => { + const data = new ArrayBuffer(0); + mockedFetch.mockImplementation(() => new Response(data)); + + const response = await storage.getFileView( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + }) diff --git a/test/services/tables-d-b.test.js b/test/services/tables-d-b.test.js new file mode 100644 index 00000000..8b475203 --- /dev/null +++ b/test/services/tables-d-b.test.js @@ -0,0 +1,1574 @@ +const { Client } = require("../../dist/client"); +const { InputFile } = require("../../dist/inputFile"); +const { TablesDB } = require("../../dist/services/tables-db"); + +const { fetch: mockedFetch, Response } = require("node-fetch-native-with-agent"); +jest.mock('node-fetch-native-with-agent', () => ({ ...jest.requireActual('node-fetch-native-with-agent'), fetch: jest.fn() })); + +describe('TablesDB', () => { + const client = new Client(); + const tablesDB = new TablesDB(client); + + + test('test method list()', async () => { + const data = { + 'total': 5, + 'databases': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.list( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method create()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + 'name': 'My Database', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'enabled': true, + 'type': 'legacy', + 'policies': [], + 'archives': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.create( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listTransactions()', async () => { + const data = { + 'total': 5, + 'transactions': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.listTransactions( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createTransaction()', async () => { + const data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'status': 'pending', + 'operations': 5, + 'expiresAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createTransaction( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getTransaction()', async () => { + const data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'status': 'pending', + 'operations': 5, + 'expiresAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.getTransaction( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateTransaction()', async () => { + const data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'status': 'pending', + 'operations': 5, + 'expiresAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.updateTransaction( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteTransaction()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.deleteTransaction( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createOperations()', async () => { + const data = { + '\$id': '259125845563242502', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'status': 'pending', + 'operations': 5, + 'expiresAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createOperations( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method get()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + 'name': 'My Database', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'enabled': true, + 'type': 'legacy', + 'policies': [], + 'archives': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.get( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method update()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + 'name': 'My Database', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'enabled': true, + 'type': 'legacy', + 'policies': [], + 'archives': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.update( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method delete()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.delete( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listTables()', async () => { + const data = { + 'total': 5, + 'tables': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.listTables( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createTable()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'databaseId': '5e5ea5c16897e', + 'name': 'My Table', + 'enabled': true, + 'rowSecurity': true, + 'columns': [], + 'indexes': [], + 'bytesMax': 65535, + 'bytesUsed': 1500,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createTable( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getTable()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'databaseId': '5e5ea5c16897e', + 'name': 'My Table', + 'enabled': true, + 'rowSecurity': true, + 'columns': [], + 'indexes': [], + 'bytesMax': 65535, + 'bytesUsed': 1500,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.getTable( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateTable()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'databaseId': '5e5ea5c16897e', + 'name': 'My Table', + 'enabled': true, + 'rowSecurity': true, + 'columns': [], + 'indexes': [], + 'bytesMax': 65535, + 'bytesUsed': 1500,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.updateTable( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteTable()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.deleteTable( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listColumns()', async () => { + const data = { + 'total': 5, + 'columns': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.listColumns( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createBooleanColumn()', async () => { + const data = { + 'key': 'isEnabled', + 'type': 'boolean', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createBooleanColumn( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateBooleanColumn()', async () => { + const data = { + 'key': 'isEnabled', + 'type': 'boolean', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.updateBooleanColumn( + '', + '', + '', + true, + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createDatetimeColumn()', async () => { + const data = { + 'key': 'birthDay', + 'type': 'datetime', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'format': 'datetime',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createDatetimeColumn( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateDatetimeColumn()', async () => { + const data = { + 'key': 'birthDay', + 'type': 'datetime', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'format': 'datetime',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.updateDatetimeColumn( + '', + '', + '', + true, + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createEmailColumn()', async () => { + const data = { + 'key': 'userEmail', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'format': 'email',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createEmailColumn( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateEmailColumn()', async () => { + const data = { + 'key': 'userEmail', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'format': 'email',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.updateEmailColumn( + '', + '', + '', + true, + 'email@example.com', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createEnumColumn()', async () => { + const data = { + 'key': 'status', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'elements': [], + 'format': 'enum',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createEnumColumn( + '', + '', + '', + [], + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateEnumColumn()', async () => { + const data = { + 'key': 'status', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'elements': [], + 'format': 'enum',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.updateEnumColumn( + '', + '', + '', + [], + true, + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createFloatColumn()', async () => { + const data = { + 'key': 'percentageCompleted', + 'type': 'double', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createFloatColumn( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateFloatColumn()', async () => { + const data = { + 'key': 'percentageCompleted', + 'type': 'double', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.updateFloatColumn( + '', + '', + '', + true, + 1.0, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createIntegerColumn()', async () => { + const data = { + 'key': 'count', + 'type': 'integer', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createIntegerColumn( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateIntegerColumn()', async () => { + const data = { + 'key': 'count', + 'type': 'integer', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.updateIntegerColumn( + '', + '', + '', + true, + 1, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createIpColumn()', async () => { + const data = { + 'key': 'ipAddress', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'format': 'ip',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createIpColumn( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateIpColumn()', async () => { + const data = { + 'key': 'ipAddress', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'format': 'ip',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.updateIpColumn( + '', + '', + '', + true, + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createLineColumn()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createLineColumn( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateLineColumn()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.updateLineColumn( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createLongtextColumn()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createLongtextColumn( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateLongtextColumn()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.updateLongtextColumn( + '', + '', + '', + true, + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createMediumtextColumn()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createMediumtextColumn( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateMediumtextColumn()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.updateMediumtextColumn( + '', + '', + '', + true, + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createPointColumn()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createPointColumn( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updatePointColumn()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.updatePointColumn( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createPolygonColumn()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createPolygonColumn( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updatePolygonColumn()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.updatePolygonColumn( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createRelationshipColumn()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'relatedTable': 'table', + 'relationType': 'oneToOne|oneToMany|manyToOne|manyToMany', + 'twoWay': true, + 'twoWayKey': 'string', + 'onDelete': 'restrict|cascade|setNull', + 'side': 'parent|child',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createRelationshipColumn( + '', + '', + '', + 'oneToOne', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createStringColumn()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'size': 128,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createStringColumn( + '', + '', + '', + 1, + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateStringColumn()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'size': 128,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.updateStringColumn( + '', + '', + '', + true, + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createTextColumn()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createTextColumn( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateTextColumn()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.updateTextColumn( + '', + '', + '', + true, + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createUrlColumn()', async () => { + const data = { + 'key': 'githubUrl', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'format': 'url',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createUrlColumn( + '', + '', + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateUrlColumn()', async () => { + const data = { + 'key': 'githubUrl', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'format': 'url',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.updateUrlColumn( + '', + '', + '', + true, + 'https://example.com', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createVarcharColumn()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'size': 128,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createVarcharColumn( + '', + '', + '', + 1, + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateVarcharColumn()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'size': 128,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.updateVarcharColumn( + '', + '', + '', + true, + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getColumn()', async () => { + const data = { + 'key': 'isEnabled', + 'type': 'boolean', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.getColumn( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteColumn()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.deleteColumn( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateRelationshipColumn()', async () => { + const data = { + 'key': 'fullName', + 'type': 'string', + 'status': 'available', + 'error': 'string', + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'relatedTable': 'table', + 'relationType': 'oneToOne|oneToMany|manyToOne|manyToMany', + 'twoWay': true, + 'twoWayKey': 'string', + 'onDelete': 'restrict|cascade|setNull', + 'side': 'parent|child',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.updateRelationshipColumn( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listIndexes()', async () => { + const data = { + 'total': 5, + 'indexes': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.listIndexes( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createIndex()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'key': 'index1', + 'type': 'primary', + 'status': 'available', + 'error': 'string', + 'columns': [], + 'lengths': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createIndex( + '', + '', + '', + 'key', + [], + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getIndex()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'key': 'index1', + 'type': 'primary', + 'status': 'available', + 'error': 'string', + 'columns': [], + 'lengths': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.getIndex( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteIndex()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.deleteIndex( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listRows()', async () => { + const data = { + 'total': 5, + 'rows': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.listRows( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createRow()', async () => { + const 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': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createRow( + '', + '', + '', + {}, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createRows()', async () => { + const data = { + 'total': 5, + 'rows': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.createRows( + '', + '', + [], + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method upsertRows()', async () => { + const data = { + 'total': 5, + 'rows': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.upsertRows( + '', + '', + [], + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateRows()', async () => { + const data = { + 'total': 5, + 'rows': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.updateRows( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteRows()', async () => { + const data = { + 'total': 5, + 'rows': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.deleteRows( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getRow()', async () => { + const 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': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.getRow( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method upsertRow()', async () => { + const 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': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.upsertRow( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateRow()', async () => { + const 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': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.updateRow( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteRow()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.deleteRow( + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method decrementRowColumn()', async () => { + const 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': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.decrementRowColumn( + '', + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method incrementRowColumn()', async () => { + const 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': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tablesDB.incrementRowColumn( + '', + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + }) diff --git a/test/services/teams.test.js b/test/services/teams.test.js new file mode 100644 index 00000000..df5c9ac1 --- /dev/null +++ b/test/services/teams.test.js @@ -0,0 +1,278 @@ +const { Client } = require("../../dist/client"); +const { InputFile } = require("../../dist/inputFile"); +const { Teams } = require("../../dist/services/teams"); + +const { fetch: mockedFetch, Response } = require("node-fetch-native-with-agent"); +jest.mock('node-fetch-native-with-agent', () => ({ ...jest.requireActual('node-fetch-native-with-agent'), fetch: jest.fn() })); + +describe('Teams', () => { + const client = new Client(); + const teams = new Teams(client); + + + test('test method list()', async () => { + const data = { + 'total': 5, + 'teams': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await teams.list( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method create()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'VIP', + 'total': 7, + 'prefs': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await teams.create( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method get()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'VIP', + 'total': 7, + 'prefs': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await teams.get( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateName()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'VIP', + 'total': 7, + 'prefs': {},}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await teams.updateName( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method delete()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await teams.delete( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listMemberships()', async () => { + const data = { + 'total': 5, + 'memberships': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await teams.listMemberships( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createMembership()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c16897e', + 'userName': 'John Doe', + 'userEmail': 'john@appwrite.io', + 'teamId': '5e5ea5c16897e', + 'teamName': 'VIP', + 'invited': '2020-10-15T06:38:00.000+00:00', + 'joined': '2020-10-15T06:38:00.000+00:00', + 'confirm': true, + 'mfa': true, + 'roles': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await teams.createMembership( + '', + [], + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getMembership()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c16897e', + 'userName': 'John Doe', + 'userEmail': 'john@appwrite.io', + 'teamId': '5e5ea5c16897e', + 'teamName': 'VIP', + 'invited': '2020-10-15T06:38:00.000+00:00', + 'joined': '2020-10-15T06:38:00.000+00:00', + 'confirm': true, + 'mfa': true, + 'roles': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await teams.getMembership( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateMembership()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c16897e', + 'userName': 'John Doe', + 'userEmail': 'john@appwrite.io', + 'teamId': '5e5ea5c16897e', + 'teamName': 'VIP', + 'invited': '2020-10-15T06:38:00.000+00:00', + 'joined': '2020-10-15T06:38:00.000+00:00', + 'confirm': true, + 'mfa': true, + 'roles': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await teams.updateMembership( + '', + '', + [], + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteMembership()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await teams.deleteMembership( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateMembershipStatus()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c16897e', + 'userName': 'John Doe', + 'userEmail': 'john@appwrite.io', + 'teamId': '5e5ea5c16897e', + 'teamName': 'VIP', + 'invited': '2020-10-15T06:38:00.000+00:00', + 'joined': '2020-10-15T06:38:00.000+00:00', + 'confirm': true, + 'mfa': true, + 'roles': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await teams.updateMembershipStatus( + '', + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getPrefs()', async () => { + const data = {}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await teams.getPrefs( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updatePrefs()', async () => { + const data = {}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await teams.updatePrefs( + '', + {}, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + }) diff --git a/test/services/tokens.test.js b/test/services/tokens.test.js new file mode 100644 index 00000000..b9c14cb4 --- /dev/null +++ b/test/services/tokens.test.js @@ -0,0 +1,107 @@ +const { Client } = require("../../dist/client"); +const { InputFile } = require("../../dist/inputFile"); +const { Tokens } = require("../../dist/services/tokens"); + +const { fetch: mockedFetch, Response } = require("node-fetch-native-with-agent"); +jest.mock('node-fetch-native-with-agent', () => ({ ...jest.requireActual('node-fetch-native-with-agent'), fetch: jest.fn() })); + +describe('Tokens', () => { + const client = new Client(); + const tokens = new Tokens(client); + + + test('test method list()', async () => { + const data = { + 'total': 5, + 'tokens': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tokens.list( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createFileToken()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'resourceId': '5e5ea5c168bb8:5e5ea5c168bb8', + 'resourceType': 'files', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'secret': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c', + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tokens.createFileToken( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method get()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'resourceId': '5e5ea5c168bb8:5e5ea5c168bb8', + 'resourceType': 'files', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'secret': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c', + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tokens.get( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method update()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'resourceId': '5e5ea5c168bb8:5e5ea5c168bb8', + 'resourceType': 'files', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'secret': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c', + 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tokens.update( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method delete()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await tokens.delete( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + }) diff --git a/test/services/users.test.js b/test/services/users.test.js new file mode 100644 index 00000000..c01295da --- /dev/null +++ b/test/services/users.test.js @@ -0,0 +1,1145 @@ +const { Client } = require("../../dist/client"); +const { InputFile } = require("../../dist/inputFile"); +const { Users } = require("../../dist/services/users"); + +const { fetch: mockedFetch, Response } = require("node-fetch-native-with-agent"); +jest.mock('node-fetch-native-with-agent', () => ({ ...jest.requireActual('node-fetch-native-with-agent'), fetch: jest.fn() })); + +describe('Users', () => { + const client = new Client(); + const users = new Users(client); + + + test('test method list()', async () => { + const data = { + 'total': 5, + 'users': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.list( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method create()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.create( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createArgon2User()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.createArgon2User( + '', + 'email@example.com', + 'password', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createBcryptUser()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.createBcryptUser( + '', + 'email@example.com', + 'password', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listIdentities()', async () => { + const data = { + 'total': 5, + 'identities': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.listIdentities( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteIdentity()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.deleteIdentity( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createMD5User()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.createMD5User( + '', + 'email@example.com', + 'password', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createPHPassUser()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.createPHPassUser( + '', + 'email@example.com', + 'password', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createScryptUser()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.createScryptUser( + '', + 'email@example.com', + 'password', + '', + 1, + 1, + 1, + 1, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createScryptModifiedUser()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.createScryptModifiedUser( + '', + 'email@example.com', + 'password', + '', + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createSHAUser()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.createSHAUser( + '', + 'email@example.com', + 'password', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method get()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.get( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method delete()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.delete( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateEmail()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.updateEmail( + '', + 'email@example.com', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateImpersonator()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.updateImpersonator( + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createJWT()', async () => { + const data = { + 'jwt': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.createJWT( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateLabels()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.updateLabels( + '', + [], + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listLogs()', async () => { + const data = { + 'total': 5, + 'logs': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.listLogs( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listMemberships()', async () => { + const data = { + 'total': 5, + 'memberships': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.listMemberships( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateMfa()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.updateMfa( + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateMFA()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.updateMFA( + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteMfaAuthenticator()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.deleteMfaAuthenticator( + '', + 'totp', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteMFAAuthenticator()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.deleteMFAAuthenticator( + '', + 'totp', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listMfaFactors()', async () => { + const data = { + 'totp': true, + 'phone': true, + 'email': true, + 'recoveryCode': true,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.listMfaFactors( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listMFAFactors()', async () => { + const data = { + 'totp': true, + 'phone': true, + 'email': true, + 'recoveryCode': true,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.listMFAFactors( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getMfaRecoveryCodes()', async () => { + const data = { + 'recoveryCodes': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.getMfaRecoveryCodes( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getMFARecoveryCodes()', async () => { + const data = { + 'recoveryCodes': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.getMFARecoveryCodes( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateMfaRecoveryCodes()', async () => { + const data = { + 'recoveryCodes': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.updateMfaRecoveryCodes( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateMFARecoveryCodes()', async () => { + const data = { + 'recoveryCodes': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.updateMFARecoveryCodes( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createMfaRecoveryCodes()', async () => { + const data = { + 'recoveryCodes': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.createMfaRecoveryCodes( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createMFARecoveryCodes()', async () => { + const data = { + 'recoveryCodes': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.createMFARecoveryCodes( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateName()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.updateName( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updatePassword()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.updatePassword( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updatePhone()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.updatePhone( + '', + '+12065550100', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getPrefs()', async () => { + const data = {}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.getPrefs( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updatePrefs()', async () => { + const data = {}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.updatePrefs( + '', + {}, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listSessions()', async () => { + const data = { + 'total': 5, + 'sessions': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.listSessions( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createSession()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.createSession( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteSessions()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.deleteSessions( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteSession()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.deleteSession( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateStatus()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.updateStatus( + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method listTargets()', async () => { + const data = { + 'total': 5, + 'targets': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.listTargets( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createTarget()', async () => { + const data = { + '\$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,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.createTarget( + '', + '', + 'email', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method getTarget()', async () => { + const data = { + '\$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,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.getTarget( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateTarget()', async () => { + const data = { + '\$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,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.updateTarget( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method deleteTarget()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.deleteTarget( + '', + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method createToken()', async () => { + const data = { + '\$id': 'bb8ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5ea5c168bb8', + 'secret': '', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'phrase': 'Golden Fox',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.createToken( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateEmailVerification()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.updateEmailVerification( + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updatePhoneVerification()', async () => { + const 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',}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await users.updatePhoneVerification( + '', + true, + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + }) diff --git a/test/services/webhooks.test.js b/test/services/webhooks.test.js new file mode 100644 index 00000000..642b4a73 --- /dev/null +++ b/test/services/webhooks.test.js @@ -0,0 +1,155 @@ +const { Client } = require("../../dist/client"); +const { InputFile } = require("../../dist/inputFile"); +const { Webhooks } = require("../../dist/services/webhooks"); + +const { fetch: mockedFetch, Response } = require("node-fetch-native-with-agent"); +jest.mock('node-fetch-native-with-agent', () => ({ ...jest.requireActual('node-fetch-native-with-agent'), fetch: jest.fn() })); + +describe('Webhooks', () => { + const client = new Client(); + const webhooks = new Webhooks(client); + + + test('test method list()', async () => { + const data = { + 'total': 5, + 'webhooks': [],}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await webhooks.list( + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method create()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'My Webhook', + 'url': 'https://example.com/webhook', + 'events': [], + 'security': true, + 'httpUser': 'username', + 'httpPass': 'password', + 'signatureKey': 'ad3d581ca230e2b7059c545e5a', + 'enabled': true, + 'logs': 'Failed to connect to remote server.', + 'attempts': 10,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await webhooks.create( + '', + '', + '', + [], + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method get()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'My Webhook', + 'url': 'https://example.com/webhook', + 'events': [], + 'security': true, + 'httpUser': 'username', + 'httpPass': 'password', + 'signatureKey': 'ad3d581ca230e2b7059c545e5a', + 'enabled': true, + 'logs': 'Failed to connect to remote server.', + 'attempts': 10,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await webhooks.get( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method update()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'My Webhook', + 'url': 'https://example.com/webhook', + 'events': [], + 'security': true, + 'httpUser': 'username', + 'httpPass': 'password', + 'signatureKey': 'ad3d581ca230e2b7059c545e5a', + 'enabled': true, + 'logs': 'Failed to connect to remote server.', + 'attempts': 10,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await webhooks.update( + '', + '', + '', + [], + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method delete()', async () => { + const data = {message: ""}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await webhooks.delete( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + + test('test method updateSignature()', async () => { + const data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'My Webhook', + 'url': 'https://example.com/webhook', + 'events': [], + 'security': true, + 'httpUser': 'username', + 'httpPass': 'password', + 'signatureKey': 'ad3d581ca230e2b7059c545e5a', + 'enabled': true, + 'logs': 'Failed to connect to remote server.', + 'attempts': 10,}; + mockedFetch.mockImplementation(() => Response.json(data)); + + const response = await webhooks.updateSignature( + '', + ); + + // Remove custom toString method on the objects to allow for clean data comparison. + delete response.toString; + + expect(response).toEqual(data); + }); + })