映射和判断规则共用一个不可变版本,试算可以直接取已选查询的结果。 Co-authored-by: Cursor <cursoragent@cursor.com>
20 lines
988 B
TypeScript
20 lines
988 B
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
vi.mock("@watchman/api", () => ({ requestJson: vi.fn() }));
|
|
import { requestJson } from "@watchman/api";
|
|
import { activateMappingVersion, saveMappingVersion } from "./client";
|
|
|
|
const mocked = vi.mocked(requestJson);
|
|
describe("mapping version client", () => {
|
|
beforeEach(() => { mocked.mockReset(); mocked.mockResolvedValue({}); });
|
|
it("saves columns and the shared condition tree together", async () => {
|
|
await saveMappingVersion("m1", { columns: [], condition_tree: { column: "n", operator: "eq", value: 1 } });
|
|
const [, init] = mocked.mock.calls[0];
|
|
expect(JSON.parse(String((init as RequestInit).body))).toEqual({ columns: [], condition_tree: { column: "n", operator: "eq", value: 1 } });
|
|
});
|
|
it("activates without sending a new tree", async () => {
|
|
await activateMappingVersion("m1", 2);
|
|
const [, init] = mocked.mock.calls[0];
|
|
expect((init as RequestInit).body).toBeUndefined();
|
|
});
|
|
});
|