16 lines
1016 B
JavaScript
16 lines
1016 B
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { resolveBackendUrl } from "../src/backend_url.js";
|
|
|
|
const phone = { protocol: "http:", hostname: "192.168.1.46", origin: "http://192.168.1.46:8081" };
|
|
const laptop = { protocol: "http:", hostname: "localhost", origin: "http://localhost:8081" };
|
|
|
|
test("a phone on the laptop's IP ignores the laptop's saved localhost address", () => {
|
|
assert.equal(resolveBackendUrl("http://localhost:8081", phone), "http://192.168.1.46:8081");
|
|
assert.equal(resolveBackendUrl("http://127.0.0.1:8081/", phone), "http://192.168.1.46:8081");
|
|
assert.equal(resolveBackendUrl("http://localhost:8081", laptop), "http://localhost:8081", "the laptop keeps it");
|
|
assert.equal(resolveBackendUrl("http://10.0.0.5:8081", phone), "http://10.0.0.5:8081", "a real address set on purpose is kept");
|
|
assert.equal(resolveBackendUrl("", phone), "http://192.168.1.46:8081");
|
|
assert.equal(resolveBackendUrl("", { protocol: "file:" }), "http://127.0.0.1:8081");
|
|
});
|