// Run with: npm run test:mapping import test from "node:test"; import assert from "node:assert/strict"; import { mapCustomFieldRow } from "./staff-field-mapping.mjs"; const baseRow = { name: "Sample", label: "Sample", data_type: "String", html_type: "Text", option_group_id: null, weight: 1, "custom_group_id.name": "Stage_1", "custom_group_id.title": "Stage 1", }; test("Money → currency", () => { const d = mapCustomFieldRow({ ...baseRow, data_type: "Money" }); assert.equal(d.render, "currency"); }); test("Date + Select Date → date", () => { const d = mapCustomFieldRow({ ...baseRow, data_type: "Date", html_type: "Select Date" }); assert.equal(d.render, "date"); }); test("Timestamp → datetime", () => { const d = mapCustomFieldRow({ ...baseRow, data_type: "Timestamp" }); assert.equal(d.render, "datetime"); }); test("Boolean → boolean", () => { const d = mapCustomFieldRow({ ...baseRow, data_type: "Boolean" }); assert.equal(d.render, "boolean"); }); test("File → file", () => { const d = mapCustomFieldRow({ ...baseRow, data_type: "File" }); assert.equal(d.render, "file"); }); test("Memo → longtext", () => { const d = mapCustomFieldRow({ ...baseRow, data_type: "Memo" }); assert.equal(d.render, "longtext"); }); test("Select with option_group_id → select", () => { const d = mapCustomFieldRow({ ...baseRow, data_type: "String", html_type: "Select", option_group_id: 140, }); assert.equal(d.render, "select"); assert.equal(d.optionGroupId, 140); }); test("Radio with option_group_id → select", () => { const d = mapCustomFieldRow({ ...baseRow, html_type: "Radio", option_group_id: 140 }); assert.equal(d.render, "select"); }); test("CheckBox with option_group_id → multiselect", () => { const d = mapCustomFieldRow({ ...baseRow, html_type: "CheckBox", option_group_id: 140 }); assert.equal(d.render, "multiselect"); }); test("Int without options → number", () => { const d = mapCustomFieldRow({ ...baseRow, data_type: "Int", html_type: "Text" }); assert.equal(d.render, "number"); }); test("Float without options → number", () => { const d = mapCustomFieldRow({ ...baseRow, data_type: "Float", html_type: "Text" }); assert.equal(d.render, "number"); }); test("Unknown combo → text fallback", () => { const d = mapCustomFieldRow({ ...baseRow, data_type: "WeirdNewType", html_type: "Mystery" }); assert.equal(d.render, "text"); }); test("Food_Co_op_Organizing group → org kind", () => { const d = mapCustomFieldRow({ ...baseRow, "custom_group_id.name": "Food_Co_op_Organizing", "custom_group_id.title": "Org", }); assert.equal(d.groupKind, "org"); }); test("Stage_1 group → activity kind", () => { const d = mapCustomFieldRow({ ...baseRow, "custom_group_id.name": "Stage_1" }); assert.equal(d.groupKind, "activity"); }); test("civiField is built from group + name", () => { const d = mapCustomFieldRow({ ...baseRow, name: "Foo", "custom_group_id.name": "Stage_2" }); assert.equal(d.civiField, "Stage_2.Foo"); });