import { describe, expect, it } from "vitest"; import { migrateLegacyCreateFlowState } from "../../lib/create/migrateLegacyCreateFlowState"; import { groupAnswersFromCreateFlowState } from "../../lib/create/groupAnswers"; describe("maturity and chip aliases", () => { it("scores one maturity answer and keeps a draft that stored several", () => { const draft = migrateLegacyCreateFlowState({ selectedMaturityIds: ["1", "2", "4"], selectedOrganizationTypeIds: ["1"], }); expect(draft.selectedMaturityIds).toEqual([ "earlyStage", "growthStage", "established", ]); expect(draft.selectedOrganizationTypeIds).toEqual(["workersCoop"]); const answers = groupAnswersFromCreateFlowState(draft); expect(answers.stage).toBe("earlyStage"); expect(answers.mainKind).toBe("workersCoop"); }); it("loads Enterprise and Larger organization as Established", () => { const fromId = migrateLegacyCreateFlowState({ selectedMaturityIds: ["4"], communityStructureChipSnapshots: { maturity: [ { id: "1", label: "Early stage", state: "unselected" }, { id: "2", label: "Growth stage", state: "unselected" }, { id: "3", label: "Established", state: "unselected" }, { id: "4", label: "Enterprise", state: "selected" }, ], }, }); expect(fromId.selectedMaturityIds).toEqual(["established"]); expect( fromId.communityStructureChipSnapshots?.maturity?.find( (row) => row.id === "established", )?.label, ).toBe("Established"); const fromLabel = migrateLegacyCreateFlowState({ selectedMaturityIds: ["larger-organization"], communityStructureChipSnapshots: { maturity: [ { id: "larger-organization", label: "Larger organization", state: "selected" }, ], }, }); expect(fromLabel.selectedMaturityIds).toEqual(["established"]); }); it("keeps the worker co-op pick when the label was Worker cooperative", () => { const draft = migrateLegacyCreateFlowState({ selectedOrganizationTypeIds: ["1"], communityStructureChipSnapshots: { organizationTypes: [ { id: "1", label: "Worker cooperative", state: "selected" }, ], }, }); expect(draft.selectedOrganizationTypeIds).toEqual(["workersCoop"]); expect( draft.communityStructureChipSnapshots?.organizationTypes?.find( (row) => row.id === "workersCoop", )?.label, ).toBe("Worker co-op"); }); });