Files
electric-cherry/tests/unit/map-aliases.test.ts
T
joshandClaude Opus 4.7 590f803d93 Auto-derive server.game and server.map from the server name
Server folders encode the game and map (e.g. t5_ascension_1 = game t5, map
alias ascension, lobby 1). A T5_MAP_ALIASES table translates the friendly
alias to the canonical mapname RCON reports (ascension → zombie_cosmodrome),
covering every base + Rezurrection map. seedServerRegistry now populates
game and map at insert time and backfills existing NULL rows on every boot;
unknown aliases log a warning so we know when to add them.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-09-12 13:35:43 -04:00

70 lines
2.2 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { parseServerName, T5_MAP_ALIASES } from '../../src/lib/server/fleet/map-aliases.js';
describe('parseServerName', () => {
it('extracts game, map alias, canonical map, and lobby from a T5 server name', () => {
expect(parseServerName('t5_ascension_1')).toEqual({
game: 't5',
mapAlias: 'ascension',
mapCanonical: 'zombie_cosmodrome',
lobby: 1
});
expect(parseServerName('t5_kino_1')).toEqual({
game: 't5',
mapAlias: 'kino',
mapCanonical: 'zombie_theater',
lobby: 1
});
expect(parseServerName('t5_cotd_1')).toEqual({
game: 't5',
mapAlias: 'cotd',
mapCanonical: 'zombie_coast',
lobby: 1
});
});
it('joins multi-segment map aliases and matches the alias table', () => {
expect(parseServerName('t5_shi_no_numa_1')).toEqual({
game: 't5',
mapAlias: 'shinonuma',
mapCanonical: 'zombie_cod5_sumpf',
lobby: 1
});
expect(parseServerName('t5_der_riese_2')).toEqual({
game: 't5',
mapAlias: 'derriese',
mapCanonical: 'zombie_cod5_factory',
lobby: 2
});
});
it('treats a name with no trailing lobby number as an alias-only tail', () => {
expect(parseServerName('t5_moon')).toEqual({
game: 't5',
mapAlias: 'moon',
mapCanonical: 'zombie_moon',
lobby: null
});
});
it('returns mapCanonical=null for unknown aliases so operators can spot the gap', () => {
expect(parseServerName('t5_newmap_1')).toEqual({
game: 't5',
mapAlias: 'newmap',
mapCanonical: null,
lobby: 1
});
});
it('rejects names with fewer than two segments', () => {
expect(parseServerName('t5')).toBeNull();
expect(parseServerName('')).toBeNull();
});
it('every alias in T5_MAP_ALIASES resolves to a zombie_* canonical mapname', () => {
for (const canonical of Object.values(T5_MAP_ALIASES)) {
expect(canonical.startsWith('zombie')).toBe(true);
}
});
});