diff --git a/README.md b/README.md index f93ac46..e88f017 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/cypress/e2e/login/login.cy.js b/cypress/e2e/login/login.cy.js index a009bbf..947fcc3 100644 --- a/cypress/e2e/login/login.cy.js +++ b/cypress/e2e/login/login.cy.js @@ -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!"); diff --git a/tsconfig.json b/tsconfig.json index bda1072..6468155 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"] }