Skip to content

Conversation

josecelano
Copy link
Member

@josecelano josecelano commented Jul 12, 2023

E2E tests for user login.

  • Test for standard user login
  • Test for admin login
  • Scaffolding to arrange the database state before assertions

I've added a generic function to run SQL queries. I needed to create an account with the "admin" role. The application has only one admin, the first registered user.

There are several options to create an admin account for E2E tests.

Solution 1

We could reset the E2E test environment before running the tests, create the admin account, and finally inject the username and password as env variables into the Cypress configuration.

Pros

  • There is only one admin, which is how the app works. With solution 2, we could only add one admin every time you run the test suite.

Cons

  • You need to create a custom script to create the user if it does not exist. Then you get the user data (username, password) and pass the credentials to Cypress as env vars. We have to deal with a new binary. I prefer to only extend Cypress with tasks and commands.

Solution 2 (the one implemented)

  • Create a Cypress custom command to register users. It's a repetitive action you want to perform on the app, like registration, login, uploading a torrent, etcetera.
  • Create a Cypress custom task to grant the admin role to the newly created user. A task is a custom code you can execute in between commands.

Pros

  • Simple solution, and we can use the database wrapper to arrange the state for other tests when it's slow via the UI, which is the preferred way.

Cons

To be able to set the database state before running an E2E test.

The first case is to grant the admin role to a random user so that we
can execute E2E tests as admin.
- Test login by "users" with admin role.
- Scaffolding to run SQL queries to arrange the database state before
  assertions.
@josecelano josecelano linked an issue Jul 12, 2023 that may be closed by this pull request
@josecelano josecelano marked this pull request as ready for review July 12, 2023 17:18
@josecelano josecelano requested a review from da2ce7 July 12, 2023 17:18
@josecelano josecelano merged commit 15ea30e into torrust:develop Jul 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

E2E tests: user login
1 participant