From 72ce45842114b012b1636e6d9b12def573807826 Mon Sep 17 00:00:00 2001 From: schultztimothy Date: Thu, 6 Apr 2023 14:50:09 -0600 Subject: [PATCH] chore(test, interface): environment variable approach to skirting wallet connection for cypress testing --- interface/.env.example | 1 + interface/components/RequireAuth.tsx | 4 +++- test/cypress.config.ts | 4 ++-- test/cypress/e2e/api_key.ts | 18 +++++++----------- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/interface/.env.example b/interface/.env.example index 17b00bb5c..94342fe3d 100644 --- a/interface/.env.example +++ b/interface/.env.example @@ -1,2 +1,3 @@ NEXT_PUBLIC_PASSPORT_SCORER_ALCHEMY_API_KEY=YOUR_API_KEY NEXT_PUBLIC_PASSPORT_SCORER_BACKEND=http://localhost:8002/ +NEXT_PUBLIC_PASSPORT_SCORER_TESTING_CYPRESS="on" diff --git a/interface/components/RequireAuth.tsx b/interface/components/RequireAuth.tsx index 92279b30a..146edd0c4 100644 --- a/interface/components/RequireAuth.tsx +++ b/interface/components/RequireAuth.tsx @@ -7,6 +7,8 @@ import { UserContext } from "../context/userContext"; import { headerInterceptor, unAuthorizedInterceptor } from "../utils/interceptors"; +const testingCypress = process.env.NEXT_PUBLIC_PASSPORT_SCORER_TESTING_CYPRESS === "on"; + const RequireAuth = ({ children }: { children: React.ReactNode }) => { const navigate = useNavigate(); const { pathname } = useLocation(); @@ -23,7 +25,7 @@ const RequireAuth = ({ children }: { children: React.ReactNode }) => { // If the user is not connected, redirect to the home page useEffect(() => { - if (pathname !== "/" && ready && !connected) { + if (pathname !== "/" && ready && !connected && !testingCypress) { navigate("/"); } }, [ready, connected, pathname, navigate]); diff --git a/test/cypress.config.ts b/test/cypress.config.ts index 5c7ef9497..3fe8dc327 100644 --- a/test/cypress.config.ts +++ b/test/cypress.config.ts @@ -27,10 +27,10 @@ export default defineConfig({ specPattern: "**/*.feature", supportFile: false, setupNodeEvents, - baseUrl: 'http://localhost:3000', + baseUrl: 'http://localhost:3001', }, env: { // serverUrl should end with '/' - serverUrl: 'http://localhost:8000/', + serverUrl: 'http://localhost:8002/', } }); diff --git a/test/cypress/e2e/api_key.ts b/test/cypress/e2e/api_key.ts index cb468ff28..5b1c3114a 100644 --- a/test/cypress/e2e/api_key.ts +++ b/test/cypress/e2e/api_key.ts @@ -3,23 +3,19 @@ import "../support/commands"; Given("that I have an API account", () => { cy.siwe(); - cy.visit("/"); - cy.get("button").contains("Sign-in with Ethereum").click(); - cy.visit("/dashboard"); + cy.visit("/#/dashboard/scorer"); }); When("I hit to create an API key", () => { - cy - .get("[data-testid='api-keys-tab']") - .contains("API Keys") - .click(); - cy.get("button").contains("Add").click(); - cy.get("[data-testid='key-name-input']").type("test"); - cy.get("[data-testid='create-button']").click(); + cy.get('#tabSelect') + .select('api-keys', { force: true }); + cy.get("button[data-testid='no-values-add']").contains("API Key").click(); + cy.get("[data-testid='key-name-input']").type("testing"); + cy.get("button").contains("Create").click(); }); Then("I’m returned a secret API key, basically a long cryptic string", () => { - + cy.get("button[data-testid='copy-api-key']"); }); Then("I can use that key to call the API", () => {});