54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
import { describe, expect, it } from "vitest";
|
|
import { createRequire } from "module";
|
|
|
|
const require = createRequire(import.meta.url);
|
|
const {
|
|
sanitizeFeatureFlagCreatePayload,
|
|
sanitizeFeatureFlagUpdatePayload
|
|
} = require("./admin-payload");
|
|
|
|
describe("feature flag admin payload sanitizing", () => {
|
|
it("keeps only editable create fields and trims stable text keys", () => {
|
|
expect(
|
|
sanitizeFeatureFlagCreatePayload({
|
|
name: " TEST_FLAG ",
|
|
description: "Manual test flag",
|
|
default_treatment: " variant-a ",
|
|
active: false,
|
|
created_at: "2026-05-19T00:00:00.000Z",
|
|
bodyshop_feature_flags_aggregate: { aggregate: { count: 3 } }
|
|
})
|
|
).toEqual({
|
|
name: "TEST_FLAG",
|
|
description: "Manual test flag",
|
|
default_treatment: "variant-a",
|
|
active: false
|
|
});
|
|
});
|
|
|
|
it("strips name from update payloads so flag keys cannot be renamed", () => {
|
|
expect(
|
|
sanitizeFeatureFlagUpdatePayload({
|
|
name: "Renamed_Flag",
|
|
description: null,
|
|
default_treatment: " on ",
|
|
active: true,
|
|
updated_at: "2026-05-19T00:00:00.000Z"
|
|
})
|
|
).toEqual({
|
|
description: null,
|
|
default_treatment: "on",
|
|
active: true
|
|
});
|
|
});
|
|
|
|
it("returns an empty update payload when no editable fields are present", () => {
|
|
expect(
|
|
sanitizeFeatureFlagUpdatePayload({
|
|
name: "Only_Name",
|
|
created_at: "2026-05-19T00:00:00.000Z"
|
|
})
|
|
).toEqual({});
|
|
});
|
|
});
|