feature/IO-3701-Harness-Replacement - Implement
This commit is contained in:
53
server/feature-flags/admin-payload.test.js
Normal file
53
server/feature-flags/admin-payload.test.js
Normal file
@@ -0,0 +1,53 @@
|
||||
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({});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user