mirror of
https://github.com/formbricks/formbricks.git
synced 2026-05-22 02:56:28 -05:00
7d77ed04de
Remove sentiment, emotion, and the TopicsUnnested join from the Cube schema, web registry, AI prompt, audit-allowlist, and i18n keys — these required metadata enrichment that is no longer planned. Tests swap the removed string dimensions for sourceType to keep coverage intact. Add csatDissatisfiedCount and csatNeutralCount so dashboards can render the standard satisfied/neutral/dissatisfied distribution alongside the existing top-2-box metric. Expose field_label, field_group_label, language, value_boolean, value_date, created_at, and updated_at as Cube dimensions. fieldLabel and fieldGroupLabel unlock "group by question" and the matrix/ranking aggregations enabled by the recent composite-question PR; the others round out coverage of the underlying feedback_records columns. Extend FieldDefinition with a boolean type and matching filter operators.
99 lines
3.2 KiB
TypeScript
99 lines
3.2 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import {
|
|
FEEDBACK_FIELDS,
|
|
formatCubeColumnHeader,
|
|
getFieldById,
|
|
getFilterOperatorsForType,
|
|
} from "./schema-definition";
|
|
|
|
describe("schema-definition", () => {
|
|
describe("getFilterOperatorsForType", () => {
|
|
test("returns string operators", () => {
|
|
const ops = getFilterOperatorsForType("string");
|
|
expect(ops).toContain("equals");
|
|
expect(ops).toContain("contains");
|
|
expect(ops).toContain("set");
|
|
});
|
|
|
|
test("returns number operators", () => {
|
|
const ops = getFilterOperatorsForType("number");
|
|
expect(ops).toContain("gt");
|
|
expect(ops).toContain("gte");
|
|
expect(ops).toContain("lt");
|
|
expect(ops).toContain("lte");
|
|
});
|
|
|
|
test("returns time operators", () => {
|
|
const ops = getFilterOperatorsForType("time");
|
|
expect(ops).toContain("equals");
|
|
expect(ops).toContain("set");
|
|
});
|
|
});
|
|
|
|
describe("getFieldById", () => {
|
|
test("returns dimension by id", () => {
|
|
const field = getFieldById("FeedbackRecords.sourceType");
|
|
expect(field).toBeDefined();
|
|
expect(field?.label).toBe("Source Type");
|
|
expect(field?.type).toBe("string");
|
|
});
|
|
|
|
test("returns measure by id", () => {
|
|
const field = getFieldById("FeedbackRecords.count");
|
|
expect(field).toBeDefined();
|
|
expect(field?.label).toBe("Count");
|
|
});
|
|
|
|
test("returns undefined for unknown id", () => {
|
|
expect(getFieldById("Unknown.field")).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe("formatCubeColumnHeader", () => {
|
|
test("extracts granularity label for time dimension key", () => {
|
|
expect(formatCubeColumnHeader("FeedbackRecords.collectedAt.day")).toBe("Day");
|
|
expect(formatCubeColumnHeader("FeedbackRecords.collectedAt.month")).toBe("Month");
|
|
});
|
|
|
|
test("returns field label for known dimension/measure", () => {
|
|
expect(formatCubeColumnHeader("FeedbackRecords.sourceType")).toBe("Source Type");
|
|
expect(formatCubeColumnHeader("FeedbackRecords.count")).toBe("Count");
|
|
});
|
|
|
|
test("converts last segment to title case for unknown keys", () => {
|
|
expect(formatCubeColumnHeader("Some.camelCaseKey")).toBe("Camel Case Key");
|
|
});
|
|
|
|
test("handles key with no dots", () => {
|
|
expect(formatCubeColumnHeader("singleKey")).toBe("Single Key");
|
|
});
|
|
});
|
|
|
|
describe("FEEDBACK_FIELDS", () => {
|
|
test("has dimensions and measures", () => {
|
|
expect(FEEDBACK_FIELDS.dimensions.length).toBeGreaterThan(0);
|
|
expect(FEEDBACK_FIELDS.measures.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
test("exposes CSAT, CES, NPS and universal measures", () => {
|
|
const ids = FEEDBACK_FIELDS.measures.map((m) => m.id);
|
|
expect(ids).toEqual(
|
|
expect.arrayContaining([
|
|
"FeedbackRecords.count",
|
|
"FeedbackRecords.uniqueRespondents",
|
|
"FeedbackRecords.uniqueResponses",
|
|
"FeedbackRecords.npsScore",
|
|
"FeedbackRecords.npsAverage",
|
|
"FeedbackRecords.csatScore",
|
|
"FeedbackRecords.csatAverage",
|
|
"FeedbackRecords.csatSatisfiedCount",
|
|
"FeedbackRecords.csatCount",
|
|
"FeedbackRecords.cesAverage",
|
|
"FeedbackRecords.cesCount",
|
|
])
|
|
);
|
|
expect(ids).not.toContain("FeedbackRecords.averageScore");
|
|
});
|
|
});
|
|
});
|