|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { buildDeploymentS2Client, deploymentS2ClientOptions } from "~/v3/s2ClientConfig"; |
| 3 | + |
| 4 | +const BASIN = "trigger-local"; |
| 5 | + |
| 6 | +describe("buildDeploymentS2Client", () => { |
| 7 | + // The SDK resolves an endpoints key with undefined members to the same hosted URLs, so nothing |
| 8 | + // on the built client distinguishes the two calls. Assert on the options instead. |
| 9 | + it("hands the SDK no endpoints key at all when no endpoint is configured", () => { |
| 10 | + expect(deploymentS2ClientOptions({ accessToken: "token" })).toEqual({ accessToken: "token" }); |
| 11 | + expect(deploymentS2ClientOptions({ accessToken: "token" })).not.toHaveProperty("endpoints"); |
| 12 | + }); |
| 13 | + |
| 14 | + it("hands the SDK one endpoint for both hosts when configured", () => { |
| 15 | + expect( |
| 16 | + deploymentS2ClientOptions({ accessToken: "token", endpoint: "http://localhost:4566" }) |
| 17 | + ).toEqual({ |
| 18 | + accessToken: "token", |
| 19 | + endpoints: { account: "http://localhost:4566", basin: "http://localhost:4566" }, |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | + it("still resolves the SDK's hosted defaults when no endpoint is configured", () => { |
| 24 | + const client = buildDeploymentS2Client({ accessToken: "token" }); |
| 25 | + |
| 26 | + expect(client.endpoints.accountBaseUrl()).toBe("https://a.s2.dev/v1"); |
| 27 | + expect(client.endpoints.basinBaseUrl(BASIN)).toBe(`https://${BASIN}.b.s2.dev/v1`); |
| 28 | + expect(client.endpoints.includeBasinHeader).toBe(false); |
| 29 | + }); |
| 30 | + |
| 31 | + it("points both the account and basin hosts at a configured endpoint", () => { |
| 32 | + const client = buildDeploymentS2Client({ |
| 33 | + accessToken: "token", |
| 34 | + endpoint: "http://localhost:4566", |
| 35 | + }); |
| 36 | + |
| 37 | + expect(client.endpoints.accountBaseUrl()).toBe("http://localhost:4566/v1"); |
| 38 | + expect(client.endpoints.basinBaseUrl(BASIN)).toBe("http://localhost:4566/v1"); |
| 39 | + expect(client.endpoints.includeBasinHeader).toBe(true); |
| 40 | + }); |
| 41 | + |
| 42 | + // A split configuration would send the access token to the hosted service while the operator |
| 43 | + // believed the client was entirely local, so one value has to drive both hosts. |
| 44 | + it("never leaves one host hosted while the other is overridden", () => { |
| 45 | + const client = buildDeploymentS2Client({ |
| 46 | + accessToken: "token", |
| 47 | + endpoint: "http://localhost:4566", |
| 48 | + }); |
| 49 | + |
| 50 | + expect(client.endpoints.accountBaseUrl()).not.toContain("s2.dev"); |
| 51 | + expect(client.endpoints.basinBaseUrl(BASIN)).not.toContain("s2.dev"); |
| 52 | + }); |
| 53 | +}); |
0 commit comments