chore(P14-8): 完成运营化与验收收口

这个提交包含在:
2026-03-06 23:24:16 +08:00
父节点 b50b084100
当前提交 d8fff0ba21
共修改 28 个文件,包含 2820 行新增和 123 行删除
@@ -0,0 +1,99 @@
const featureFlags = require("../../../src/services/featureFlags");
describe("FeatureFlags Service", () => {
describe("normalizeOverrideMode", () => {
it("should default to force_off", () => {
expect(featureFlags.OVERRIDE_MODE_LIST.includes("force_off")).toBe(true);
// internal function tested indirectly or we can just mock config
});
});
describe("evaluateFeatureFlag", () => {
it("returns env_hard_off when config disables it globally", async () => {
const result = await featureFlags.evaluateFeatureFlag({
prisma: {},
config: { invoiceVerificationEnabled: false },
flagKey: featureFlags.FEATURE_FLAG_KEYS.invoiceVerification,
});
expect(result.enabled).toBe(false);
expect(result.reason).toBe("env_hard_off");
});
it("evaluates using db record when config enabled", async () => {
const mockPrisma = {
featureFlag: {
findUnique: vi.fn().mockResolvedValue({
flag_key: "invoice_verification",
override_mode: "inherit",
rollout_type: "global",
department_ids: [],
}),
},
};
const result = await featureFlags.evaluateFeatureFlag({
prisma: mockPrisma,
config: { invoiceVerificationEnabled: true },
flagKey: featureFlags.FEATURE_FLAG_KEYS.invoiceVerification,
});
expect(result.enabled).toBe(true);
expect(result.reason).toBe("env_inherit_global_on");
});
it("blocks if department is not in allowlist", async () => {
const mockPrisma = {
featureFlag: {
findUnique: vi.fn().mockResolvedValue({
flag_key: "invoice_verification",
override_mode: "inherit",
rollout_type: "department_allowlist",
department_ids: ["dep_A"],
}),
},
};
const result = await featureFlags.evaluateFeatureFlag({
prisma: mockPrisma,
config: { invoiceVerificationEnabled: true },
flagKey: featureFlags.FEATURE_FLAG_KEYS.invoiceVerification,
departmentId: "dep_B",
strictDepartment: true
});
expect(result.enabled).toBe(false);
expect(result.reason).toBe("department_not_allowed");
});
it("allows if department is in allowlist", async () => {
const mockPrisma = {
featureFlag: {
findUnique: vi.fn().mockResolvedValue({
flag_key: "invoice_verification",
override_mode: "inherit",
rollout_type: "department_allowlist",
department_ids: ["dep_A", "dep_B"],
}),
},
};
const result = await featureFlags.evaluateFeatureFlag({
prisma: mockPrisma,
config: { invoiceVerificationEnabled: true },
flagKey: featureFlags.FEATURE_FLAG_KEYS.invoiceVerification,
departmentId: "dep_B",
});
expect(result.enabled).toBe(true);
expect(result.reason).toBe("env_inherit_department_allowed");
});
});
describe("updateFeatureFlag", () => {
it("returns not_found for unknown flag", async () => {
const result = await featureFlags.updateFeatureFlag({}, { flagKey: "unknown" });
expect(result.status).toBe("not_found");
});
});
});