style: 统一全仓代码格式
This commit is contained in:
1 parent
d811478d0f
commit
8033cabff9
30 files changed
+1183
-187
No files matched your search
@@ -2,7 +2,12 @@
|
||||
"name": "@personal-brand/api-client",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" } },
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc -p tsconfig.json",
|
||||
"lint": "eslint .",
|
||||
|
||||
@@ -7,7 +7,8 @@ function response(body: unknown, status = 200): FetchResponse {
|
||||
}
|
||||
|
||||
test("客户端发送认证头、查询参数和 JSON 请求体", async () => {
|
||||
const calls: Array<{ url: string; init?: { headers?: Record<string, string>; body?: string } }> = [];
|
||||
const calls: Array<{ url: string; init?: { headers?: Record<string, string>; body?: string } }> =
|
||||
[];
|
||||
const client = new ApiClient({
|
||||
baseUrl: "http://api.test/",
|
||||
token: "token-1",
|
||||
@@ -18,7 +19,10 @@ test("客户端发送认证头、查询参数和 JSON 请求体", async () => {
|
||||
});
|
||||
await client.listAdminBookings({ status: "received", unreadOnly: true, tagId: "tag/1" });
|
||||
await client.createAdminTag("重点");
|
||||
assert.equal(calls[0]?.url, "http://api.test/admin/bookings?status=received&unreadOnly=true&tagId=tag%2F1");
|
||||
assert.equal(
|
||||
calls[0]?.url,
|
||||
"http://api.test/admin/bookings?status=received&unreadOnly=true&tagId=tag%2F1",
|
||||
);
|
||||
assert.equal(calls[0]?.init?.headers?.authorization, "Bearer token-1");
|
||||
assert.equal(calls[1]?.init?.body, JSON.stringify({ name: "重点" }));
|
||||
});
|
||||
@@ -26,7 +30,11 @@ test("客户端发送认证头、查询参数和 JSON 请求体", async () => {
|
||||
test("客户端将统一错误响应转换为 ApiClientError", async () => {
|
||||
const client = new ApiClient({
|
||||
baseUrl: "http://api.test",
|
||||
fetcher: async () => response({ data: null, error: { code: "HTTP_401", message: "无权限" }, requestId: "req-1" }, 401),
|
||||
fetcher: async () =>
|
||||
response(
|
||||
{ data: null, error: { code: "HTTP_401", message: "无权限" }, requestId: "req-1" },
|
||||
401,
|
||||
),
|
||||
});
|
||||
await assert.rejects(
|
||||
() => client.getAdminUnreadCount(),
|
||||
|
||||
Reference in new issue
Block a user