|
| 1 | +import { EnvironmentId, ORCHESTRATION_PROTOCOL_VERSION } from "@t3tools/contracts"; |
| 2 | +import { describe, expect, it } from "vite-plus/test"; |
| 3 | + |
| 4 | +import { orchestrationProtocolCompatibilityError } from "@t3tools/client-runtime/connection"; |
| 5 | + |
| 6 | +import { environmentStatusText } from "./environmentStatusText"; |
| 7 | + |
| 8 | +function compatibilityMessage(serverProtocolVersion: number): string { |
| 9 | + const error = orchestrationProtocolCompatibilityError({ |
| 10 | + environmentId: EnvironmentId.make("environment-preview"), |
| 11 | + label: "Studio Mac", |
| 12 | + platform: { os: "darwin", arch: "arm64" }, |
| 13 | + serverVersion: "1.0.0", |
| 14 | + orchestrationProtocolVersion: serverProtocolVersion, |
| 15 | + capabilities: { repositoryIdentity: true }, |
| 16 | + }); |
| 17 | + if (error === null) throw new Error("expected an incompatible protocol"); |
| 18 | + return error.message; |
| 19 | +} |
| 20 | + |
| 21 | +describe("environment status text", () => { |
| 22 | + it.each([ |
| 23 | + ["a newer server", ORCHESTRATION_PROTOCOL_VERSION + 1, "Update your app"], |
| 24 | + ["an older server", ORCHESTRATION_PROTOCOL_VERSION - 1, "Update T3 Code on Studio Mac"], |
| 25 | + ])("tells the user what to update for %s", (_, serverProtocolVersion, guidance) => { |
| 26 | + const text = environmentStatusText({ |
| 27 | + phase: "unsupported", |
| 28 | + error: compatibilityMessage(serverProtocolVersion), |
| 29 | + traceId: null, |
| 30 | + }); |
| 31 | + expect(text).toContain(guidance); |
| 32 | + }); |
| 33 | + |
| 34 | + it("falls back to the generic label when there is no detail", () => { |
| 35 | + expect(environmentStatusText({ phase: "unsupported", error: null, traceId: null })).toBe( |
| 36 | + "Client not supported", |
| 37 | + ); |
| 38 | + }); |
| 39 | +}); |
0 commit comments