mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-29 09:02:02 +03:00
perf(test): consolidate browser profile CRUD checks
This commit is contained in:
@@ -331,117 +331,80 @@ describe("profile CRUD endpoints", () => {
|
|||||||
await stopBrowserControlServer();
|
await stopBrowserControlServer();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("POST /profiles/create returns 400 for missing name", async () => {
|
it("validates profile create/delete endpoints", async () => {
|
||||||
await startBrowserControlServerFromConfig();
|
await startBrowserControlServerFromConfig();
|
||||||
const base = `http://127.0.0.1:${testPort}`;
|
const base = `http://127.0.0.1:${testPort}`;
|
||||||
|
|
||||||
const result = await realFetch(`${base}/profiles/create`, {
|
const createMissingName = await realFetch(`${base}/profiles/create`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify({}),
|
||||||
});
|
});
|
||||||
expect(result.status).toBe(400);
|
expect(createMissingName.status).toBe(400);
|
||||||
const body = (await result.json()) as { error: string };
|
const createMissingNameBody = (await createMissingName.json()) as { error: string };
|
||||||
expect(body.error).toContain("name is required");
|
expect(createMissingNameBody.error).toContain("name is required");
|
||||||
});
|
|
||||||
|
|
||||||
it("POST /profiles/create returns 400 for invalid name format", async () => {
|
const createInvalidName = await realFetch(`${base}/profiles/create`, {
|
||||||
await startBrowserControlServerFromConfig();
|
|
||||||
const base = `http://127.0.0.1:${testPort}`;
|
|
||||||
|
|
||||||
const result = await realFetch(`${base}/profiles/create`, {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ name: "Invalid Name!" }),
|
body: JSON.stringify({ name: "Invalid Name!" }),
|
||||||
});
|
});
|
||||||
expect(result.status).toBe(400);
|
expect(createInvalidName.status).toBe(400);
|
||||||
const body = (await result.json()) as { error: string };
|
const createInvalidNameBody = (await createInvalidName.json()) as { error: string };
|
||||||
expect(body.error).toContain("invalid profile name");
|
expect(createInvalidNameBody.error).toContain("invalid profile name");
|
||||||
});
|
|
||||||
|
|
||||||
it("POST /profiles/create returns 409 for duplicate name", async () => {
|
const createDuplicate = await realFetch(`${base}/profiles/create`, {
|
||||||
await startBrowserControlServerFromConfig();
|
|
||||||
const base = `http://127.0.0.1:${testPort}`;
|
|
||||||
|
|
||||||
// "openclaw" already exists as the default profile
|
|
||||||
const result = await realFetch(`${base}/profiles/create`, {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ name: "openclaw" }),
|
body: JSON.stringify({ name: "openclaw" }),
|
||||||
});
|
});
|
||||||
expect(result.status).toBe(409);
|
expect(createDuplicate.status).toBe(409);
|
||||||
const body = (await result.json()) as { error: string };
|
const createDuplicateBody = (await createDuplicate.json()) as { error: string };
|
||||||
expect(body.error).toContain("already exists");
|
expect(createDuplicateBody.error).toContain("already exists");
|
||||||
});
|
|
||||||
|
|
||||||
it("POST /profiles/create accepts cdpUrl for remote profiles", async () => {
|
const createRemote = await realFetch(`${base}/profiles/create`, {
|
||||||
await startBrowserControlServerFromConfig();
|
|
||||||
const base = `http://127.0.0.1:${testPort}`;
|
|
||||||
|
|
||||||
const result = await realFetch(`${base}/profiles/create`, {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ name: "remote", cdpUrl: "http://10.0.0.42:9222" }),
|
body: JSON.stringify({ name: "remote", cdpUrl: "http://10.0.0.42:9222" }),
|
||||||
});
|
});
|
||||||
expect(result.status).toBe(200);
|
expect(createRemote.status).toBe(200);
|
||||||
const body = (await result.json()) as {
|
const createRemoteBody = (await createRemote.json()) as {
|
||||||
profile?: string;
|
profile?: string;
|
||||||
cdpUrl?: string;
|
cdpUrl?: string;
|
||||||
isRemote?: boolean;
|
isRemote?: boolean;
|
||||||
};
|
};
|
||||||
expect(body.profile).toBe("remote");
|
expect(createRemoteBody.profile).toBe("remote");
|
||||||
expect(body.cdpUrl).toBe("http://10.0.0.42:9222");
|
expect(createRemoteBody.cdpUrl).toBe("http://10.0.0.42:9222");
|
||||||
expect(body.isRemote).toBe(true);
|
expect(createRemoteBody.isRemote).toBe(true);
|
||||||
});
|
|
||||||
|
|
||||||
it("POST /profiles/create returns 400 for invalid cdpUrl", async () => {
|
const createBadRemote = await realFetch(`${base}/profiles/create`, {
|
||||||
await startBrowserControlServerFromConfig();
|
|
||||||
const base = `http://127.0.0.1:${testPort}`;
|
|
||||||
|
|
||||||
const result = await realFetch(`${base}/profiles/create`, {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ name: "badremote", cdpUrl: "ws://bad" }),
|
body: JSON.stringify({ name: "badremote", cdpUrl: "ws://bad" }),
|
||||||
});
|
});
|
||||||
expect(result.status).toBe(400);
|
expect(createBadRemote.status).toBe(400);
|
||||||
const body = (await result.json()) as { error: string };
|
const createBadRemoteBody = (await createBadRemote.json()) as { error: string };
|
||||||
expect(body.error).toContain("cdpUrl");
|
expect(createBadRemoteBody.error).toContain("cdpUrl");
|
||||||
});
|
|
||||||
|
|
||||||
it("DELETE /profiles/:name returns 404 for non-existent profile", async () => {
|
const deleteMissing = await realFetch(`${base}/profiles/nonexistent`, {
|
||||||
await startBrowserControlServerFromConfig();
|
|
||||||
const base = `http://127.0.0.1:${testPort}`;
|
|
||||||
|
|
||||||
const result = await realFetch(`${base}/profiles/nonexistent`, {
|
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
});
|
});
|
||||||
expect(result.status).toBe(404);
|
expect(deleteMissing.status).toBe(404);
|
||||||
const body = (await result.json()) as { error: string };
|
const deleteMissingBody = (await deleteMissing.json()) as { error: string };
|
||||||
expect(body.error).toContain("not found");
|
expect(deleteMissingBody.error).toContain("not found");
|
||||||
});
|
|
||||||
|
|
||||||
it("DELETE /profiles/:name returns 400 for default profile deletion", async () => {
|
const deleteDefault = await realFetch(`${base}/profiles/openclaw`, {
|
||||||
await startBrowserControlServerFromConfig();
|
|
||||||
const base = `http://127.0.0.1:${testPort}`;
|
|
||||||
|
|
||||||
// openclaw is the default profile
|
|
||||||
const result = await realFetch(`${base}/profiles/openclaw`, {
|
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
});
|
});
|
||||||
expect(result.status).toBe(400);
|
expect(deleteDefault.status).toBe(400);
|
||||||
const body = (await result.json()) as { error: string };
|
const deleteDefaultBody = (await deleteDefault.json()) as { error: string };
|
||||||
expect(body.error).toContain("cannot delete the default profile");
|
expect(deleteDefaultBody.error).toContain("cannot delete the default profile");
|
||||||
});
|
|
||||||
|
|
||||||
it("DELETE /profiles/:name returns 400 for invalid name format", async () => {
|
const deleteInvalid = await realFetch(`${base}/profiles/Invalid-Name!`, {
|
||||||
await startBrowserControlServerFromConfig();
|
|
||||||
const base = `http://127.0.0.1:${testPort}`;
|
|
||||||
|
|
||||||
const result = await realFetch(`${base}/profiles/Invalid-Name!`, {
|
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
});
|
});
|
||||||
expect(result.status).toBe(400);
|
expect(deleteInvalid.status).toBe(400);
|
||||||
const body = (await result.json()) as { error: string };
|
const deleteInvalidBody = (await deleteInvalid.json()) as { error: string };
|
||||||
expect(body.error).toContain("invalid profile name");
|
expect(deleteInvalidBody.error).toContain("invalid profile name");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user