Added some documentation

This commit is contained in:
Khalim Conn-Kowlessar 2023-07-11 15:49:19 +01:00
parent 9a3b067478
commit 4db0ce0091
3 changed files with 37 additions and 4 deletions

View file

@ -78,3 +78,37 @@ npm run create_users -- {email} {firstName}
```
Since we're using just the built in process arguments to read command line arguments, the ordering of arguments needs to be email address and then name
# Cypress Testing Documentation
This document provides an overview of how to perform end-to-end testing using Cypress for the login functionality of the application. The testing code is based on the provided code snippets.
## Prerequisites
Node.js installed on your machine
Cypress installed as a dev dependency in your project
## Test Execution
To execute the login tests, follow these steps:
1. Run
```bash
npm run test:e2e:open
```
Which will open Crypress test runner
2. Select the tests that you want to run. At the time of writing, only login tests have been completed
## Key files
The key files that are at play for testing are documented here. Because of some issues testing next-auth and setting cookies, a custom command to set
the JWT, and avoid the functionality defined in the signIn function as defined in `src/app/api/auth/[...nextauth]/route.ts`
**cypress/plugins/index.js** is a standard file, required by cypress to journey through the Google Oauth flow
**cypress/figtures/session.json** is a user fixture that is used to log in a user in the login tests
**cypress/support/commands.ts** creates a custom login user command which sets a JWT and allows us to actually authenticate. `cy.intercept` only mocks the client side behaviour of the apis and therefore does not set any cookies, do this function does this manually.

View file

@ -1,5 +1,5 @@
const USER = {
name: "John",
name: "John Wick",
};
describe("Login page", () => {
@ -32,8 +32,6 @@ describe("Login page", () => {
// Check cookies with cy.getCookies() command after login and task are completed
cy.getCookies().then((cookies) => {
cy.log(cookies);
const cookie = cookies.find((cookie) => cookie.name === cookieName);
cy.log("Cookie found!");

View file

@ -30,7 +30,8 @@
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
"src/app/db/schema/users.ts"
"src/app/db/schema/users.ts",
"cypress/support/commands.js"
],
"exclude": ["node_modules"]
}