103 lines
2.9 KiB
TypeScript
103 lines
2.9 KiB
TypeScript
import * as RelayClient from "@t3tools/shared/relayClient";
|
|
import { assert, it } from "@effect/vitest";
|
|
import * as Effect from "effect/Effect";
|
|
import * as Option from "effect/Option";
|
|
|
|
import { acquireRelayClientForLink } from "./cloud.ts";
|
|
|
|
const managedExecutable = {
|
|
status: "available",
|
|
executablePath: "/tmp/cloudflared",
|
|
source: "managed",
|
|
version: RelayClient.CLOUDFLARED_VERSION,
|
|
} as const;
|
|
|
|
it.effect("does not install the relay client when the user declines the managed download", () =>
|
|
Effect.gen(function* () {
|
|
let installCalls = 0;
|
|
const result = yield* acquireRelayClientForLink(
|
|
{
|
|
resolve: Effect.succeed({
|
|
status: "missing",
|
|
version: RelayClient.CLOUDFLARED_VERSION,
|
|
}),
|
|
install: Effect.sync(() => {
|
|
installCalls += 1;
|
|
return managedExecutable;
|
|
}),
|
|
installWithProgress: () =>
|
|
Effect.sync(() => {
|
|
installCalls += 1;
|
|
return managedExecutable;
|
|
}),
|
|
},
|
|
() => Effect.succeed(false),
|
|
() => Effect.void,
|
|
);
|
|
|
|
assert.isTrue(Option.isNone(result));
|
|
assert.equal(installCalls, 0);
|
|
}),
|
|
);
|
|
|
|
it.effect("installs the relay client after the user accepts the managed download", () =>
|
|
Effect.gen(function* () {
|
|
let installCalls = 0;
|
|
const progress: Array<string> = [];
|
|
const result = yield* acquireRelayClientForLink(
|
|
{
|
|
resolve: Effect.succeed({
|
|
status: "missing",
|
|
version: RelayClient.CLOUDFLARED_VERSION,
|
|
}),
|
|
install: Effect.sync(() => {
|
|
installCalls += 1;
|
|
return managedExecutable;
|
|
}),
|
|
installWithProgress: (report) =>
|
|
report({ type: "progress", stage: "downloading" }).pipe(
|
|
Effect.andThen(
|
|
Effect.sync(() => {
|
|
installCalls += 1;
|
|
return managedExecutable;
|
|
}),
|
|
),
|
|
),
|
|
},
|
|
() => Effect.succeed(true),
|
|
(event) =>
|
|
Effect.sync(() => {
|
|
if (event.type === "progress") {
|
|
progress.push(event.stage);
|
|
}
|
|
}),
|
|
);
|
|
|
|
assert.deepEqual(Option.getOrThrow(result), managedExecutable);
|
|
assert.equal(installCalls, 1);
|
|
assert.deepEqual(progress, ["downloading"]);
|
|
}),
|
|
);
|
|
|
|
it.effect("reuses an available relay client executable without prompting", () =>
|
|
Effect.gen(function* () {
|
|
let promptCalls = 0;
|
|
const result = yield* acquireRelayClientForLink(
|
|
{
|
|
resolve: Effect.succeed(managedExecutable),
|
|
install: Effect.die("unexpected install"),
|
|
installWithProgress: () => Effect.die("unexpected install"),
|
|
},
|
|
() =>
|
|
Effect.sync(() => {
|
|
promptCalls += 1;
|
|
return false;
|
|
}),
|
|
() => Effect.void,
|
|
);
|
|
|
|
assert.deepEqual(Option.getOrThrow(result), managedExecutable);
|
|
assert.equal(promptCalls, 0);
|
|
}),
|
|
);
|