Skip to content

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

1.0 KB
Raw Blame
import fetchMock from "fetch-mock";

import type { GdrivePayload } from "metabase-types/api";

export function setupGdriveGetFolderEndpoint({
  errorCode,
  ...gdrivePayload
}: Partial<GdrivePayload> & {
  errorCode?: number;
} = {}) {
  fetchMock.removeRoute("gdrive-get-folder");

  if (errorCode) {
    fetchMock.get("path:/api/ee/gsheets/connection", errorCode, {
      name: "gdrive-get-folder",
    });
    return;
  }
  fetchMock.get(
    "path:/api/ee/gsheets/connection",
    () => {
      return { ...gdrivePayload, _test: "" };
    },
    { name: "gdrive-get-folder" },
  );
}

export function setupGdriveServiceAccountEndpoint(
  email = "[email protected]",
) {
  fetchMock.get("path:/api/ee/gsheets/service-account", () => {
    return { email };
  });
}

export function setupGdrivePostFolderEndpoint() {
  fetchMock.post("path:/api/ee/gsheets/connection", { status: 202 });
}

export function setupGdriveSyncEndpoint() {
  fetchMock.post("path:/api/ee/gsheets/connection/sync", () => {
    return { db_id: 1 };
  });
}