fix(test): clean up mock spies in platform.test.ts after each test
This commit is contained in:
1 parent
d447426d48
commit
a415bf38c3
1 file changed
+30
-20
@@ -1,4 +1,4 @@
|
||||
import { describe, expect, it, spyOn } from "bun:test";
|
||||
import { describe, expect, it, spyOn, afterEach } from "bun:test";
|
||||
import { handlePlatformCommand } from "./platform.js";
|
||||
import * as api from "../../domains/datalink/api.js";
|
||||
import * as services from "../../domains/datalink/services.js";
|
||||
@@ -7,6 +7,13 @@ import type { CliRuntime } from "../types.js";
|
||||
import type { CorpConfig } from "../../core/config/types.js";
|
||||
|
||||
describe("CLI - platform 命令与 record 动作", () => {
|
||||
let spies: ReturnType<typeof spyOn>[] = [];
|
||||
afterEach(() => {
|
||||
for (const spy of spies) {
|
||||
spy.mockRestore();
|
||||
}
|
||||
spies = [];
|
||||
});
|
||||
const mockCorp: CorpConfig = {
|
||||
id: "corp-1",
|
||||
name: "测试企业",
|
||||
@@ -67,10 +74,10 @@ describe("CLI - platform 命令与 record 动作", () => {
|
||||
});
|
||||
|
||||
it("records 正确解析嵌套 dataLink 的停启用状态和更新时间", async () => {
|
||||
spyOn(helpers, "createClientsForCorp").mockResolvedValue({ ekbClient: {} } as any);
|
||||
spyOn(services, "resolvePlatform").mockResolvedValue(mockPlatform as any);
|
||||
spyOn(services, "resolveEntity").mockResolvedValue(mockEntity as any);
|
||||
spyOn(api, "searchEntityRecords").mockResolvedValue({
|
||||
spies.push(spyOn(helpers, "createClientsForCorp").mockResolvedValue({ ekbClient: {} } as any));
|
||||
spies.push(spyOn(services, "resolvePlatform").mockResolvedValue(mockPlatform as any));
|
||||
spies.push(spyOn(services, "resolveEntity").mockResolvedValue(mockEntity as any));
|
||||
spies.push(spyOn(api, "searchEntityRecords").mockResolvedValue({
|
||||
total: 2,
|
||||
data: [
|
||||
{
|
||||
@@ -86,7 +93,7 @@ describe("CLI - platform 命令与 record 动作", () => {
|
||||
components: [],
|
||||
path: null,
|
||||
template: null,
|
||||
});
|
||||
}));
|
||||
|
||||
const res = await handlePlatformCommand(
|
||||
{ area: "platform", action: "records", args: ["platform-1", "entity-1"], options: {}, raw: [] },
|
||||
@@ -99,10 +106,10 @@ describe("CLI - platform 命令与 record 动作", () => {
|
||||
});
|
||||
|
||||
it("record get 获取记录详情", async () => {
|
||||
spyOn(helpers, "createClientsForCorp").mockResolvedValue({ ekbClient: {} } as any);
|
||||
spyOn(services, "resolvePlatform").mockResolvedValue(mockPlatform as any);
|
||||
spyOn(services, "resolveEntity").mockResolvedValue(mockEntity as any);
|
||||
spyOn(api, "getRecordDetail").mockResolvedValue({
|
||||
spies.push(spyOn(helpers, "createClientsForCorp").mockResolvedValue({ ekbClient: {} } as any));
|
||||
spies.push(spyOn(services, "resolvePlatform").mockResolvedValue(mockPlatform as any));
|
||||
spies.push(spyOn(services, "resolveEntity").mockResolvedValue(mockEntity as any));
|
||||
spies.push(spyOn(api, "getRecordDetail").mockResolvedValue({
|
||||
dataLink: {
|
||||
id: "r-1",
|
||||
name: "测试项目",
|
||||
@@ -112,7 +119,7 @@ describe("CLI - platform 命令与 record 动作", () => {
|
||||
updateTime: 12345679,
|
||||
form: { customField: "测试值" },
|
||||
},
|
||||
});
|
||||
}));
|
||||
|
||||
const res = await handlePlatformCommand(
|
||||
{ area: "platform", action: "record", args: ["get", "platform-1", "entity-1", "r-1"], options: {}, raw: [] },
|
||||
@@ -126,10 +133,11 @@ describe("CLI - platform 命令与 record 动作", () => {
|
||||
});
|
||||
|
||||
it("record toggle 切换停启用状态", async () => {
|
||||
spyOn(helpers, "createClientsForCorp").mockResolvedValue({ ekbClient: {} } as any);
|
||||
spyOn(services, "resolvePlatform").mockResolvedValue(mockPlatform as any);
|
||||
spyOn(services, "resolveEntity").mockResolvedValue(mockEntity as any);
|
||||
spies.push(spyOn(helpers, "createClientsForCorp").mockResolvedValue({ ekbClient: {} } as any));
|
||||
spies.push(spyOn(services, "resolvePlatform").mockResolvedValue(mockPlatform as any));
|
||||
spies.push(spyOn(services, "resolveEntity").mockResolvedValue(mockEntity as any));
|
||||
const toggleSpy = spyOn(api, "toggleRecordState").mockResolvedValue({ recordId: "r-1", active: true });
|
||||
spies.push(toggleSpy);
|
||||
|
||||
const res = await handlePlatformCommand(
|
||||
{ area: "platform", action: "record", args: ["toggle", "platform-1", "entity-1", "r-1"], options: {}, raw: [] },
|
||||
@@ -142,10 +150,11 @@ describe("CLI - platform 命令与 record 动作", () => {
|
||||
});
|
||||
|
||||
it("record edit 编辑字段", async () => {
|
||||
spyOn(helpers, "createClientsForCorp").mockResolvedValue({ ekbClient: {} } as any);
|
||||
spyOn(services, "resolvePlatform").mockResolvedValue(mockPlatform as any);
|
||||
spyOn(services, "resolveEntity").mockResolvedValue(mockEntity as any);
|
||||
spies.push(spyOn(helpers, "createClientsForCorp").mockResolvedValue({ ekbClient: {} } as any));
|
||||
spies.push(spyOn(services, "resolvePlatform").mockResolvedValue(mockPlatform as any));
|
||||
spies.push(spyOn(services, "resolveEntity").mockResolvedValue(mockEntity as any));
|
||||
const editSpy = spyOn(api, "editRecord").mockResolvedValue({ id: "r-1" } as any);
|
||||
spies.push(editSpy);
|
||||
|
||||
const res = await handlePlatformCommand(
|
||||
{
|
||||
@@ -172,10 +181,11 @@ describe("CLI - platform 命令与 record 动作", () => {
|
||||
});
|
||||
|
||||
it("record recompute 触发台账重算", async () => {
|
||||
spyOn(helpers, "createClientsForCorp").mockResolvedValue({ ekbClient: {} } as any);
|
||||
spyOn(services, "resolvePlatform").mockResolvedValue(mockPlatform as any);
|
||||
spyOn(services, "resolveEntity").mockResolvedValue(mockEntity as any);
|
||||
spies.push(spyOn(helpers, "createClientsForCorp").mockResolvedValue({ ekbClient: {} } as any));
|
||||
spies.push(spyOn(services, "resolvePlatform").mockResolvedValue(mockPlatform as any));
|
||||
spies.push(spyOn(services, "resolveEntity").mockResolvedValue(mockEntity as any));
|
||||
const recomputeSpy = spyOn(api, "recomputeRecordLedger").mockResolvedValue({ id: "ok" });
|
||||
spies.push(recomputeSpy);
|
||||
|
||||
const res = await handlePlatformCommand(
|
||||
{ area: "platform", action: "record", args: ["recompute", "platform-1", "entity-1", "r-1"], options: {}, raw: [] },
|
||||
|
||||
Reference in new issue
Block a user