58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
import {
|
|
getOpenClawClientErrorMessage,
|
|
isOpenClawAuthRequiredError,
|
|
OPENCLAW_AUTH_REQUIRED_CODE,
|
|
OPENCLAW_AUTH_REQUIRED_MESSAGE,
|
|
OPENCLAW_FORBIDDEN_MESSAGE,
|
|
OPENCLAW_UPGRADE_RETRY_MESSAGE,
|
|
} from "@/lib/openclaw-chat/errors";
|
|
|
|
test.describe("OpenClaw client error messages", () => {
|
|
test("reports a signed-out website session as a login error", () => {
|
|
const response = {
|
|
code: OPENCLAW_AUTH_REQUIRED_CODE,
|
|
error: OPENCLAW_AUTH_REQUIRED_MESSAGE,
|
|
};
|
|
expect(getOpenClawClientErrorMessage(401, response)).toBe(
|
|
OPENCLAW_AUTH_REQUIRED_MESSAGE
|
|
);
|
|
expect(isOpenClawAuthRequiredError(401, response)).toBe(true);
|
|
});
|
|
|
|
test("supports the legacy website unauthorized response", () => {
|
|
expect(
|
|
getOpenClawClientErrorMessage(401, { error: "Unauthorized" })
|
|
).toBe(OPENCLAW_AUTH_REQUIRED_MESSAGE);
|
|
});
|
|
|
|
test("does not confuse an upstream 401 with a signed-out website session", () => {
|
|
const response = {
|
|
code: "UPSTREAM_AUTH_ERROR",
|
|
error: OPENCLAW_UPGRADE_RETRY_MESSAGE,
|
|
};
|
|
expect(getOpenClawClientErrorMessage(401, response)).toBe(
|
|
OPENCLAW_UPGRADE_RETRY_MESSAGE
|
|
);
|
|
expect(isOpenClawAuthRequiredError(401, response)).toBe(false);
|
|
});
|
|
|
|
test("reports a forbidden conversation separately", () => {
|
|
expect(getOpenClawClientErrorMessage(403, { error: "Forbidden" })).toBe(
|
|
OPENCLAW_FORBIDDEN_MESSAGE
|
|
);
|
|
});
|
|
|
|
test("preserves actionable client validation errors", () => {
|
|
expect(
|
|
getOpenClawClientErrorMessage(400, { error: "请输入问题或上传附件" })
|
|
).toBe("请输入问题或上传附件");
|
|
});
|
|
|
|
test("uses the upgrade message for service failures", () => {
|
|
expect(getOpenClawClientErrorMessage(503, null)).toBe(
|
|
OPENCLAW_UPGRADE_RETRY_MESSAGE
|
|
);
|
|
});
|
|
});
|