diff --git a/cypress/e2e/crypto/crypto.spec.ts b/cypress/e2e/crypto/crypto.spec.ts index 2a55c21b05..b5db3871b8 100644 --- a/cypress/e2e/crypto/crypto.spec.ts +++ b/cypress/e2e/crypto/crypto.spec.ts @@ -158,8 +158,8 @@ describe("Cryptography", function () { cy.startSynapse("default") .as("synapse") .then((synapse: SynapseInstance) => { - cy.initTestUser(synapse, "Alice"); - cy.getBot(synapse, { displayName: "Bob", autoAcceptInvites: false }).as("bob"); + cy.initTestUser(synapse, "Alice", undefined, "alice_"); + cy.getBot(synapse, { displayName: "Bob", autoAcceptInvites: false, userIdPrefix: "bob_" }).as("bob"); }); }); diff --git a/cypress/support/bot.ts b/cypress/support/bot.ts index f4476af12f..78c83c5c8e 100644 --- a/cypress/support/bot.ts +++ b/cypress/support/bot.ts @@ -22,6 +22,10 @@ import { Credentials } from "./synapse"; import Chainable = Cypress.Chainable; interface CreateBotOpts { + /** + * A prefix to use for the userid. If unspecified, "bot_" will be used. + */ + userIdPrefix?: string; /** * Whether the bot should automatically accept all invites. */ @@ -41,6 +45,7 @@ interface CreateBotOpts { } const defaultCreateBotOptions = { + userIdPrefix: "bot_", autoAcceptInvites: true, startClient: true, bootstrapCrossSigning: true, @@ -153,7 +158,7 @@ function setupBotClient( Cypress.Commands.add("getBot", (synapse: SynapseInstance, opts: CreateBotOpts): Chainable => { opts = Object.assign({}, defaultCreateBotOptions, opts); - const username = Cypress._.uniqueId("userId_"); + const username = Cypress._.uniqueId(opts.userIdPrefix); 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}`); diff --git a/cypress/support/login.ts b/cypress/support/login.ts index 73300f7905..338da2f9db 100644 --- a/cypress/support/login.ts +++ b/cypress/support/login.ts @@ -37,11 +37,14 @@ declare global { * @param synapse the synapse returned by startSynapse * @param displayName the displayName to give the test user * @param prelaunchFn optional function to run before the app is visited + * @param userIdPrefix optional prefix to use for the generated user id. If unspecified, `user_` will be + * useed. */ initTestUser( synapse: SynapseInstance, displayName: string, prelaunchFn?: () => void, + userIdPrefix?: string, ): Chainable; /** * Logs into synapse with the given username/password @@ -91,7 +94,12 @@ Cypress.Commands.add( // eslint-disable-next-line max-len Cypress.Commands.add( "initTestUser", - (synapse: SynapseInstance, displayName: string, prelaunchFn?: () => void): Chainable => { + ( + synapse: SynapseInstance, + displayName: string, + prelaunchFn?: () => void, + userIdPrefix = "user_", + ): Chainable => { // XXX: work around Cypress not clearing IDB between tests cy.window({ log: false }).then((win) => { win.indexedDB.databases()?.then((databases) => { @@ -101,7 +109,7 @@ Cypress.Commands.add( }); }); - const username = Cypress._.uniqueId("userId_"); + const username = Cypress._.uniqueId(userIdPrefix); const password = Cypress._.uniqueId("password_"); return cy .registerUser(synapse, username, password, displayName)