From edd90d7db1b1a4298b59b0499ff56794d342e4ab Mon Sep 17 00:00:00 2001 From: Angel Mendez Cano Date: Fri, 24 Oct 2025 15:33:14 +0000 Subject: [PATCH] feat: migrate support/client-impl.js to ts - convert support/client-impl.js to TypeScript - update related files and references - remove obsolete support/client.d.ts --- .../{client-impl.js => client-impl.ts} | 11 +++++++--- e2e-tests/cypress/tests/support/client.d.ts | 22 ------------------- .../tests/support/{client.js => client.ts} | 11 +++++++++- 3 files changed, 18 insertions(+), 26 deletions(-) rename e2e-tests/cypress/tests/support/{client-impl.js => client-impl.ts} (69%) delete mode 100644 e2e-tests/cypress/tests/support/client.d.ts rename e2e-tests/cypress/tests/support/{client.js => client.ts} (75%) diff --git a/e2e-tests/cypress/tests/support/client-impl.js b/e2e-tests/cypress/tests/support/client-impl.ts similarity index 69% rename from e2e-tests/cypress/tests/support/client-impl.js rename to e2e-tests/cypress/tests/support/client-impl.ts index 248f934cb7f..b26b59ea4c1 100644 --- a/e2e-tests/cypress/tests/support/client-impl.js +++ b/e2e-tests/cypress/tests/support/client-impl.ts @@ -4,9 +4,10 @@ import {Client4} from '@mattermost/client'; import clientRequest from '../plugins/client_request'; +import { type Options, type ClientResponse } from '@mattermost/types/client4'; export class E2EClient extends Client4 { - async doFetchWithResponse(url, options) { + protected doFetchWithResponse = async (url: string, options: Options): Promise> => { const { body, headers, @@ -30,6 +31,10 @@ export class E2EClient extends Client4 { this.setUserId(response.data.id); this.setUserRoles(response.data.roles); } - return response; - } + return { + response: response as unknown as Response, + headers: response.headers, + data: response.data, + }; + }; } diff --git a/e2e-tests/cypress/tests/support/client.d.ts b/e2e-tests/cypress/tests/support/client.d.ts deleted file mode 100644 index e639b79fd1a..00000000000 --- a/e2e-tests/cypress/tests/support/client.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See LICENSE.txt for license information. - -/// - -// *************************************************************** -// Each command should be properly documented using JSDoc. -// See https://jsdoc.app/index.html for reference. -// Basic requirements for documentation are the following: -// - Meaningful description -// - Specific link to https://api.mattermost.com -// - Each parameter with `@params` -// - Return value with `@returns` -// - Example usage with `@example` -// Custom command should follow naming convention of having `api` prefix, e.g. `apiLogin`. -// *************************************************************** - -declare namespace Cypress { - interface Chainable { - makeClient(options?: {user: Pick}): Chainable; - } -} diff --git a/e2e-tests/cypress/tests/support/client.js b/e2e-tests/cypress/tests/support/client.ts similarity index 75% rename from e2e-tests/cypress/tests/support/client.js rename to e2e-tests/cypress/tests/support/client.ts index c57a26bdba1..b56a99db194 100644 --- a/e2e-tests/cypress/tests/support/client.js +++ b/e2e-tests/cypress/tests/support/client.ts @@ -6,7 +6,7 @@ import {E2EClient} from './client-impl'; const clients = {}; -async function makeClient({user = getAdminAccount(), useCache = true} = {}) { +async function makeClient({user = getAdminAccount(), useCache = true} = {}): Promise { const cacheKey = user.username + user.password; if (useCache && clients[cacheKey] != null) { return clients[cacheKey]; @@ -27,3 +27,12 @@ async function makeClient({user = getAdminAccount(), useCache = true} = {}) { } Cypress.Commands.add('makeClient', makeClient); + +declare global { + // eslint-disable-next-line @typescript-eslint/no-namespace + namespace Cypress { + interface Chainable { + makeClient: typeof makeClient; + } + } +}