Skip to content

chore: skip global.setup if first user already exists #12930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup api route url
  • Loading branch information
Emyrk committed Apr 10, 2024
commit 1b721ed4cecbae25b6eb2d32f68587c553267bb1
8 changes: 5 additions & 3 deletions site/e2e/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { findSessionToken, randomName } from "./helpers";

let currentOrgId: string;

export const setupApiCalls = async (page: Page) => {
const token = await findSessionToken(page);
API.setSessionToken(token);
export const setupApiCalls = async (page: Page, unauthenticated?: boolean) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having a boolean as an optional argument is almost always a bad idea imo, because from the call site setupApiCalls(page, true) is incredibly vague. it should either be on an options object, or ideally imo, it would just gracefully do nothing if there is no token, and not take any additional params.

try {
  const token = await findSessionToken(page);
  API.setSessionToken(token);
} catch {}

if (!unauthenticated) {
const token = await findSessionToken(page);
API.setSessionToken(token);
}
API.setHost(`http://127.0.0.1:${coderPort}`);
};

Expand Down
5 changes: 3 additions & 2 deletions site/e2e/global.setup.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { expect, test } from "@playwright/test";
import { hasFirstUser } from "api/api";
import { Language } from "pages/CreateUserPage/CreateUserForm";
import { setupApiCalls } from "./api";
import * as constants from "./constants";
import { storageState } from "./playwright.config";

test("setup deployment", async ({ page }) => {
await page.goto("/", { waitUntil: "domcontentloaded" });
await setupApiCalls(page, true);
const exists = await hasFirstUser();
if (exists) {
// First user already exists, abort early. All tests execute this as a dependency,
// if you run multiple tests in the UI, this will fail unless we check this.
return;
}

await page.goto("/", { waitUntil: "domcontentloaded" });

// Setup first user
await page.getByLabel(Language.usernameLabel).fill(constants.username);
await page.getByLabel(Language.emailLabel).fill(constants.email);
Expand Down