2026-04-27 11:03:04 +08:00
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
QIEHAO_REAL_NAME_AUTH_MESSAGE,
|
2026-04-30 18:15:20 +08:00
|
|
|
WANGYIHAO_DRAFT_SAVE_PARAMETER_MESSAGE,
|
|
|
|
|
WANGYIHAO_PUBLISH_CLICK_MESSAGE,
|
|
|
|
|
WANGYIHAO_TOKEN_MISSING_MESSAGE,
|
2026-04-27 11:03:04 +08:00
|
|
|
isQiehaoRealNameAuthError,
|
|
|
|
|
normalizePublisherErrorMessage,
|
|
|
|
|
normalizeQiehaoPublishErrorMessage,
|
2026-04-30 18:15:20 +08:00
|
|
|
normalizeWangyihaoPublishErrorMessage,
|
2026-04-27 11:03:04 +08:00
|
|
|
} from "./publisher-errors";
|
|
|
|
|
|
|
|
|
|
describe("publisher error normalization", () => {
|
|
|
|
|
it("normalizes Qiehao real-name authentication failures from raw platform text", () => {
|
|
|
|
|
expect(
|
|
|
|
|
normalizePublisherErrorMessage("type:business, code:-5022, msg:user is not real name authentication"),
|
|
|
|
|
).toBe(QIEHAO_REAL_NAME_AUTH_MESSAGE);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("recognizes Qiehao real-name authentication failures by business code", () => {
|
|
|
|
|
expect(isQiehaoRealNameAuthError("publish rejected", -5022)).toBe(true);
|
|
|
|
|
expect(normalizeQiehaoPublishErrorMessage("publish rejected", -5022)).toBe(QIEHAO_REAL_NAME_AUTH_MESSAGE);
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-30 18:15:20 +08:00
|
|
|
it("normalizes Wangyihao token missing failures", () => {
|
|
|
|
|
expect(normalizePublisherErrorMessage("wangyihao_token_missing")).toBe(WANGYIHAO_TOKEN_MISSING_MESSAGE);
|
|
|
|
|
expect(normalizeWangyihaoPublishErrorMessage("Error: wangyihao_token_missing")).toBe(
|
|
|
|
|
WANGYIHAO_TOKEN_MISSING_MESSAGE,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("normalizes Wangyihao draft parameter failures", () => {
|
|
|
|
|
expect(normalizePublisherErrorMessage("wangyihao_draft_save_failed:wangyihao_error_100002")).toBe(
|
|
|
|
|
WANGYIHAO_DRAFT_SAVE_PARAMETER_MESSAGE,
|
|
|
|
|
);
|
|
|
|
|
expect(normalizeWangyihaoPublishErrorMessage("wangyihao_draft_save_failed:参数错误")).toBe(
|
|
|
|
|
WANGYIHAO_DRAFT_SAVE_PARAMETER_MESSAGE,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("normalizes Wangyihao publish click failures", () => {
|
|
|
|
|
expect(normalizePublisherErrorMessage("wangyihao_publish_click_failed")).toBe(
|
|
|
|
|
WANGYIHAO_PUBLISH_CLICK_MESSAGE,
|
|
|
|
|
);
|
|
|
|
|
expect(normalizeWangyihaoPublishErrorMessage("wangyihao_publish_click_failed:未找到发布按钮")).toBe(
|
|
|
|
|
WANGYIHAO_PUBLISH_CLICK_MESSAGE,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-27 11:03:04 +08:00
|
|
|
it("leaves unknown publisher errors unchanged", () => {
|
|
|
|
|
expect(normalizePublisherErrorMessage("qiehao_publish_failed")).toBe("qiehao_publish_failed");
|
|
|
|
|
});
|
|
|
|
|
});
|