Files
community-rule/tests/unit/publishedRuleAnalytics.test.ts
T

45 lines
1.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
publishedRuleAnalyticsFromDocument,
publishedRuleAnalyticsFromState,
} from "../../lib/create/publishedRuleAnalytics";
describe("publishedRuleAnalyticsFromDocument", () => {
it("reads place and a canonical group type", () => {
expect(
publishedRuleAnalyticsFromDocument({
communityLocation: " Boulder ",
orgType: "mutualAid",
}),
).toEqual({ communityLocation: "Boulder", orgType: "mutualAid" });
});
it("drops unknown types and empty place", () => {
expect(
publishedRuleAnalyticsFromDocument({
communityLocation: " ",
orgType: "not-a-kind",
}),
).toEqual({ communityLocation: null, orgType: null });
});
});
describe("publishedRuleAnalyticsFromState", () => {
it("takes place from the description field and the main group type", () => {
expect(
publishedRuleAnalyticsFromState({
communityLocation: "Denver",
selectedOrganizationTypeIds: ["mutualAid", "nonprofit"],
}),
).toEqual({ communityLocation: "Denver", orgType: "mutualAid" });
});
it("records a catalog other kind when the main kind was typed", () => {
expect(
publishedRuleAnalyticsFromState({
selectedOrganizationTypeIds: ["custom-tenants-union", "workersCoop"],
}),
).toEqual({ orgType: "workersCoop" });
});
});