/**
 * Your custom connector can be tested locally prior to publishing it.
 * In this file, we create a testing harness for our custom connector
 * and we invoke our data source to verify it returns expected results.
 *
 * To run just this set of unit tests, run "npm run test -- src/dataSources.test.ts"
 *
 * For more information on unit tests, see
 * https://prismatic.io/docs/custom-connectors/unit-testing/
 */

import { createConnection, createHarness } from "@prismatic-io/spectral/dist/testing";
import dotenv from "dotenv";
import myComponent from ".";
import { acmeApiKey } from "./connections";

dotenv.config({ path: ".env.testing" });

const harness = createHarness(myComponent);

const acmeConnection = createConnection(acmeApiKey, {
  baseUrl: process.env.ACME_ENDPOINT,
  apiKey: process.env.ACME_API_KEY,
});

describe("Test DataSource", () => {
  test("Test selectItem dropdown menu datasource", async () => {
    const { result } = await harness.dataSource("selectItem", {
      acmeConnection,
    });
    expect(result).toStrictEqual([
      { key: "1", label: "Widgets" },
      { key: "2", label: "Whatsits" },
      { key: "3", label: "Gadgets" },
    ]);
  });
});
