From e3f591e7d2dc663c5211bf7ff11bda3997cf0a6f Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 16 Dec 2022 14:59:03 +0000 Subject: [PATCH] Return the password from `getBot` ... so that we can use it to log in for a second time --- cypress/e2e/crypto/crypto.spec.ts | 3 ++- cypress/support/bot.ts | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cypress/e2e/crypto/crypto.spec.ts b/cypress/e2e/crypto/crypto.spec.ts index 2a55c21b05..d89e0bc176 100644 --- a/cypress/e2e/crypto/crypto.spec.ts +++ b/cypress/e2e/crypto/crypto.spec.ts @@ -18,13 +18,14 @@ import { MatrixClient, Room } from "matrix-js-sdk/src/matrix"; import type { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest"; import type { ISasEvent } from "matrix-js-sdk/src/crypto/verification/SAS"; +import type { CypressBot } from "../../support/bot"; import { SynapseInstance } from "../../plugins/synapsedocker"; import Chainable = Cypress.Chainable; type EmojiMapping = [emoji: string, name: string]; interface CryptoTestContext extends Mocha.Context { synapse: SynapseInstance; - bob: MatrixClient; + bob: CypressBot; } const waitForVerificationRequest = (cli: MatrixClient): Promise => { diff --git a/cypress/support/bot.ts b/cypress/support/bot.ts index f4476af12f..40e0986d16 100644 --- a/cypress/support/bot.ts +++ b/cypress/support/bot.ts @@ -46,6 +46,10 @@ const defaultCreateBotOptions = { bootstrapCrossSigning: true, } as CreateBotOpts; +export interface CypressBot extends MatrixClient { + __cypress_password: string; +} + declare global { // eslint-disable-next-line @typescript-eslint/no-namespace namespace Cypress { @@ -55,7 +59,7 @@ declare global { * @param synapse the instance on which to register the bot user * @param opts create bot options */ - getBot(synapse: SynapseInstance, opts: CreateBotOpts): Chainable; + getBot(synapse: SynapseInstance, opts: CreateBotOpts): Chainable; /** * Returns a new Bot instance logged in as an existing user * @param synapse the instance on which to register the bot user @@ -151,14 +155,20 @@ function setupBotClient( }); } -Cypress.Commands.add("getBot", (synapse: SynapseInstance, opts: CreateBotOpts): Chainable => { +Cypress.Commands.add("getBot", (synapse: SynapseInstance, opts: CreateBotOpts): Chainable => { opts = Object.assign({}, defaultCreateBotOptions, opts); const username = Cypress._.uniqueId("userId_"); const password = Cypress._.uniqueId("password_"); - return cy.registerUser(synapse, username, password, opts.displayName).then((credentials) => { - cy.log(`Registered bot user ${username} with displayname ${opts.displayName}`); - return setupBotClient(synapse, credentials, opts); - }); + return cy + .registerUser(synapse, username, password, opts.displayName) + .then((credentials) => { + cy.log(`Registered bot user ${username} with displayname ${opts.displayName}`); + return setupBotClient(synapse, credentials, opts); + }) + .then((client): Chainable => { + Object.assign(client, { __cypress_password: password }); + return cy.wrap(client as CypressBot); + }); }); Cypress.Commands.add(