From 7c6dcd1831ac83a06eda849c701e2221b801f2ba Mon Sep 17 00:00:00 2001 From: wambui-pixel <80099068+wambui-pixel@users.noreply.github.com> Date: Tue, 26 Nov 2024 13:17:24 +0300 Subject: [PATCH] NOISSUE - Rename things to clients (#108) * rename things to clients Signed-off-by: wambuipixel * fix: replace console log with console error Signed-off-by: wambuipixel * add changeset Signed-off-by: wambuipixel * fix: add tests Signed-off-by: wambuipixel * fix: address requested changes Signed-off-by: wambuipixel --------- Signed-off-by: wambuipixel --- .changeset/lazy-windows-hammer.md | 5 + examples/bootstrap.ts | 38 ++--- examples/certs.ts | 16 +- examples/invitations.ts | 12 +- examples/messages.ts | 10 +- examples/users.ts | 44 ++--- src/bootstrap.ts | 257 ++++++++++++++---------------- src/certs.ts | 117 ++++++-------- src/defs.ts | 2 +- src/messages.ts | 46 +++--- src/sdk.ts | 2 +- tests/bootstrap.test.ts | 34 ++-- tests/invitations.test.ts | 12 +- tests/messages.test.ts | 8 +- tests/roles.test.ts | 28 ++-- tests/users.test.ts | 44 ++--- 16 files changed, 321 insertions(+), 354 deletions(-) create mode 100644 .changeset/lazy-windows-hammer.md diff --git a/.changeset/lazy-windows-hammer.md b/.changeset/lazy-windows-hammer.md new file mode 100644 index 0000000..d8df200 --- /dev/null +++ b/.changeset/lazy-windows-hammer.md @@ -0,0 +1,5 @@ +--- +"@absmach/magistrala-sdk": patch +--- + +rename things to clients diff --git a/examples/bootstrap.ts b/examples/bootstrap.ts index ad83194..97d4d67 100644 --- a/examples/bootstrap.ts +++ b/examples/bootstrap.ts @@ -13,7 +13,7 @@ mySdk.bootstrap.AddBootstrap( { external_id: "", external_key: "externalKey", - thing_id: "", + client_id: "", name: "", }, domainId, @@ -23,14 +23,14 @@ mySdk.bootstrap.AddBootstrap( console.log("response:", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.bootstrap.Whitelist( { external_id: "", external_key: "", - thing_id: "", + client_id: "", name: "", }, domainId, @@ -40,13 +40,13 @@ mySdk.bootstrap.Whitelist( console.log("response:", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.bootstrap.UpdateBootstrap( { - name: "Bootstrap1", - thing_id: "", + name: "", + client_id: "", }, domainId, token, @@ -55,11 +55,11 @@ mySdk.bootstrap.UpdateBootstrap( console.log("response:", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.bootstrap.ViewBootstrap( - "", + "", domainId, token, ) @@ -67,12 +67,12 @@ mySdk.bootstrap.ViewBootstrap( console.log("response:", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.bootstrap.UpdateBootstrapCerts( { - thing_id: "", + client_id: "", client_cert: "", client_key: "", ca_cert: "", @@ -84,11 +84,11 @@ mySdk.bootstrap.UpdateBootstrapCerts( console.log("response:", response); }) .catch((error) => { - console.log(error); + console.error(error); }); -mySdk.bootstrap.RemoveBootstrap( - "", +mySdk.bootstrap.DeleteBootstrap( + "", domainId, token, ) @@ -96,7 +96,7 @@ mySdk.bootstrap.RemoveBootstrap( console.log("response:", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.bootstrap.Bootstrap( @@ -107,7 +107,7 @@ mySdk.bootstrap.Bootstrap( console.log("response:", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.bootstrap.Bootstraps( @@ -119,11 +119,11 @@ mySdk.bootstrap.Bootstraps( console.log("response:", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.bootstrap.UpdateBootstrapConnection( - "", + "", domainId, ["", ""], token, @@ -132,7 +132,7 @@ mySdk.bootstrap.UpdateBootstrapConnection( console.log("response:", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.bootstrap.SecureBootstrap( @@ -144,5 +144,5 @@ mySdk.bootstrap.SecureBootstrap( console.log("response:", response); }) .catch((error) => { - console.log(error); + console.error(error); }); diff --git a/examples/certs.ts b/examples/certs.ts index 84a1735..c1f3e20 100644 --- a/examples/certs.ts +++ b/examples/certs.ts @@ -11,7 +11,7 @@ const domainId = ""; mySdk.certs .IssueCert( - "", + "", "", domainId, token, @@ -20,12 +20,12 @@ mySdk.certs console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.certs - .ViewCertByThing( - "", + .ViewCertByClient( + "", domainId, token, ) @@ -33,7 +33,7 @@ mySdk.certs console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.certs @@ -46,12 +46,12 @@ mySdk.certs console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.certs .RevokeCert( - "", + "", domainId, token, ) @@ -59,5 +59,5 @@ mySdk.certs console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); diff --git a/examples/invitations.ts b/examples/invitations.ts index c9c307e..c3122d2 100644 --- a/examples/invitations.ts +++ b/examples/invitations.ts @@ -23,7 +23,7 @@ mySdk.invitations.SendInvitation( console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.invitations.Invitation( @@ -35,7 +35,7 @@ mySdk.invitations.Invitation( console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.invitations.Invitations( @@ -49,7 +49,7 @@ mySdk.invitations.Invitations( console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.invitations.AcceptInvitation( @@ -60,7 +60,7 @@ mySdk.invitations.AcceptInvitation( console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.invitations.RejectInvitation( @@ -71,7 +71,7 @@ mySdk.invitations.RejectInvitation( console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.invitations.DeleteInvitation( @@ -83,5 +83,5 @@ mySdk.invitations.DeleteInvitation( console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); diff --git a/examples/messages.ts b/examples/messages.ts index 4936749..14e569d 100644 --- a/examples/messages.ts +++ b/examples/messages.ts @@ -10,12 +10,12 @@ const mySdk = new SDK({ const token = ""; mySdk.messages - .Send("", "", "") + .Send("", "", "") .then((response: any) => { console.log("response: ", response); }) - .catch((error: unknown) => { - console.log(error); + .catch((error) => { + console.error(error); }); mySdk.messages @@ -23,6 +23,6 @@ mySdk.messages .then((response: any) => { console.log("response: ", response); }) - .catch((error: unknown) => { - console.log(error); + .catch((error) => { + console.error(error); }); diff --git a/examples/users.ts b/examples/users.ts index 720c909..5d8a9bb 100644 --- a/examples/users.ts +++ b/examples/users.ts @@ -22,7 +22,7 @@ mySdk.users console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.users @@ -31,7 +31,7 @@ mySdk.users console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.users @@ -40,7 +40,7 @@ mySdk.users console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.users @@ -49,7 +49,7 @@ mySdk.users console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.users @@ -58,7 +58,7 @@ mySdk.users console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.users @@ -70,7 +70,7 @@ mySdk.users console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.users @@ -79,7 +79,7 @@ mySdk.users console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.users @@ -91,7 +91,7 @@ mySdk.users console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.users @@ -103,7 +103,7 @@ mySdk.users console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.users @@ -112,7 +112,7 @@ mySdk.users console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.users @@ -121,7 +121,7 @@ mySdk.users console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.users @@ -130,7 +130,7 @@ mySdk.users console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.users @@ -139,7 +139,7 @@ mySdk.users console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.users @@ -148,7 +148,7 @@ mySdk.users console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.users @@ -157,7 +157,7 @@ mySdk.users console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.users @@ -166,7 +166,7 @@ mySdk.users console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.users.ListUserClients( @@ -179,7 +179,7 @@ mySdk.users.ListUserClients( console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.users @@ -188,7 +188,7 @@ mySdk.users console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.users @@ -197,7 +197,7 @@ mySdk.users console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.users @@ -206,7 +206,7 @@ mySdk.users console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.users @@ -215,7 +215,7 @@ mySdk.users console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); mySdk.users @@ -224,5 +224,5 @@ mySdk.users console.log("response: ", response); }) .catch((error) => { - console.log(error); + console.error(error); }); diff --git a/src/bootstrap.ts b/src/bootstrap.ts index fc858aa..3e75b3f 100644 --- a/src/bootstrap.ts +++ b/src/bootstrap.ts @@ -8,19 +8,11 @@ import { type Response, } from "./defs"; +/** +* @class Bootstrap +* Handles interactions with bootstrap API including creating, updating and managing bootstrap configurations. +*/ export default class Bootstrap { - // Bootstraps API Client - /** - * @class Bootstrap - * Bootstrap is used to create, update, view and remove bootstrap configurations. - * @param {string} bootstraps_url - The url of the bootstraps service. - * @param {string} content_type - The content type of the request. - * @param {string} bootstrapEndpoint - The endpoint of the bootstraps service which is - * configs. - * @returns {Bootstrap} - Returns a Bootstrap object. - * - */ - private readonly bootstrapUrl: URL; private readonly contentType: string; @@ -37,43 +29,43 @@ export default class Bootstrap { private readonly secureEndpoint: string; + /** + * @constructor + * Initializes the Bootstrap API client. + * @param {object} config - Configuration object. + * @param {string} config.bootstrapUrl - Base URL for the bootstrap API. + */ public constructor(bootstrapUrl: string) { this.bootstrapUrl = new URL(bootstrapUrl); this.contentType = "application/json"; - this.bootstrapEndpoint = "things/bootstrap"; - this.configsEndpoint = "things/configs"; - this.whitelistEndpoint = "things/state"; - this.bootstrapCertsEndpoint = "things/configs/certs"; - this.bootstrapConnEndpoint = "things/configs/connections"; + this.bootstrapEndpoint = "clients/bootstrap"; + this.configsEndpoint = "clients/configs"; + this.whitelistEndpoint = "clients/state"; + this.bootstrapCertsEndpoint = "clients/configs/certs"; + this.bootstrapConnEndpoint = "clients/configs/connections"; this.secureEndpoint = "secure"; } + /** + * @method AddBootstrap - Creates a new bootstrap configuration. + * @param {BootstrapConfig} bootstrapConfig - The bootstrap configuration object containing details like external key, channels, externalId, clientId, etc. + * @param {string} domainId - The unique ID of the domain. + * @param {string} token - Authorization token. + * @returns {Promise} response - A promise that resolves when the bootstrap configuration is created. + * @throws {Error} - If the bootstrap configuration cannot be created. + */ public async AddBootstrap( - bootstrap: BootstrapConfig, + bootstrapConfig: BootstrapConfig, domainId: string, token: string ): Promise { - // Create a bootstrap configuration - /** - * @method Create - Create a new bootstrap configuration. - * @param {object} config - The configuration object. - * @param {string} domainId - The Domain ID. - * @param {string} token - Authentication Token. - * @example - * const config = { - * "external_id": "345", - * "external_key": "012", - * "thing_id": "3d49a42f-63fd-491b-9784-adf4b64ef347", - * } - */ - const options: RequestInit = { method: "POST", headers: { "Content-Type": this.contentType, Authorization: `Bearer ${token}`, }, - body: JSON.stringify(bootstrap), + body: JSON.stringify(bootstrapConfig), }; try { const response = await fetch( @@ -97,38 +89,31 @@ export default class Bootstrap { } } + /** + * @method Whitelist - Updates a bootstrap configuration and changes the status of the config to whitelisted. + * @param {BootstrapConfig} bootstrapConfig - The bootstrap configuration object containing details like external key, channels, externalId, clientId, etc. + * @param {string} domainId - The unique ID of the domain. + * @param {string} token - Authorization token. + * @returns {Promise} response - A promise that resolves when the bootstrap configuration is whitelisted. + * @throws {Error} - If the bootstrap configuration cannot be whitelisted. + */ public async Whitelist( - bootstrap: BootstrapConfig, + bootstrapConfig: BootstrapConfig, domainId: string, token: string ): Promise { - // Update a bootstrap configuration - /** - * @method Whitelist - Allows a logged in user to update a bootstrap configuration. - * This changes the status of the config to whitelisted. - * @param {object} config - The configuration object. - * @param {string} domainId - The Domain ID. - * @param {string} token - Authentication Token. - * @example - * const config = { - * "external_id": "345", - * "external_key": "012", - * "thing_id": "3d49a42f-63fd-491b-9784-adf4b64ef347", - * "name": "thing_name" - * } - */ const options: RequestInit = { method: "PUT", headers: { "Content-Type": this.contentType, Authorization: `Bearer ${token}`, }, - body: JSON.stringify({ state: bootstrap.state }), + body: JSON.stringify({ state: bootstrapConfig.state }), }; try { const response = await fetch( new URL( - `${domainId}/${this.whitelistEndpoint}/${bootstrap.client_id}`, + `${domainId}/${this.whitelistEndpoint}/${bootstrapConfig.client_id}`, this.bootstrapUrl ).toString(), options @@ -147,38 +132,31 @@ export default class Bootstrap { } } + /** + * @method UpdateBootstrap - Updates an existing bootstrap configuration's details. + * @param {BootstrapConfig} bootstrapConfig - The bootstrap configuration object containing details like external key, channels, externalId, clientId, etc. + * @param {string} domainId - The unique ID of the domain. + * @param {string} token - Authorization token. + * @returns {Promise} response - A promise that resolves when the bootstrap configuration is updated. + * @throws {Error} - If the bootstrap configuration cannot be updated. + */ public async UpdateBootstrap( - bootstrap: BootstrapConfig, + bootstrapConfig: BootstrapConfig, domainId: string, token: string ): Promise { - // Update a bootstrap configuration - /** - * @method Update - Allows a logged in user to update a bootstrap configuration. - * This can change the name of the config and metadata. - * @param {object} config - The configuration object. - * @param {string} domainId - The Domain ID. - * @param {string} token - The token to be used for authentication. - * @example - * const config = { - * "external_id": "345", - * "external_key": "012", - * "thing_id": "3d49a42f-63fd-491b-9784-adf4b64ef347", - * "name": "thing_name" - * } - */ const options = { method: "PUT", headers: { "Content-Type": this.contentType, Authorization: `Bearer ${token}`, }, - body: JSON.stringify(bootstrap), + body: JSON.stringify(bootstrapConfig), }; try { const response = await fetch( new URL( - `${domainId}/${this.configsEndpoint}/${bootstrap.client_id}`, + `${domainId}/${this.configsEndpoint}/${bootstrapConfig.client_id}`, this.bootstrapUrl ).toString(), options @@ -197,20 +175,20 @@ export default class Bootstrap { } } + /** + * @method ViewBootstrap - Retrieves a bootstrap config by its ID. + * @param {string} clientId - The unique identifier of the client. + * @param {string} domainId - The unique ID of the domain. + * @param {string} token - Authorization token. + * @returns {Promise} bootstrapConfig - The requested bootstrap configuration object. + * @throws {Error} - If the bootstrap configuration cannot be fetched. + */ + public async ViewBootstrap( - thingId: string, + clientId: string, domainId: string, token: string ): Promise { - // View a bootstrap configuration - /** - * @method View - Allows a logged in user to view a bootstrap configuration. - * Once provided with the thingId and a valid token, it returns the configuration object. - * @param {string} thingId - The thingId of the configuration to be viewed. - * @param {string} domainId - The Domain ID. - * @param {string} token - Authentication Token. - */ - const options = { method: "GET", headers: { @@ -221,7 +199,7 @@ export default class Bootstrap { try { const response = await fetch( new URL( - `${domainId}/${this.configsEndpoint}/${thingId}`, + `${domainId}/${this.configsEndpoint}/${clientId}`, this.bootstrapUrl ).toString(), options @@ -230,42 +208,38 @@ export default class Bootstrap { const errorRes = await response.json(); throw Errors.HandleError(errorRes.message, response.status); } - const bootstrap: BootstrapConfig = await response.json(); - return bootstrap; + const bootstrapConfig: BootstrapConfig = await response.json(); + return bootstrapConfig; } catch (error) { throw error; } } + /** + * @method UpdateBootstrapCerts - Updates the details of a specific role in a domain. + * @param {BootstrapConfig} bootstrapConfig - The bootstrap configuration object containing details like external key, channels, externalId, clientId, etc. + * @param {string} domainId - The unique ID of the domain. + * @param {string} token - Authorization token. + * @returns {Promise} bootstrapConfig - The updated bootstrap configuration. + * @throws {Error} - If the certs cannot be updated. + */ public async UpdateBootstrapCerts( - configs: BootstrapConfig, + bootstrapConfig: BootstrapConfig, domainId: string, token: string ): Promise { - // Update certs of a bootstrap configuration - /** - * @method UpdateCerts - Allows a logged in user to update the certs of a bootstrap configuration. - * Update is performed by replacing the current certificate data with values provided in a request payload. - * @param {string} configId - The config_id of the configuration to be updated. This can also mean the thing_id. - * @param {string} client_cert - The client certificate to be used. - * @param {string} client_key - The client key to be used. - * @param {string} ca - The certificate authority to be used. - * @param {string} domainId - The Domain ID. - * @param {string} token - Authentication Token. - * - */ const options: RequestInit = { method: "PATCH", headers: { "Content-Type": this.contentType, Authorization: `Bearer ${token}`, }, - body: JSON.stringify(configs), + body: JSON.stringify(bootstrapConfig), }; try { const response = await fetch( new URL( - `${domainId}/${this.bootstrapCertsEndpoint}/${configs.client_id}`, + `${domainId}/${this.bootstrapCertsEndpoint}/${bootstrapConfig.client_id}`, this.bootstrapUrl ).toString(), options @@ -274,26 +248,26 @@ export default class Bootstrap { const errorRes = await response.json(); throw Errors.HandleError(errorRes.message, response.status); } - const updatedBootstrap: BootstrapConfig = await response.json(); - return updatedBootstrap; + const updatedBootstrapConfig: BootstrapConfig = await response.json(); + return updatedBootstrapConfig; } catch (error) { throw error; } } - public async RemoveBootstrap( - thingId: string, + /** + * @method DeleteBootstrap - Deletes bootstrap configuration with specified id. + * @param {string} clientId - The unique ID of the client. + * @param {string} domainId - The unique ID of the domain. + * @param {string} token - Authorization token. + * @returns {Promise} response - A promise that resolves when the bootstrap configuration is deleted. + * @throws {Error} - If the bootstrap configuration cannot be deleted. + */ + public async DeleteBootstrap( + clientId: string, domainId: string, token: string ): Promise { - // Remove a bootstrap configuration - /** - * @method Remove - Allows a logged in user to delete a bootstrap configuration. - * @param {string} configId - The config ID of the configuration to be deleted. - * This can also mean the thing ID. - * @param {string} domainId - The Domain ID. - * @param {string} token - Authentication Token. - */ const options: RequestInit = { method: "DELETE", headers: { @@ -304,7 +278,7 @@ export default class Bootstrap { try { const response = await fetch( new URL( - `${domainId}/${this.configsEndpoint}/${thingId}`, + `${domainId}/${this.configsEndpoint}/${clientId}`, this.bootstrapUrl ).toString(), options @@ -323,22 +297,22 @@ export default class Bootstrap { } } + /** + * @method Bootstrap - Retrieves a configuration with given external ID and encrypted external key. + * @param {string} externalId - The external ID of the configuration to be retrieved. + * @param {string} externalKey - The encrypted external key of the configuration to be retrieved. + * @return {Promise} bootstrapConfig - Returns the requested bootstrap configuration. + * @throws {Error} - If the bootstrap configuration cannot be retrieved. + */ public async Bootstrap( externalId: string, externalKey: string ): Promise { - // Retrive a bootstrap configuration - /** - * @method Bootstrap - Retrieves a configuration with given external ID and encrypted external key. - * @param {string} external_id - The external ID of the configuration to be retrieved. - * @param {string} external_key - The encrypted external key of the configuration to be retrieved. - * @return {object} - Returns a Bootstrap Configuration. - */ const options: RequestInit = { method: "GET", headers: { "Content-Type": this.contentType, - Authorization: `Thing ${externalKey}`, + Authorization: `Client ${externalKey}`, }, }; try { @@ -360,19 +334,19 @@ export default class Bootstrap { } } + /** + * @method Bootstraps -Retrieves all bootstrap configuration matching the provided query parameters. + * @param {PageMetadata} queryParams - Query parameters for the request. + * @param {string} domainId -The unique ID of the domain. + * @param {String} token - Authorization token. + * @returns {Promise} bootstrapPage - A page of bootstrap configurations. + * @throws {Error} - If the bootstrap configurations cannot be fetched. + */ public async Bootstraps( queryParams: PageMetadata, domainId: string, token: string ): Promise { - // Retrive all bootstraps with pagination - /** - * @method Bootstraps - Gets all bootstraps with pagination. - * @param {Object} queryParams - Query parameters. - * @param {string} domainId - The Domain ID. - * @param {String} token - Authentication token. - * @returns {Object} - Bootstrap Page. - */ const stringParams: Record = Object.fromEntries( Object.entries(queryParams).map(([key, value]) => [key, String(value)]) ); @@ -405,20 +379,21 @@ export default class Bootstrap { } } + /** + * @method UpdateBootstrapConnection - Updates the connection of a bootstrap configuration. + * @param {string} clientId - The unique identifier of the client. + * @param {string[]} channels - An array of unique channels ids to be updated. + * @param {string} domainId - The unique ID of the domain. + * @param {string} token - Authorization token. + * @returns {Promise} response - A promise that resolves when the bootstrap configuration connection are updated. + * @throws {Error} - If the bootstrap configuration cannot be updated. + */ public async UpdateBootstrapConnection( - thingId: string, + clientId: string, domainId: string, channels: string[], token: string ): Promise { - // Update a bootstrap connection - /** - * @method UpdateConnection - Allows a logged in user to update the connection of a bootstrap configuration. - * @param {string} thing_id - The thing_id of the configuration to be updated. - * @param {object} channels - The channels object to be used for the update. - * @param {string} domainId - The Domain ID. - * @param {string} token - The token to be used for authentication. - * */ const options: RequestInit = { method: "PUT", headers: { @@ -430,7 +405,7 @@ export default class Bootstrap { try { const response = await fetch( new URL( - `${domainId}/${this.bootstrapConnEndpoint}/${thingId}`, + `${domainId}/${this.bootstrapConnEndpoint}/${clientId}`, this.bootstrapUrl ).toString(), options @@ -449,6 +424,14 @@ export default class Bootstrap { } } + /** + * @method SecureBootstrap - Secures a bootstrap configuration by encrypting it. + * @param {string} externalId - The unique external ID of the bootstrap configuration. + * @param {string[]} externalKey - The unique external key of the bootstrap configuration. + * @param {string} cryptoKey -The unique crypto key to be used to secure the bootstrap configuration. + * @returns {Promise} - bootstrapConfig - Returns the secured bootstrap configuration. + * @throws {Error} - If the bootstrap configuration cannot be scured. + */ public async SecureBootstrap( externalId: string, externalKey: string, @@ -462,7 +445,7 @@ export default class Bootstrap { method: "GET", headers: { "Content-Type": this.contentType, - Authorization: `Thing ${encryptedKey}`, + Authorization: `Client ${encryptedKey}`, }, }; try { diff --git a/src/certs.ts b/src/certs.ts index 3647240..7ff744f 100644 --- a/src/certs.ts +++ b/src/certs.ts @@ -1,17 +1,11 @@ import Errors from "./errors"; -import { type Cert, type CertSerials, type Response } from "./defs"; +import { type Cert, CertsPage, type Response } from "./defs"; +/** +*@class Certs +* Handles interactions with certs API, including issuing, viewing, revoking certificates and manage certificates. +*/ export default class Certs { - // Certs API Client - /** - *@class Certs - Certs is used to manage certificates. - *It is used to issue, view and revoke certificates. - * @param {string} certsUrl - The url of the certs service. - * @param {string} contentType - The content type of the request. - * @param {string} certsEndpoint - The endpoint of the certs service which is certs. - * @returns {Certs} - Returns a Certs object. - */ - private readonly certsUrl: URL; private readonly contentType: string; @@ -24,36 +18,28 @@ export default class Certs { this.certsEndpoint = "certs"; } + /** + * @method IssueCert - Issues a certificate to a client. + * @param {string} clientId - The unique ID of the client to be issued a certificate. + * @param {string} valid - The time in hours for which the certificate is valid such as '10h' + * @param {string} domainId - The unique ID of the domain. + * @param {string} token - Authorization token. + * @returns {Promise} cert - A promise that resolves with the certificate issued. + * @throws {Error} - If the certificate cannot be issued. + */ public async IssueCert( - thingID: string, + clientId: string, valid: string, domainId: string, token: string ): Promise { - // Issue a certificate - /** - * @method IssueCert - Issue a certificate to a thing. - * Requires a thingID and a valid time in hours as well as a token. - * @param {string} thingID - The thingID of the thing to be issued a certificate. - * @param {string} valid - The time in hours for which the certificate is valid such as '10h' - * @param {string} domainId - The Domain ID. - * @param {String} token - Access token. - * @example - * const certs = { - * "cert_serial": "22:16:df:60:c2:99:bc:c4:9b:1d:fd:71:5e:e9:07:d9:1b:3c:85:1d", - * "client_cert": "-----BEGIN CERTIFICATE-----\nMIIEATCCAumgAwIBAgIUIhbfYMKZvMSbHf1xXukH2Rs8hR0wDQYJKoZIhvcNAQEL1k\n-----END CERTIFICATE-----", - * "client_key": "-----BEGIN RSA PRIVATE KEY-----\nMIIEoQIBAAKCAQEAy9gF84a5s6jlX6hkAPXrLYqvdhe6uygdr6eHfd5erdcdxfgc\n-----END RSA PRIVATE KEY-----", - * "expiration": "2023-09-20T10:02:48Z", - * "thingID": "3d49a42f-63fd-491b-9784-adf4b64ef347" - * } - */ const options: RequestInit = { method: "POST", headers: { "Content-Type": this.contentType, Authorization: `Bearer ${token}`, }, - body: JSON.stringify({ thing_id: thingID, ttl: valid }), + body: JSON.stringify({ client_id: clientId, ttl: valid }), }; try { @@ -72,21 +58,19 @@ export default class Certs { } } - public async ViewCertByThing( - thingID: string, + /** + * @method ViewCertByClient - Retrieves all certs matching the provided client Id. + * @param {string} clientId - The unique ID of the client. + * @param {string} domainId - The unique ID of the domain. + * @param {string} token - Authorization token. + * @returns {Promise} certsPage - A page of certs. + * @throws {Error} - If the certs cannot be fetched. + */ + public async ViewCertByClient( + clientId: string, domainId: string, token: string - ): Promise { - // View certificates by thingID - /** - * @method ViewCertByThing - Allows a logged in user to view a certificate serial once they - * provide a valid connected thing-id and token. - * @param {string} thingID - The thingID of the thing whose certificate is to be viewed. - * @param {string} domainId - The Domain ID. - * @param {string} token - The token to be used for authentication. - * - */ - + ): Promise { const options: RequestInit = { method: "GET", headers: { @@ -96,35 +80,33 @@ export default class Certs { }; try { const response = await fetch( - new URL(`${domainId}/serials/${thingID}`, this.certsUrl).toString(), + new URL(`${domainId}/serials/${clientId}`, this.certsUrl).toString(), options ); if (!response.ok) { const errorRes = await response.json(); throw Errors.HandleError(errorRes.message, response.status); } - const certsPage: CertSerials = await response.json(); + const certsPage: CertsPage = await response.json(); return certsPage; } catch (error) { throw error; } } + /** + * @method ViewCert - Retrieves a certificate by its id. + * @param {string} certId - The unique ID of the certificate. + * @param {string} domainId - The unique ID of the domain. + * @param {string} token - Authorization token. + * @returns {Promise} cert - The requested cert object. + * @throws {Error} - If the cert cannot be fetched. + */ public async ViewCert( - id: string, + certId: string, domainId: string, token: string ): Promise { - // View certificate by certID - /** - * @method ViewCert - Allows a logged in user to view a certificate once they - * provide a valid cert-id and token. - * @param {string} id - The ID of the certificate to be viewed. - * @param {string} domainId - The Domain ID. - * @param {string} token - The token to be used for authentication. - * - */ - const options: RequestInit = { method: "GET", headers: { @@ -136,7 +118,7 @@ export default class Certs { try { const response = await fetch( new URL( - `${domainId}/${this.certsEndpoint}/${id}`, + `${domainId}/${this.certsEndpoint}/${certId}`, this.certsUrl ).toString(), options @@ -152,20 +134,19 @@ export default class Certs { } } + /** + * @method RevokeCert - Revokes and deletes a certificate with specified id. + * @param {string} certId - The unique ID of the certificate to be revoked. + * @param {string} domainId - The unique ID of the domain. + * @param {string} token - Authorization token. + * @returns {Promise} response - A promise that resolves when the cert is revoked. + * @throws {Error} - If the cert cannot be revoked. + */ public async RevokeCert( - id: string, + certId: string, domainId: string, token: string ): Promise { - // Revoke a certificate - /** - * @method RevokeCert - Allows a logged in user to delete a certificate once they - * provide a valid thing-id and token. - * @param {string} id - The id of the certificate to be revoked. - * @param {string} domainId - The Domain ID. - * @param {string} token - The token to be used for authentication. - */ - const options: RequestInit = { method: "DELETE", headers: { @@ -177,7 +158,7 @@ export default class Certs { try { const response = await fetch( new URL( - `${domainId}/${this.certsEndpoint}/${id}`, + `${domainId}/${this.certsEndpoint}/${certId}`, this.certsUrl ).toString(), options diff --git a/src/defs.ts b/src/defs.ts index f392c7a..f21e04a 100644 --- a/src/defs.ts +++ b/src/defs.ts @@ -291,7 +291,7 @@ export interface Cert { expiration?: string; } -export interface CertSerials { +export interface CertsPage { certs: Cert[]; total: number; offset: number; diff --git a/src/messages.ts b/src/messages.ts index 22fedb7..7b23ab9 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -35,23 +35,21 @@ export default class Messages { this.contentType = "application/json"; } + /** + * @method Send- Sends message to a given Channel via HTTP adapter. The client and Channel must exist and the client connected to the Channel. + * @param {string} channelId - The ID of the Channel to send the message to. + * @param {string} msg - Message to send to the Channel that should be in encoded into + * bytes format for example: + * [{"bn":"demo", "bu":"V", "n":"voltage", "u":"V", "v":5}] + * @param {string} clientKey - The secret of the client sending the message. + * @returns {Promise} response - A promise that resolves when the message is sent. + * @throws {Error} - If the message cannot be sent. + */ public async Send( channelId: string, msg: string, - thingKey: string + clientKey: string ): Promise { - // Send a message - /** - * @method Send- Sends message to a given Channel via HTTP adapter. Message is sent - * through a writer add-on such as Timescale. Message is sent to the - * HTTP adapter. The Thing and Channel must exist and the Thing connected to the Channel. - * @param {string} channel_id - The ID of the Channel to send the message to. - * @param {string} msg -message to send to the Channel that should be in encoded into - * bytes format for example: - * [{"bn":"demo", "bu":"V", "n":"voltage", "u":"V", "v":5}] - * @param {string} thing_key - The secret of the Thing sending the message. - */ - const chanNameParts = channelId.split(".", 2); const chanId = chanNameParts[0]; let subtopic = ""; @@ -64,7 +62,7 @@ export default class Messages { method: "POST", headers: { "Content-Type": this.contentType, - Authorization: `Thing ${thingKey}`, + Authorization: `client ${clientKey}`, }, body: msg, }; @@ -90,22 +88,22 @@ export default class Messages { } } + /** + * + * @method Read - Read messages from a given channel. + * @param {MessagesPageMetadata} queryParams - Query parameters for the request. + * @param {string} channelId - The ID of the channel to read the message from. + * @param {string} token - Authorization token. + * @param {string} domainId - The unique ID of the domain. + * @returns {Promise} messagesPage - A page of messages. + * @throws {Error} - If the messages cannot be fetched. + */ public async Read( pm: MessagesPageMetadata, channelId: string, token: string, domainId: string ): Promise { - // Read messages - /** - * - * @method Read - Read messages from a given channel. Messages are read from a reader - * add-on such as Timescale. Messages are read from the http adapter. - * @param {string} channel_id - The ID of the channel to read the message from. - * @param {string} token - Authentication token. - * @param {string} domain_id - The ID of the domain. - */ - const stringParams: Record = Object.fromEntries( Object.entries(pm).map(([key, value]) => [key, String(value)]) ); diff --git a/src/sdk.ts b/src/sdk.ts index 909b8d1..48ac668 100644 --- a/src/sdk.ts +++ b/src/sdk.ts @@ -32,7 +32,7 @@ export type { Domain, DomainsPage, Cert, - CertSerials, + CertsPage, Invitation, InvitationsPage, Relation, diff --git a/tests/bootstrap.test.ts b/tests/bootstrap.test.ts index e4e82bd..0117a76 100644 --- a/tests/bootstrap.test.ts +++ b/tests/bootstrap.test.ts @@ -29,7 +29,7 @@ describe("Bootstraps", () => { "bb7edb32-2eac-4aad-aebe-ed96fe073879", "bb7edb32-2eac-4aad-aebe-ed96fe073879", ]; - const thingId = "77cbb344-7c41-47f3-a53a-a3d435b67207"; + const clientId = "77cbb344-7c41-47f3-a53a-a3d435b67207"; const token = "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9"; const domainId = "886b4266-77d1-4258-abae-2931fb4f16de"; const externalKey = "key"; @@ -39,7 +39,7 @@ describe("Bootstraps", () => { fetchMock.resetMocks(); }); - test("AddBootstrap should create a Bootstrap Configuration and return success", async () => { + test("Add bootstrap should create a bootstrap configuration", async () => { const createResponse = { status: 200, message: "Bootstrap configuration created", @@ -54,7 +54,7 @@ describe("Bootstraps", () => { expect(response).toEqual(createResponse); }); - test("Whitelist should allow a user to update a Bootstrap Configuration and return success", async () => { + test("Whitelist should whitelist a bootstrap configuration", async () => { const whitelistResponse = { status: 200, message: "Bootstrap configuration state updated successfully", @@ -65,7 +65,7 @@ describe("Bootstraps", () => { expect(response).toEqual(whitelistResponse); }); - test("UpdateBootstrap should allow a user to update a Bootstrap Configuration and return success", async () => { + test("Update bootstrap should update a bootstrap configuration", async () => { const updateResponse = { status: 200, message: "Bootstrap configuration updated successfully", @@ -80,18 +80,18 @@ describe("Bootstraps", () => { expect(response).toEqual(updateResponse); }); - test("ViewBootstrap should allow a user to view a Bootstrap Configuration and return success", async () => { + test("View bootstrap should view a bootstrap configuration", async () => { fetchMock.mockResponseOnce(JSON.stringify(bootstrap)); const response = await sdk.bootstrap.ViewBootstrap( - thingId, + clientId, domainId, token, ); expect(response).toEqual(bootstrap); }); - test("UpdateBootstrapCerts should update certs of a bootstrap configuration and return success", async () => { + test("Update bootstrap certs should update certs of a bootstrap configuration", async () => { fetchMock.mockResponseOnce(JSON.stringify(bootstrap)); const response = await sdk.bootstrap.UpdateBootstrapCerts( @@ -102,29 +102,29 @@ describe("Bootstraps", () => { expect(response).toEqual(bootstrap); }); - test("RemoveBootstrap should allow a user to view a Bootstrap Configuration and return success", async () => { - const removeResponse = { + test("Delete bootstrap should delete a bootstrap configuration", async () => { + const deleteResponse = { status: 200, message: "Bootstrap configuration deleted", }; - fetchMock.mockResponseOnce(JSON.stringify(removeResponse)); + fetchMock.mockResponseOnce(JSON.stringify(deleteResponse)); - const response = await sdk.bootstrap.RemoveBootstrap( - thingId, + const response = await sdk.bootstrap.DeleteBootstrap( + clientId, domainId, token, ); - expect(response).toEqual(removeResponse); + expect(response).toEqual(deleteResponse); }); - test("Bootstrap should retrive a Bootstrap Configuration and return success", async () => { + test("Bootstrap should retrieve a bootstrap configuration", async () => { fetchMock.mockResponseOnce(JSON.stringify(bootstrap)); const response = await sdk.bootstrap.Bootstrap(externalId, externalKey); expect(response).toEqual(bootstrap); }); - test("Bootstraps should retrive all bootstraps and return success", async () => { + test("Bootstraps should retrieve all bootstraps", async () => { fetchMock.mockResponseOnce(JSON.stringify(bootstrapPage)); const response = await sdk.bootstrap.Bootstraps( @@ -135,7 +135,7 @@ describe("Bootstraps", () => { expect(response).toEqual(bootstrapPage); }); - test("UpdateBootstrapConnection should retrive all bootstraps and return success", async () => { + test("Update bootstrap connection update bootstrap connection", async () => { const connResponse = { status: 200, message: "Bootstrap connection successful", @@ -143,7 +143,7 @@ describe("Bootstraps", () => { fetchMock.mockResponseOnce(JSON.stringify(connResponse)); const response = await sdk.bootstrap.UpdateBootstrapConnection( - thingId, + clientId, domainId, channels, token, diff --git a/tests/invitations.test.ts b/tests/invitations.test.ts index 32f2424..4cc6131 100644 --- a/tests/invitations.test.ts +++ b/tests/invitations.test.ts @@ -37,7 +37,7 @@ describe("Invitations", () => { fetchMock.resetMocks(); }); - test("send invitation should send an invitation and return success", async () => { + test("Send invitation should send an invitation", async () => { const SendInvitationResponse = { status: 200, message: "Invitation sent successfully", @@ -48,21 +48,21 @@ describe("Invitations", () => { expect(response).toEqual(SendInvitationResponse); }); - test("invitation should return an invitation and return success", async () => { + test("Invitation should return an invitation", async () => { fetchMock.mockResponseOnce(JSON.stringify(invitation)); const response = await sdk.invitations.Invitation(userId, domainId, token); expect(response).toEqual(invitation); }); - test("invitations should return a list of invitations and return success", async () => { + test("Invitations should return a list of invitations", async () => { fetchMock.mockResponseOnce(JSON.stringify(invitationsPage)); const response = await sdk.invitations.Invitations(queryParams, token); expect(response).toEqual(invitationsPage); }); - test("accept invitation should accept an invitation and return success", async () => { + test("Accept invitation should accept an invitation", async () => { const AcceptInvitationResponse = { status: 200, message: "Invitation accepted successfully", @@ -73,7 +73,7 @@ describe("Invitations", () => { expect(response).toEqual(AcceptInvitationResponse); }); - test("reject invitation should reject an invitation and return success", async () => { + test("Reject invitation should reject an invitation", async () => { const RejectInvitationResponse = { status: 200, message: "Invitation rejected successfully", @@ -84,7 +84,7 @@ describe("Invitations", () => { expect(response).toEqual(RejectInvitationResponse); }); - test("delete invitation should delete an invitation and return success", async () => { + test("Delete invitation should delete an invitation", async () => { const DeleteInvitationResponse = { status: 200, message: "Invitation deleted successfully", diff --git a/tests/messages.test.ts b/tests/messages.test.ts index aaa906d..013976c 100644 --- a/tests/messages.test.ts +++ b/tests/messages.test.ts @@ -21,7 +21,7 @@ describe("Messages", () => { value: 120.1, }; const msg = '[{"n": "temp","bu": "C","u": "C","v": 23000}]'; - const thingKey = "bb7edb32-2eac-4aad-aebe-ed96fe073879"; + const clientKey = "bb7edb32-2eac-4aad-aebe-ed96fe073879"; const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJiYjdlZGIzM"; const domainId = "bb7edb32-2eac-4aad-aebe-ed96fe073879"; const queryParams = { @@ -40,19 +40,19 @@ describe("Messages", () => { fetchMock.resetMocks(); }); - test("Send should send a message and return success", async () => { + test("Send should send a message", async () => { fetchMock.mockResponseOnce( JSON.stringify({ status: 200, message: "Message sent successfully" }), ); - const response = await sdk.messages.Send(channelId, msg, thingKey); + const response = await sdk.messages.Send(channelId, msg, clientKey); expect(response).toEqual({ status: 200, message: "Message sent successfully", }); }); - test("Read should read messages and return success", async () => { + test("Read should read messages", async () => { fetchMock.mockResponseOnce(JSON.stringify(messagesPage)); const response = await sdk.messages.Read( diff --git a/tests/roles.test.ts b/tests/roles.test.ts index e915844..245d1ff 100644 --- a/tests/roles.test.ts +++ b/tests/roles.test.ts @@ -20,7 +20,7 @@ describe("Roles", () => { fetchMock.resetMocks(); }); - test("ListAvailableActions should return available actions", async () => { + test("List available actions should return available actions", async () => { const availableActions = ["read", "write", "delete"]; fetchMock.mockResponseOnce(JSON.stringify(availableActions)); @@ -28,7 +28,7 @@ describe("Roles", () => { expect(response).toEqual(availableActions); }); - test("CreateRole should create a new role and return it", async () => { + test("Create role should create a new role and return it", async () => { fetchMock.mockResponseOnce(JSON.stringify(role)); const response = await roles.CreateRole( @@ -43,7 +43,7 @@ describe("Roles", () => { expect(response).toEqual(role); }); - test("ListRoles should return a page of roles", async () => { + test("List roles should return a page of roles", async () => { const rolesPage = { roles: [role], total: 1, offset: 0, limit: 10 }; fetchMock.mockResponseOnce(JSON.stringify(rolesPage)); @@ -57,7 +57,7 @@ describe("Roles", () => { expect(response).toEqual(rolesPage); }); - test("ViewRole should return details of a specific role", async () => { + test("View role should return details of a specific role", async () => { fetchMock.mockResponseOnce(JSON.stringify(role)); const response = await roles.ViewRole( @@ -70,7 +70,7 @@ describe("Roles", () => { expect(response).toEqual(role); }); - test("UpdateRole should update a role and return the updated role", async () => { + test("Update role should update a role and return the updated role", async () => { const updatedRole = { ...role, actions: [...actions, "execute"] }; fetchMock.mockResponseOnce(JSON.stringify(updatedRole)); @@ -85,7 +85,7 @@ describe("Roles", () => { expect(response).toEqual(updatedRole); }); - test("DeleteRole should delete a role and return success response", async () => { + test("Delete role should delete a role response", async () => { const successResponse = { status: 200, message: "Role deleted successfully", @@ -102,7 +102,7 @@ describe("Roles", () => { expect(response).toEqual(successResponse); }); - test("AddRoleActions should add actions to a role and return updated actions", async () => { + test("Add role actions should add actions to a role and return updated actions", async () => { const updatedActions = [...actions, "execute"]; fetchMock.mockResponseOnce(JSON.stringify(updatedActions)); @@ -117,7 +117,7 @@ describe("Roles", () => { expect(response).toEqual(updatedActions); }); - test("ListRoleActions should return actions of a specific role", async () => { + test("List role actions should return actions of a specific role", async () => { fetchMock.mockResponseOnce(JSON.stringify(actions)); const response = await roles.ListRoleActions( @@ -130,7 +130,7 @@ describe("Roles", () => { expect(response).toEqual(actions); }); - test("DeleteRoleActions should remove actions from a role and return success response", async () => { + test("Delete role actions should remove actions from a role response", async () => { const successResponse = { status: 200, message: "Role actions deleted successfully", @@ -148,7 +148,7 @@ describe("Roles", () => { expect(response).toEqual(successResponse); }); - test("DeleteAllRoleActions should remove all actions from a role and return success response", async () => { + test("Delete all role actions should remove all actions from a role response", async () => { const successResponse = { status: 200, message: "Role actions deleted successfully", @@ -165,7 +165,7 @@ describe("Roles", () => { expect(response).toEqual(successResponse); }); - test("AddRoleMembers should add members to a role and return updated members", async () => { + test("Add role members should add members to a role and return updated members", async () => { const updatedMembers = [...members, "user3"]; fetchMock.mockResponseOnce(JSON.stringify(updatedMembers)); @@ -180,7 +180,7 @@ describe("Roles", () => { expect(response).toEqual(updatedMembers); }); - test("ListRoleMembers should return members of a specific role", async () => { + test("List role members should return members of a specific role", async () => { fetchMock.mockResponseOnce(JSON.stringify(members)); const response = await roles.ListRoleMembers( @@ -194,7 +194,7 @@ describe("Roles", () => { expect(response).toEqual(members); }); - test("DeleteRoleMembers should remove members from a role and return success response", async () => { + test("Delete role members should remove members from a role response", async () => { const successResponse = { status: 200, message: "Role members deleted successfully", @@ -212,7 +212,7 @@ describe("Roles", () => { expect(response).toEqual(successResponse); }); - test("DeleteAllRoleMembers should remove all members from a role and return success response", async () => { + test("Delete all role members should remove all members from a role response", async () => { const successResponse = { status: 200, message: "Role members deleted successfully", diff --git a/tests/users.test.ts b/tests/users.test.ts index fb3d015..fa64c72 100644 --- a/tests/users.test.ts +++ b/tests/users.test.ts @@ -117,63 +117,63 @@ describe("Users", () => { fetchMock.resetMocks(); }); - test("create should create a user and return success", async () => { + test("Create should create a user", async () => { fetchMock.mockResponseOnce(JSON.stringify(user)); const response = await sdk.users.Create(user); expect(response).toEqual(user); }); - test("create token should create a token for a user and return success", async () => { + test("Create token should create a token for a user", async () => { fetchMock.mockResponseOnce(JSON.stringify(tokenObject)); const response = await sdk.users.CreateToken(login); expect(response).toEqual(tokenObject); }); - test("refresh token should refresh a user's token and return success", async () => { + test("Refresh token should refresh a user's token", async () => { fetchMock.mockResponseOnce(JSON.stringify(tokenObject)); const response = await sdk.users.RefreshToken(refreshToken); expect(response).toEqual(tokenObject); }); - test("users should get a list of users and return success", async () => { + test("Users should get a list of users", async () => { fetchMock.mockResponseOnce(JSON.stringify(UsersPage)); const response = await sdk.users.Users(queryParams, token); expect(response).toEqual(UsersPage); }); - test("update should update a user metadata and return success", async () => { + test("Update should update a user metadata", async () => { fetchMock.mockResponseOnce(JSON.stringify(user)); const response = await sdk.users.Update(user, token); expect(response).toEqual(user); }); - test("update user email should update a user email address and return success", async () => { + test("Update user email should update a user email address", async () => { fetchMock.mockResponseOnce(JSON.stringify(user)); const response = await sdk.users.UpdateEmail(user, token); expect(response).toEqual(user); }); - test("update username should update a username and return success", async () => { + test("Update username should update a username", async () => { fetchMock.mockResponseOnce(JSON.stringify(user)); const response = await sdk.users.UpdateUsername(user, token); expect(response).toEqual(user); }); - test("update user profile picture should update a user profile picture URL and return success", async () => { + test("Update user profile picture should update a user profile picture URL", async () => { fetchMock.mockResponseOnce(JSON.stringify(user)); const response = await sdk.users.UpdateProfilePicture(user, token); expect(response).toEqual(user); }); - test("update user password should update a user password and return success", async () => { + test("Update user password should update a user password", async () => { fetchMock.mockResponseOnce(JSON.stringify(user)); const response = await sdk.users.UpdateUserPassword( @@ -184,49 +184,49 @@ describe("Users", () => { expect(response).toEqual(user); }); - test("update user tags should update a user tags and return success", async () => { + test("Update user tags should update a user tags", async () => { fetchMock.mockResponseOnce(JSON.stringify(user)); const response = await sdk.users.UpdateUserTags(user, token); expect(response).toEqual(user); }); - test("update user role should update a user role and return success", async () => { + test("Update user role should update a user role", async () => { fetchMock.mockResponseOnce(JSON.stringify(user)); const response = await sdk.users.UpdateUserRole(user, token); expect(response).toEqual(user); }); - test("get user should get a user and return success", async () => { + test("User should retrieve a user", async () => { fetchMock.mockResponseOnce(JSON.stringify(user)); const response = await sdk.users.User(userId, token); expect(response).toEqual(user); }); - test("user profile should return a user profile and return success", async () => { + test("User profile should return a user profile", async () => { fetchMock.mockResponseOnce(JSON.stringify(user)); const response = await sdk.users.UserProfile(token); expect(response).toEqual(user); }); - test("disable user should disable a user and return success", async () => { + test("Disable user should disable a user", async () => { fetchMock.mockResponseOnce(JSON.stringify(user)); const response = await sdk.users.Disable(user, token); expect(response).toEqual(user); }); - test("enable user should enable a user and return success", async () => { + test("Enable user should enable a user", async () => { fetchMock.mockResponseOnce(JSON.stringify(user)); const response = await sdk.users.Enable(user, token); expect(response).toEqual(user); }); - test("list user groups should return a list of groups associated with a user and return success", async () => { + test("List user groups should return a list of groups associated with a user", async () => { fetchMock.mockResponseOnce(JSON.stringify(GroupsPage)); const response = await sdk.users.ListUserGroups( @@ -238,7 +238,7 @@ describe("Users", () => { expect(response).toEqual(GroupsPage); }); - test("list user clients should return a list of clients associated with a user and return success", async () => { + test("List user clients should return a list of clients associated with a user", async () => { fetchMock.mockResponseOnce(JSON.stringify(clientsPage)); const response = await sdk.users.ListUserClients( @@ -250,7 +250,7 @@ describe("Users", () => { expect(response).toEqual(clientsPage); }); - test("list user channels should return a list of channels associated with a user and return success", async () => { + test("List user channels should return a list of channels associated with a user", async () => { fetchMock.mockResponseOnce(JSON.stringify(channelsPage)); const response = await sdk.users.ListUserChannels( @@ -262,7 +262,7 @@ describe("Users", () => { expect(response).toEqual(channelsPage); }); - test("reset user password request should send a password reset request and return success", async () => { + test("Reset user password request should send a password reset request", async () => { const resetPasswordRequestResponse = { status: 200, message: "Email with reset link sent successfully", @@ -273,7 +273,7 @@ describe("Users", () => { expect(response).toEqual(resetPasswordRequestResponse); }); - test("reset user password should reset a user password and return success", async () => { + test("Reset user password should reset a user password", async () => { const resetPasswordResponse = { status: 200, message: "Password reset successfully", @@ -284,7 +284,7 @@ describe("Users", () => { expect(response).toEqual(resetPasswordResponse); }); - test("delete user should delete a user and return success", async () => { + test("Delete user should delete a user", async () => { const deleteResponse = { status: 200, message: "User deleted successfully", @@ -295,7 +295,7 @@ describe("Users", () => { expect(response).toEqual(deleteResponse); }); - test("search user should search for a user and return success", async () => { + test("Search user should search for a user", async () => { fetchMock.mockResponseOnce(JSON.stringify(UsersPage)); const response = await sdk.users.SearchUsers(queryParams, token);