Skip to content
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

test: logs exports #667

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
80 changes: 43 additions & 37 deletions e2e/api.spec.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,80 @@
import { test, expect } from "@playwright/test"
import { test, expect } from "@playwright/test";

let privateKey = null
let publicKey = null
let privateKey: string | null;
let publicKey: string | null = null;

// run tests one after another
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) => resp.url().includes("/regenerate-key"))
await page.waitForTimeout(1500);

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)
console.log(publicKey, await page.getByTestId("public-key").textContent());

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

test("private api /logs", async ({ page }) => {
// Test API query

if (!privateKey) return;

const res = await fetch(apiUrl + "/v1/runs", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-Key": privateKey!,
"X-API-Key": privateKey,
},
})
});

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

test("create dataset", async ({ page }) => {
// Test API query

if (!privateKey) return;

const res = await fetch(apiUrl + "/v1/datasets", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": privateKey!,
"X-API-Key": privateKey,
},
body: JSON.stringify({
slug: "test-dataset",
type: "chat",
}),
})
});

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

test("get dataset publicly via slug", async ({ page }) => {
// Test API query
Expand All @@ -79,10 +84,11 @@ test("get dataset publicly via slug", async ({ page }) => {
headers: {
// Use the legacy way to pass the API key (used in old SDKs)
"Content-Type": "application/json",
Authorization: `Bearer ${publicKey!}`,
Authorization: `Bearer ${publicKey}`,
},
})
});

const json = await res.json()
expect(json.items).toBeInstanceOf(Array)
})
const json = await res.json();
console.log(json);
expect(json.items).toBeInstanceOf(Array);
});
Loading
Loading