/**
 * 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/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 ?? acmeApiKey.inputs.baseUrl.default,
  apiKey: process.env.ACME_API_KEY ?? "",
});

describe("Test DataSource", () => {
  test("Test selectPost dropdown menu datasource", async () => {
    const { result } = await harness.dataSource("selectPost", {
      acmeConnection,
    });
    expect(result).toHaveLength(100);
    expect(result).toEqual(expect.arrayContaining([{ key: "1", label: expect.any(String) }]));
  });
});
