feat: submit batches to status backend

This commit is contained in:
2026-04-23 17:41:44 +08:00
parent b3bcc2af45
commit 3e2d7b36f2
4 changed files with 79 additions and 6 deletions
+47 -2
View File
@@ -1,8 +1,13 @@
import { describe, expect, test, vi } from "vitest";
import { DEFAULT_BATCH_SUBMIT_BASE_URL } from "../src/shared/batch-submit-config";
import { createBatchSubmitClient } from "../src/shared/batch-submit-client";
describe("batch-submit-client", () => {
test("exports the default batch submit base url", () => {
expect(DEFAULT_BATCH_SUBMIT_BASE_URL).toBe("http://192.168.31.29:8083");
});
test("posts the batch payload with a Bearer token", async () => {
const sendMessage = vi.fn(async () => ({
ok: true,
@@ -12,7 +17,15 @@ describe("batch-submit-client", () => {
const fetchImpl = vi.fn(async () => ({
ok: true,
status: 200,
json: async () => ({ acceptedCount: 2, ok: true })
json: async () => ({
data: {
batch_id: "p7pdhhtde8kj-2026-04-22T12:30:00.000Z",
status: true,
talent_count: 1
},
msg: "",
success: true
})
}));
const client = createBatchSubmitClient({
@@ -32,7 +45,7 @@ describe("batch-submit-client", () => {
});
expect(fetchImpl).toHaveBeenCalledWith(
"http://127.0.0.1:4319/api/mock/batches",
"http://127.0.0.1:4319/api/v1/batch-status/batches",
expect.objectContaining({
body: JSON.stringify({
authors: [{ authorId: "111", authorName: "达人A" }],
@@ -52,6 +65,38 @@ describe("batch-submit-client", () => {
);
});
test("throws when the batch submit api returns success false", async () => {
const client = createBatchSubmitClient({
baseUrl: "http://127.0.0.1:4319",
fetchImpl: vi.fn(async () => ({
ok: true,
status: 200,
json: async () => ({
data: null,
msg: "duplicate batch id",
success: false
})
})),
sendMessage: vi.fn(async () => ({
ok: true,
type: "auth:token",
value: { accessToken: "abc123" }
}))
});
await expect(
client.submitBatch({
authors: [],
batchId: "批次A-2026-04-22T12:30:00.000Z",
batchName: "批次A",
createdAt: "2026-04-22T12:30:00.000Z",
creatorName: "王少卿",
logtoUserId: "p7pdhhtde8kj",
resource: "https://talent-search.intelligrow.cn"
})
).rejects.toThrow(/duplicate batch id/i);
});
test("throws on unauthorized responses", async () => {
const client = createBatchSubmitClient({
baseUrl: "http://127.0.0.1:4319",