The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
import { createMockCollection } from "metabase-types/api/mocks";
import { getWritableCollection } from "./utils";
describe("getWritableCollection", () => {
it("returns collection when can_write is true", () => {
const childCollection = createMockCollection({
id: 2,
type: "library-data",
can_write: true,
});
const rootCollection = createMockCollection({
id: 1,
children: [childCollection],
});
const result = getWritableCollection(rootCollection, "library-data");
expect(result).toEqual(childCollection);
});
it("returns undefined when can_write is false", () => {
const childCollection = createMockCollection({
id: 2,
type: "library-data",
can_write: false,
});
const rootCollection = createMockCollection({
id: 1,
children: [childCollection],
});
const result = getWritableCollection(rootCollection, "library-data");
expect(result).toBeUndefined();
});
it("returns undefined when collection type does not exist", () => {
const childCollection = createMockCollection({
id: 2,
type: "library-metrics",
can_write: true,
});
const rootCollection = createMockCollection({
id: 1,
children: [childCollection],
});
const result = getWritableCollection(rootCollection, "library-data");
expect(result).toBeUndefined();
});
});