sailfork / t3code-github / .repos/ alchemy-effect/ packages/ integration-tests/ test/ Cloudflare/ Tunnel/ Configuration.test.ts

import * as Cloudflare from "@alchemy.run/cloudflare";
import { describe, expect } from "@alchemy.run/test";
import * as Test from "@alchemy.run/test/Alchemy";
import * as Provider from "alchemy/Provider";
import * as Effect from "effect/Effect";
import { MinimumLogLevel } from "effect/References";
const { test } = Test.make({ providers: Cloudflare.providers() });

const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");

describe(
  "Tunnel Configuration",
  { tags: ["provider:cloudflare", "provider:cloudflare:tunnel", "live"] },
  () => {
    // Canonical `list()` test (parent fan-out singleton): the configuration is a
    // per-tunnel document with no account-wide enumeration API, so `list()`
    // enumerates every cfd_tunnel in the account and reads each tunnel's config.
    // Deploy a tunnel + configuration, then assert the deployed tunnel appears in
    // the listed result.
    test.provider(
      "list enumerates configurations across all tunnels",
      (stack) =>
        Effect.gen(function* () {
          yield* stack.destroy();

          const deployed = yield* stack.deploy(
            Effect.gen(function* () {
              const tunnel = yield* Cloudflare.Tunnel.Tunnel("ListTunnel", {
                configSrc: "cloudflare",
              });
              const config = yield* Cloudflare.Tunnel.Configuration("ListConfig", {
                tunnelId: tunnel.tunnelId,
                ingress: [
                  { hostname: "config-list-test.internal", service: "http://localhost:8080" },
                ],
              });
              return { tunnelId: tunnel.tunnelId, config };
            }),
          );

          const provider = yield* Provider.findProvider(Cloudflare.Tunnel.Configuration);
          const all = yield* provider.list();

          expect(all.some((c) => c.tunnelId === deployed.tunnelId)).toBe(true);

          yield* stack.destroy();
        }).pipe(logLevel),
      { timeout: 180_000 },
    );
  },
);