Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
hughcrt committed Dec 26, 2024
1 parent 5d35024 commit b39c490
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11,995 deletions.
67 changes: 35 additions & 32 deletions e2e/api.spec.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
import { test, expect } from "@playwright/test"
import { test, expect } from "@playwright/test";

let privateKey = null
let publicKey = null
let privateKey = null;
let publicKey = null;

// run tests one after another
test.describe.configure({ mode: "serial" })
test.describe.configure({ mode: "serial" });

const apiUrl = process.env.API_URL || "http://localhost:3333"
const apiUrl = process.env.API_URL || "http://localhost:3333";

test("regenerate api keys", async ({ page }) => {
await page.goto("/settings")
await page.goto("/settings");

await page.waitForLoadState("networkidle")
await page.waitForLoadState("networkidle");

publicKey = await page.getByTestId("public-key").textContent()
publicKey = await page.getByTestId("public-key").textContent();

const firstPrivateKey = await page.getByTestId("private-key").textContent()
const firstPrivateKey = await page.getByTestId("private-key").textContent();

expect(publicKey).toHaveLength(36) // uuid length
expect(firstPrivateKey).toHaveLength(36) // uuid length
expect(publicKey).toHaveLength(36); // uuid length
expect(firstPrivateKey).toHaveLength(36); // uuid length

await page.waitForTimeout(300) // helps with flakiness in local
await page.waitForTimeout(300); // helps with flakiness in local

await page.getByTestId("regenerate-private-key-button").click()
await page.getByTestId("regenerate-private-key-button").click();

await page.getByTestId("confirm-button").click()
await page.getByTestId("confirm-button").click();

await page.waitForResponse((resp) => resp.url().includes("/regenerate-key"))
await page.waitForResponse((resp) => {
console.log(resp.url());
return resp.url().includes("/regenerate-key");
});

await page.waitForTimeout(1000)
await page.waitForTimeout(1000);

const secondPrivateKey = await page.getByTestId("private-key").textContent()
const secondPrivateKey = await page.getByTestId("private-key").textContent();

expect(firstPrivateKey).not.toEqual(secondPrivateKey)
expect(firstPrivateKey).not.toEqual(secondPrivateKey);

privateKey = secondPrivateKey
})
privateKey = secondPrivateKey;
});

test("private api /logs", async ({ page }) => {
// Test API query
Expand All @@ -46,11 +49,11 @@ test("private api /logs", async ({ page }) => {
"Content-Type": "application/json",
"X-API-Key": privateKey!,
},
})
});

const json = await res.json()
expect(json.data).toBeInstanceOf(Array)
})
const json = await res.json();
expect(json.data).toBeInstanceOf(Array);
});

test("create dataset", async ({ page }) => {
// Test API query
Expand All @@ -65,11 +68,11 @@ test("create dataset", async ({ page }) => {
slug: "test-dataset",
type: "chat",
}),
})
});

const json = await res.json()
expect(json.slug).toEqual("test-dataset")
})
const json = await res.json();
expect(json.slug).toEqual("test-dataset");
});

test("get dataset publicly via slug", async ({ page }) => {
// Test API query
Expand All @@ -81,8 +84,8 @@ test("get dataset publicly via slug", async ({ page }) => {
"Content-Type": "application/json",
Authorization: `Bearer ${publicKey!}`,
},
})
});

const json = await res.json()
expect(json.items).toBeInstanceOf(Array)
})
const json = await res.json();
expect(json.items).toBeInstanceOf(Array);
});
1 change: 1 addition & 0 deletions e2e/auth.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const authFile = "e2e/.auth/user.json";
test.beforeAll(async () => {
test.slow();
// Sometimes the teardown isn't called, so we need to clean up the database before running the tests
console.log("deleting org");
await deleteOrg();
});

Expand Down
Loading

0 comments on commit b39c490

Please sign in to comment.