Files
community-rule/tests/unit/copiedRuleDocument.test.ts

79 lines
2.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
findCopiedNameHit,
stripCopiedRuleDocument,
} from "../../lib/create/copiedRuleDocument";
describe("stripCopiedRuleDocument", () => {
it("drops name, description, photo, and save-email", () => {
const out = stripCopiedRuleDocument({
title: "Juniper Street Food Share",
communityContext: "A neighborhood share.",
communityAvatarUrl: "https://example.test/a.png",
communityAvatarFileName: "a.png",
communityLocation: "Boulder",
communitySaveEmail: "a@example.com",
sections: [
{
categoryName: "Values",
entries: [{ title: "Care", body: "We care." }],
},
],
});
expect(out.title).toBeUndefined();
expect(out.communityContext).toBeUndefined();
expect(out.communityAvatarUrl).toBeUndefined();
expect(out.communityAvatarFileName).toBeUndefined();
expect(out.communityLocation).toBeUndefined();
expect(out.communitySaveEmail).toBeUndefined();
expect(out.sections).toEqual([
{
categoryName: "Values",
entries: [{ title: "Care", body: "We care." }],
},
]);
});
});
describe("findCopiedNameHit", () => {
it("returns the first entry that still names the original group", () => {
expect(
findCopiedNameHit(
{
sections: [
{
categoryName: "Values",
entries: [
{
title: "Solidarity",
body: "Juniper Street Food Share members share food.",
},
],
},
],
},
"Juniper Street Food Share",
),
).toEqual({
categoryName: "Values",
entryTitle: "Solidarity",
});
});
it("returns null when the name is gone", () => {
expect(
findCopiedNameHit(
{
sections: [
{
categoryName: "Values",
entries: [{ title: "Care", body: "We care." }],
},
],
},
"Juniper Street Food Share",
),
).toBeNull();
});
});