From 4820764ede1b88b2247d25dda2cdac4b92736f74 Mon Sep 17 00:00:00 2001 From: Diegogtzt03 <65473367+Diegogtz03@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:15:46 -0600 Subject: [PATCH 1/6] refactor: Remove unused login test and add login/sign up tests with GitHub provider --- knowx/cypress/e2e/login/initial.cy.ts | 13 ----- knowx/cypress/e2e/login/login.cy.ts | 68 +++++++++++++++++++++++++++ knowx/src/app/auth/page.tsx | 1 + knowx/src/app/history/page.tsx | 20 +++++--- 4 files changed, 83 insertions(+), 19 deletions(-) delete mode 100644 knowx/cypress/e2e/login/initial.cy.ts create mode 100644 knowx/cypress/e2e/login/login.cy.ts diff --git a/knowx/cypress/e2e/login/initial.cy.ts b/knowx/cypress/e2e/login/initial.cy.ts deleted file mode 100644 index 6de253d..0000000 --- a/knowx/cypress/e2e/login/initial.cy.ts +++ /dev/null @@ -1,13 +0,0 @@ -describe('Auth Redirect', () => { - it('passes', () => { - cy.visit('http://localhost:3000') - cy.url().should('eq', 'http://localhost:3000/auth') - }) -}) - -describe('Logged out Redirect', () => { - it('passes', () => { - cy.visit('http://localhost:3000/dashboard') - cy.url().should('eq', 'http://localhost:3000/auth') - }) -}) \ No newline at end of file diff --git a/knowx/cypress/e2e/login/login.cy.ts b/knowx/cypress/e2e/login/login.cy.ts new file mode 100644 index 0000000..3f3d0af --- /dev/null +++ b/knowx/cypress/e2e/login/login.cy.ts @@ -0,0 +1,68 @@ +// E2E login/sign up tests (Diego Gutiérrez A01284841) + +// commands.ts +// Origin: https://www.tomoliver.net/posts/cypress-samesite-problem +Cypress.Commands.add("rewriteHeaders", () => { + cy.intercept("*", (req) => + req.on("response", (res) => { + const setCookies = res.headers["set-cookie"] + res.headers["set-cookie"] = ( + Array.isArray(setCookies) ? setCookies : [setCookies] + ) + .filter((x) => x) + .map((headerContent) => + headerContent.replace( + /samesite=(lax|strict)/gi, + "secure; samesite=none", + ), + ) + }), + ) +}) + +describe("Auth Redirect", () => { + it("passes", () => { + // Check if the user is redirected to the auth page when trying to access other pages + cy.visit("http://localhost:3000").wait(1000) + cy.url().should("eq", "http://localhost:3000/auth") + + // Check if all routes redirect to the auth page + cy.visit("http://localhost:3000/dashboard").wait(1000) + cy.url().should("eq", "http://localhost:3000/auth") + + // cy.visit("http://localhost:3000/history").wait(1000) + // cy.url().should("eq", "http://localhost:3000/auth") + }) +}) + +describe("Login using github", () => { + beforeEach(() => { + cy.rewriteHeaders() + }) + it("passes", () => { + cy.visit("http://localhost:3000/auth") + + cy.get("#provider-button-github").click() + + // cy.url().then((url) => { + // if (cy.url().includes("github.com")) { + cy.origin("https://github.com", () => { + cy.get("#login_field").should("exist") + + cy.get("#login_field").type("knowx06@gmail.com") + cy.get("#password").type("S!P4AeZ63*#BtT3.") + cy.get('input[type="submit"]').click() + + cy.get('button[name="authorize"]').contains("Authorize").click() + }) + + // cy.get('button[name="authorize"]') + // .contains("Authorize") + // .click() + // .then(() => { + cy.url().should("eq", "http://localhost:3000/dashboard") + // }) + // cy.url().should("eq", "http://localhost:3000/dashboard") + // } + }) +}) diff --git a/knowx/src/app/auth/page.tsx b/knowx/src/app/auth/page.tsx index 1f31a6e..7e1558d 100644 --- a/knowx/src/app/auth/page.tsx +++ b/knowx/src/app/auth/page.tsx @@ -115,6 +115,7 @@ export default function Signup() {