Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

1.4 KB
Raw Blame
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();
  });
});