@prosopo/load-balancer 2.10.42 → 2.10.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,76 @@
1
+ // Copyright 2021-2026 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ import { afterEach, describe, expect, it } from "vitest";
16
+ import {
17
+ DEFAULT_DEVELOPMENT_PROVIDER_URL,
18
+ getDevelopmentProviderUrl,
19
+ readDevelopmentProviderUrlOverride,
20
+ } from "../developmentProviderUrl.js";
21
+
22
+ const ENV_KEY = "PROSOPO_PROVIDER_URL_DEVELOPMENT";
23
+ const original: string | undefined = process.env[ENV_KEY];
24
+
25
+ afterEach(() => {
26
+ if (original === undefined) delete process.env[ENV_KEY];
27
+ else process.env[ENV_KEY] = original;
28
+ });
29
+
30
+ describe("the development provider url", () => {
31
+ it("is localhost when nothing overrides it", () => {
32
+ expect(getDevelopmentProviderUrl(undefined)).toBe("https://localhost:9229");
33
+ expect(DEFAULT_DEVELOPMENT_PROVIDER_URL).toBe("https://localhost:9229");
34
+ });
35
+
36
+ it("is the override when one is set", () => {
37
+ // The case this exists for: a phone loading the demo over the LAN cannot
38
+ // reach the provider via `localhost`, which resolves to the phone.
39
+ expect(getDevelopmentProviderUrl("https://192.0.2.10:9229")).toBe(
40
+ "https://192.0.2.10:9229",
41
+ );
42
+ });
43
+
44
+ it("drops a trailing slash so the url composes with /healthz", () => {
45
+ expect(getDevelopmentProviderUrl("https://192.0.2.10:9229/")).toBe(
46
+ "https://192.0.2.10:9229",
47
+ );
48
+ });
49
+
50
+ it("falls back rather than yielding an empty url", () => {
51
+ for (const blank of ["", " ", undefined]) {
52
+ expect(getDevelopmentProviderUrl(blank)).toBe(
53
+ DEFAULT_DEVELOPMENT_PROVIDER_URL,
54
+ );
55
+ }
56
+ });
57
+ });
58
+
59
+ describe("reading the override", () => {
60
+ it("reads the environment variable", () => {
61
+ process.env[ENV_KEY] = "https://198.51.100.7:9229";
62
+ expect(readDevelopmentProviderUrlOverride()).toBe(
63
+ "https://198.51.100.7:9229",
64
+ );
65
+ });
66
+
67
+ it("is undefined when the variable is unset", () => {
68
+ delete process.env[ENV_KEY];
69
+ expect(readDevelopmentProviderUrlOverride()).toBeUndefined();
70
+ });
71
+
72
+ it("defaults when the variable is unset", () => {
73
+ delete process.env[ENV_KEY];
74
+ expect(getDevelopmentProviderUrl()).toBe(DEFAULT_DEVELOPMENT_PROVIDER_URL);
75
+ });
76
+ });