Skip to content

Commit

Permalink
chore(test, interface): environment variable approach to skirting wal…
Browse files Browse the repository at this point in the history
…let connection for cypress testing (#210)
  • Loading branch information
Tim Schultz authored Apr 6, 2023
1 parent 2c1d57a commit c7da3fc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
1 change: 1 addition & 0 deletions interface/.env.example
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 3 additions & 1 deletion interface/components/RequireAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions test/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
}
});
18 changes: 7 additions & 11 deletions test/cypress/e2e/api_key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {});

0 comments on commit c7da3fc

Please sign in to comment.