Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
* No magic strings
* Re-type function parameters
* Document user types
  • Loading branch information
minnakt committed Feb 20, 2024
1 parent 7387484 commit 5ed984b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 19 deletions.
12 changes: 12 additions & 0 deletions cypress/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
export const EVG_BASE_URL = "http://localhost:9090";
export const GQL_URL = `${EVG_BASE_URL}/graphql/query`;

/**
* Defines user credentials that can be used to log in to the application.
* - admin: A user who has admin permissions and is a superuser.
* - privileged: A user who has admin permissions, but is not a superuser.
* - regular: A user who has no admin permissions.
*/
export const users = {
admin: { username: "admin", password: "password" },
privileged: { username: "privileged", password: "password" },
regular: { username: "regular", password: "password" },
};
10 changes: 6 additions & 4 deletions cypress/integration/distroSettings/permissions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { users } from "../../constants";

describe("distro permissions", () => {
beforeEach(() => {
cy.logout();
});

it("hides the new distro button when a user cannot create distros", () => {
cy.login({ username: "privileged" });
cy.login(users.privileged);
cy.visit("/distro/rhel71-power8-large/settings/general");
cy.dataCy("new-distro-button").should("not.exist");
cy.dataCy("delete-distro-button").should(
Expand All @@ -16,7 +18,7 @@ describe("distro permissions", () => {
});

it("disables the delete button when user lacks admin permissions", () => {
cy.login({ username: "regular" });
cy.login(users.regular);
cy.visit("/distro/rhel71-power8-large/settings/general");
cy.dataCy("delete-distro-button").should(
"have.attr",
Expand All @@ -26,7 +28,7 @@ describe("distro permissions", () => {
});

it("disables fields when user lacks edit permissions", () => {
cy.login({ username: "regular" });
cy.login(users.regular);
cy.visit("/distro/rhel71-power8-large/settings/general");
cy.dataCy("distro-settings-page").within(() => {
cy.get('input[type="checkbox"]').should(
Expand All @@ -39,7 +41,7 @@ describe("distro permissions", () => {
});

it("enables fields if user has edit permissions for a particular distro", () => {
cy.login({ username: "regular" });
cy.login(users.regular);
cy.visit("/distro/localhost/settings/general");
cy.dataCy("distro-settings-page").within(() => {
cy.get('input[type="checkbox"]').should(
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/nav_bar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EVG_BASE_URL } from "../constants";
import { EVG_BASE_URL, users } from "../constants";

const PATCH_ID = "5e4ff3abe3c3317e352062e4";
const USER_ID = "admin";
Expand Down Expand Up @@ -118,7 +118,7 @@ describe("Nav Bar", () => {

it("Should not show Admin button to non-admins", () => {
cy.logout();
cy.login({ username: "regular" });
cy.login(users.regular);
cy.visit(SPRUCE_URLS.version);
cy.dataCy("user-dropdown-link").click();
cy.dataCy("admin-link").should("not.exist");
Expand Down
13 changes: 5 additions & 8 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EVG_BASE_URL, GQL_URL } from "../constants";
import { EVG_BASE_URL, GQL_URL, users } from "../constants";
import { hasOperationName } from "../utils/graphql-test-utils";

type cyGetOptions = Parameters<typeof cy.get>[1];
Expand Down Expand Up @@ -33,8 +33,8 @@ Cypress.Commands.add(
* `enterLoginCredentials` is a custom command to enter login credentials
*/
Cypress.Commands.add("enterLoginCredentials", () => {
cy.get("input[name=username]").type("admin");
cy.get("input[name=password]").type("password");
cy.get("input[name=username]").type(users.admin.username);
cy.get("input[name=password]").type(users.admin.password);
cy.get("button[id=login-submit]").click();
});

Expand All @@ -52,13 +52,10 @@ Cypress.Commands.add("getInputByLabel", (label: string | RegExp) => {
});

/* login */
Cypress.Commands.add("login", ({ username = "admin" }) => {
Cypress.Commands.add("login", (user = users.admin) => {
cy.getCookie("mci-token").then((c) => {
if (!c) {
cy.request("POST", `${EVG_BASE_URL}/login`, {
username,
password: "password",
});
cy.request("POST", `${EVG_BASE_URL}/login`, user);
}
});
});
Expand Down
16 changes: 11 additions & 5 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,17 @@ declare global {
*/
selectLGOption(label: string, option: string | RegExp): void;
/**
* Custom command to navigate to login page and login.
* @param username The username of the account to log in to.
* @example cy.login()
* Custom command to navigate to login page and log in.
* @example cy.login({ username: "me", password: "abc" })
* @example cy.login() // defaults to admin login
*/
login({ username }: { username: string }): void;
login({
password,
username,
}?: {
username: string;
password: string;
}): void;
/**
* Custom command to log out of the application.
* @example cy.logout()
Expand Down Expand Up @@ -148,7 +154,7 @@ before(() => {
(() => {
let mutationDispatched: boolean;
beforeEach(() => {
cy.login({ username: "admin" });
cy.login();
cy.setCookie(bannerCookie, "true");
cy.setCookie(CY_DISABLE_COMMITS_WELCOME_MODAL, "true");
cy.setCookie(CY_DISABLE_NEW_USER_WELCOME_MODAL, "true");
Expand Down

0 comments on commit 5ed984b

Please sign in to comment.