接入登录图形验证码流程

This commit is contained in:
andy
2026-07-15 14:16:14 +07:00
parent 99a0a483ca
commit 25da8a718e
7 changed files with 263 additions and 16 deletions

66
src/api/loginSms.test.ts Normal file
View File

@@ -0,0 +1,66 @@
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import {
buildCaptchaImageUrl,
buildSendMobileCodeRequest,
resolveLoginErrorMessage,
} from "./loginSms.ts";
describe("login sms api helpers", () => {
it("builds send-code request with image captcha params and clientConfigId header", () => {
const result = buildSendMobileCodeRequest({
mobile: "+8613800000000",
clientConfigId: "6",
imageRandomStr: "captcha-random",
imageCode: "42",
});
assert.deepEqual(result.config, {
url: "/admin/platformUser/sendMobileCode/%2B8613800000000",
method: "get",
params: {
imageRandomStr: "captcha-random",
imageCode: "42",
},
});
assert.deepEqual(result.options, {
skipAuth: true,
headers: {
clientConfigId: "6",
},
});
});
it("builds captcha image url from api base url", () => {
assert.equal(
buildCaptchaImageUrl("captcha random", {
baseURL: "/ingress/",
cacheBust: 123,
}),
"/ingress/auth/code/image?randomStr=captcha+random&_t=123",
);
});
it("uses backend business error message before generic fallback", () => {
assert.equal(
resolveLoginErrorMessage(
{
kind: "business",
message: "图形验证码不合法",
},
"网络错误",
),
"图形验证码不合法",
);
assert.equal(
resolveLoginErrorMessage(
{
kind: "network",
message: "Network Error",
},
"网络错误",
),
"网络错误",
);
});
});