Keep a typed main kind from being ranked as the catalog other kind, and store that catalog kind on the finished Rule.
This commit is contained in:
1 parent
4b90bce006
commit
3e0181e4de
7 files changed
+174
-48
No files matched your search
@@ -1,5 +1,11 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { buildFacetQueryString } from "../../lib/create/buildFacetQueryString";
|
||||
import { TYPED_ORG_TYPE_MARKER } from "../../lib/create/deckTypes";
|
||||
import {
|
||||
groupAnswersFromCreateFlowState,
|
||||
groupAnswersFromRequestedFacets,
|
||||
} from "../../lib/create/groupAnswers";
|
||||
import { parseRequestedFacetsFromSearchParams } from "../../lib/server/validation/methodFacetsSchemas";
|
||||
|
||||
describe("buildFacetQueryString", () => {
|
||||
it("maps community chip ids to facet.* query params", () => {
|
||||
@@ -19,4 +25,36 @@ describe("buildFacetQueryString", () => {
|
||||
it("returns empty string when no selections", () => {
|
||||
expect(buildFacetQueryString({})).toBe("");
|
||||
});
|
||||
|
||||
it("keeps a catalog other kind from becoming the main kind when the main kind was typed", () => {
|
||||
const state = {
|
||||
selectedCommunitySizeIds: ["sixToTwelve"],
|
||||
selectedOrganizationTypeIds: ["custom-tenants-union", "workersCoop"],
|
||||
};
|
||||
const params = new URLSearchParams(buildFacetQueryString(state));
|
||||
expect(params.getAll("facet.orgType")).toEqual([
|
||||
TYPED_ORG_TYPE_MARKER,
|
||||
"workersCoop",
|
||||
]);
|
||||
const fromState = groupAnswersFromCreateFlowState(state);
|
||||
const fromQuery = groupAnswersFromRequestedFacets(
|
||||
parseRequestedFacetsFromSearchParams(params),
|
||||
);
|
||||
expect(fromQuery.mainKind).toBeNull();
|
||||
expect(fromQuery.otherKinds).toEqual(["workersCoop"]);
|
||||
expect(fromQuery.mainKind).toBe(fromState.mainKind);
|
||||
expect(fromQuery.otherKinds).toEqual(fromState.otherKinds);
|
||||
});
|
||||
|
||||
it("does not mark a catalog main kind", () => {
|
||||
const params = new URLSearchParams(
|
||||
buildFacetQueryString({
|
||||
selectedOrganizationTypeIds: ["workersCoop", "nonprofit"],
|
||||
}),
|
||||
);
|
||||
expect(params.getAll("facet.orgType")).toEqual([
|
||||
"workersCoop",
|
||||
"nonprofit",
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { TYPED_ORG_TYPE_MARKER } from "../../lib/create/deckTypes";
|
||||
import {
|
||||
flattenRequestedFacets,
|
||||
methodFacetsSchema,
|
||||
@@ -66,6 +67,17 @@ describe("parseRequestedFacetsFromSearchParams", () => {
|
||||
params.append("foo", "bar");
|
||||
expect(parseRequestedFacetsFromSearchParams(params)).toEqual({});
|
||||
});
|
||||
|
||||
it("keeps a typed main-kind marker ahead of catalog kinds", () => {
|
||||
const params = new URLSearchParams();
|
||||
params.append("facet.orgType", TYPED_ORG_TYPE_MARKER);
|
||||
params.append("facet.orgType", "not-a-kind");
|
||||
params.append("facet.orgType", "workersCoop");
|
||||
expect(parseRequestedFacetsFromSearchParams(params).orgType).toEqual([
|
||||
TYPED_ORG_TYPE_MARKER,
|
||||
"workersCoop",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("flattenRequestedFacets", () => {
|
||||
@@ -80,4 +92,12 @@ describe("flattenRequestedFacets", () => {
|
||||
{ group: "orgType", value: "dao" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("omits the typed main-kind marker from scoring pairs", () => {
|
||||
expect(
|
||||
flattenRequestedFacets({
|
||||
orgType: [TYPED_ORG_TYPE_MARKER, "workersCoop"],
|
||||
}),
|
||||
).toEqual([{ group: "orgType", value: "workersCoop" }]);
|
||||
});
|
||||
});
|
||||
@@ -33,4 +33,12 @@ describe("publishedRuleAnalyticsFromState", () => {
|
||||
}),
|
||||
).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" });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user