AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
tests(frontend): e2e tests for api key page (#10683)
Abhimanyu Yadav1105e6c0d20c
diff --git a/autogpt_platform/backend/backend/server/routers/v1.py b/autogpt_platform/backend/backend/server/routers/v1.pyindex 15fb6dfcfd..b2cc5c646b 100644--- a/autogpt_platform/backend/backend/server/routers/v1.py+++ b/autogpt_platform/backend/backend/server/routers/v1.py@@ -1071,7 +1071,6 @@ async def get_api_key(tags=["api-keys"],dependencies=[Depends(auth_middleware)],)-@feature_flag("api-keys-enabled")async def delete_api_key(key_id: str, user_id: Annotated[str, Depends(get_user_id)]) -> Optional[APIKeyWithoutHash]:diff --git a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/api_keys/components/APIKeySection/APIKeySection.tsx b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/api_keys/components/APIKeySection/APIKeySection.tsxindex a9f98d66d0..61a2dcf260 100644--- a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/api_keys/components/APIKeySection/APIKeySection.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/api_keys/components/APIKeySection/APIKeySection.tsx@@ -44,9 +44,9 @@ export function APIKeysSection() {</TableHeader><TableBody>{apiKeys.map((key) => (- <TableRow key={key.id}>+ <TableRow key={key.id} data-testid="api-key-row"><TableCell>{key.name}</TableCell>- <TableCell>+ <TableCell data-testid="api-key-id"><div className="rounded-md border p-1 px-2 text-xs">{`${key.prefix}******************${key.postfix}`}</div>@@ -76,7 +76,11 @@ export function APIKeysSection() {<TableCell><DropdownMenu><DropdownMenuTrigger asChild>- <Button variant="ghost" size="sm">+ <Button+ data-testid="api-key-actions"+ variant="ghost"+ size="sm"+ ><MoreVertical className="h-4 w-4" /></Button></DropdownMenuTrigger>diff --git a/autogpt_platform/frontend/src/tests/api-keys.spec.ts b/autogpt_platform/frontend/src/tests/api-keys.spec.tsnew file mode 100644index 0000000000..a42ae8384e--- /dev/null+++ b/autogpt_platform/frontend/src/tests/api-keys.spec.ts@@ -0,0 +1,64 @@+import { expect, test } from "@playwright/test";+import { LoginPage } from "./pages/login.page";+import { TEST_CREDENTIALS } from "./credentials";+import { hasUrl } from "./utils/assertion";+import { getSelectors } from "./utils/selectors";++test.describe("API Keys Page", () => {+ test.beforeEach(async ({ page }) => {+ const loginPage = new LoginPage(page);+ await page.goto("/login");+ await loginPage.login(TEST_CREDENTIALS.email, TEST_CREDENTIALS.password);+ await hasUrl(page, "/marketplace");+ });++ test("should redirect to login page when user is not authenticated", async ({+ browser,+ }) => {+ const context = await browser.newContext();+ const page = await context.newPage();++ try {+ await page.goto("/profile/api_keys");+ await hasUrl(page, "/login");+ } finally {+ await page.close();+ await context.close();+ }+ });++ test("should create a new API key successfully", async ({ page }) => {+ const { getButton, getField } = getSelectors(page);+ await page.goto("/profile/api_keys");+ await getButton("Create Key").click();++ await getField("Name").fill("Test Key");+ await getButton("Create").click();++ await expect(+ page.getByText("AutoGPT Platform API Key Created"),+ ).toBeVisible();+ await getButton("Close").first().click();++ await expect(page.getByText("Test Key").first()).toBeVisible();+ });++ test("should revoke an existing API key", async ({ page }) => {+ const { getRole, getId } = getSelectors(page);+ await page.goto("/profile/api_keys");++ const apiKeyRow = getId("api-key-row").first();+ const apiKeyContent = await apiKeyRow+ .getByTestId("api-key-id")+ .textContent();+ const apiKeyActions = apiKeyRow.getByTestId("api-key-actions").first();++ await apiKeyActions.click();+ await getRole("menuitem", "Revoke").click();+ await expect(+ page.getByText("AutoGPT Platform API key revoked successfully"),+ ).toBeVisible();++ await expect(page.getByText(apiKeyContent!)).not.toBeVisible();+ });+});