Files
6c0413e39b Start 2.0 development
Co-authored-by: Anthony <anthony@infraly.co>
Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
2026-10-05 18:10:18 -04:00

30 lines
972 B
TypeScript

import { describe, expect, it } from 'vitest';
import type { AdminAllocation } from '@/api/admin/nodes/queries';
import { allocationLabel } from './helpers';
const allocation = (alias: string | null): AdminAllocation => ({
object: 'allocation',
attributes: {
id: 1,
ip: '10.0.0.1',
alias,
port: 25565,
notes: null,
server_id: null,
server_name: null,
assigned: false,
},
});
describe('allocationLabel', () => {
it('prefers an alias that differs from the IP', () => {
expect(allocationLabel(allocation('play.example.com'))).toBe('play.example.com:25565');
});
it('falls back to the IP for a missing, empty, or redundant alias', () => {
expect(allocationLabel(allocation(null))).toBe('10.0.0.1:25565');
expect(allocationLabel(allocation(''))).toBe('10.0.0.1:25565');
expect(allocationLabel(allocation('10.0.0.1'))).toBe('10.0.0.1:25565');
});
});