30 lines
1.5 KiB
JavaScript
30 lines
1.5 KiB
JavaScript
import { describe, it, expect } from 'vitest';
|
|
import { isRemoteHost, pickServiceUrls } from '../../public/views/service_url.js';
|
|
|
|
describe('isRemoteHost', () => {
|
|
it('treats private/local hosts as not-remote', () => {
|
|
for (const h of ['localhost', '127.0.0.1', '192.168.1.216', '10.0.0.5', '172.16.0.1', 'void.local', 'ct311', 'nas.lan'])
|
|
expect(isRemoteHost(h)).toBe(false);
|
|
});
|
|
it('treats public domains as remote', () => {
|
|
for (const h of ['void.hynesy.com', 'dash.example.org'])
|
|
expect(isRemoteHost(h)).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('pickServiceUrls', () => {
|
|
const svc = { url: 'http://192.168.1.99', external: 'https://gramps.hynesy.com' };
|
|
it('remote + external → domain primary, LAN alt', () => {
|
|
expect(pickServiceUrls(svc, true)).toEqual({ primary: 'https://gramps.hynesy.com', alt: 'http://192.168.1.99', lanOnly: false });
|
|
});
|
|
it('local + external → LAN primary, domain alt', () => {
|
|
expect(pickServiceUrls(svc, false)).toEqual({ primary: 'http://192.168.1.99', alt: 'https://gramps.hynesy.com', lanOnly: false });
|
|
});
|
|
it('remote + no external → LAN primary, no alt, lanOnly', () => {
|
|
expect(pickServiceUrls({ url: 'http://192.168.1.5' }, true)).toEqual({ primary: 'http://192.168.1.5', alt: null, lanOnly: true });
|
|
});
|
|
it('local + no external → LAN primary, no alt', () => {
|
|
expect(pickServiceUrls({ url: 'http://192.168.1.5' }, false)).toEqual({ primary: 'http://192.168.1.5', alt: null, lanOnly: false });
|
|
});
|
|
});
|