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

tests: Add Integration with starter-projects Endpoint and Vector Store Test #3599

Merged
merged 4 commits into from
Aug 28, 2024
Merged
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
1 change: 1 addition & 0 deletions src/frontend/src/controllers/API/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const URLs = {
VARIABLES: `variables`,
VALIDATE: `validate`,
CONFIG: `config`,
STARTER_PROJECTS: `starter-projects`,
} as const;

export function getURL(key: keyof typeof URLs, params: any = {}) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./use-get-starter-projects";
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { useDarkStore } from "@/stores/darkStore";
import { useQueryFunctionType } from "@/types/api";
import { api } from "../../api";
import { getURL } from "../../helpers/constants";
import { UseRequestProcessor } from "../../services/request-processor";

export interface IStarterProjectsDataArray {
name: string;
last_used_at: string | null;
total_uses: number;
is_active: boolean;
id: string;
api_key: string;
user_id: string;
created_at: string;
}

interface IApiQueryResponse {
total_count: number;
user_id: string;
api_keys: Array<IStarterProjectsDataArray>;
}

export const useGetStarterProjectsQuery: useQueryFunctionType<
undefined,
IApiQueryResponse
> = (_, options) => {
const { query } = UseRequestProcessor();

const getStarterProjectsFn = async () => {
return await api.get<IApiQueryResponse>(`${getURL("STARTER_PROJECTS")}/`);
};

const responseFn = async () => {
const { data } = await getStarterProjectsFn();
return data;
};

const queryResult = query(["useGetStarterProjectsQuery"], responseFn, {
...options,
});

return queryResult;
};
2 changes: 0 additions & 2 deletions src/frontend/src/pages/AppWrapperPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ export function AppWrapperPage() {

const [retryCount, setRetryCount] = useState(0);

console.log(healthCheckMaxRetries);

useEffect(() => {
const isServerBusy =
(error as AxiosError)?.response?.status === 503 ||
Expand Down
91 changes: 91 additions & 0 deletions src/frontend/tests/end-to-end/starter-projects.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
const { test, expect } = require("@playwright/test");

test("vector store from starter projects should have its connections and nodes on the flow", async ({
page,
request,
}) => {
const response = await request.get("/api/v1/starter-projects");
expect(response.status()).toBe(200);
const responseBody = await response.json();

const astraStarterProject = responseBody.find((project) => {
if (project.data.nodes) {
return project.data.nodes.some((node) => node.id.includes("Astra"));
}
});

await page.route("**/api/v1/flows/", async (route) => {
if (route.request().method() === "GET") {
try {
const response = await route.fetch();
const flowsData = await response.json();

const modifiedFlows = flowsData.map((flow) => {
if (flow.name === "Vector Store RAG" && flow.user_id === null) {
return {
...flow,
data: astraStarterProject?.data,
};
}
return flow;
});

const modifiedResponse = JSON.stringify(modifiedFlows);

route.fulfill({
status: response.status(),
headers: response.headers(),
body: modifiedResponse,
});
} catch (error) {
console.error("Error in route handler:", error);
}
} else {
// If not a GET request, continue without modifying
await route.continue();
}
});

await page.goto("/");

await page.waitForSelector('[data-testid="mainpage_title"]', {
timeout: 30000,
});

await page.waitForSelector('[id="new-project-btn"]', {
timeout: 30000,
});

let modalCount = 0;
try {
const modalTitleElement = await page?.getByTestId("modal-title");
if (modalTitleElement) {
modalCount = await modalTitleElement.count();
}
} catch (error) {
modalCount = 0;
}

while (modalCount === 0) {
await page.getByText("New Project", { exact: true }).click();
await page.waitForTimeout(3000);
modalCount = await page.getByTestId("modal-title")?.count();
}

await page.getByRole("heading", { name: "Vector Store RAG" }).click();
await page.waitForSelector('[title="fit view"]', {
timeout: 100000,
});

await page.getByTitle("fit view").click();
await page.getByTitle("zoom out").click();

const edges = await page.locator(".react-flow__edge-interaction").count();
const nodes = await page.getByTestId("div-generic-node").count();

const edgesFromServer = astraStarterProject?.data.edges.length;
const nodesFromServer = astraStarterProject?.data.nodes.length;

expect(edges).toBe(edgesFromServer);
expect(nodes).toBe(nodesFromServer);
});
Loading