Apply selected server maps automatically without config overlays
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { composeCfg, parseCfg, parseOverlay } from '../../src/lib/server/fleet/config-compose.js';
|
||||
import { composeCfg, composeServerCfg, parseCfg, parseOverlay } from '../../src/lib/server/fleet/config-compose.js';
|
||||
import { T5_ZOMBIE_MAPS } from '../../src/lib/server/fleet/map-aliases.js';
|
||||
|
||||
const BASELINE = [
|
||||
'// GENERAL',
|
||||
@@ -86,3 +87,42 @@ describe('composeCfg', () => {
|
||||
expect(result.trim()).toBe(BASELINE.trim());
|
||||
});
|
||||
});
|
||||
|
||||
describe('automatic map selection', () => {
|
||||
it.each(T5_ZOMBIE_MAPS)('selects $friendly without a map overlay', ({ canonical }) => {
|
||||
const result = composeServerCfg(BASELINE, [], 't5', canonical);
|
||||
expect(result).toContain(`set sv_maprotation "map ${canonical}"`);
|
||||
expect(result.match(/^set sv_maprotation /gm)).toHaveLength(1);
|
||||
expect(result).toContain('set sv_voice "1"');
|
||||
});
|
||||
|
||||
it('overrides legacy map-choice overlays while keeping other settings', () => {
|
||||
const result = composeServerCfg(BASELINE, [{
|
||||
id: 5, text: 'set sv_maprotation "map zombie_moon"\nset g_inactivity "0"'
|
||||
}], 't5', 'zombie_cosmodrome');
|
||||
expect(result).toContain('set sv_maprotation "map zombie_cosmodrome"');
|
||||
expect(result).not.toContain('map zombie_moon');
|
||||
expect(result).toContain('set g_inactivity "0"');
|
||||
});
|
||||
|
||||
it('appends the rotation when absent and preserves CRLF', () => {
|
||||
expect(composeServerCfg('set sv_voice "1"\r\n', [], 't5', 'zombietron'))
|
||||
.toBe('set sv_voice "1"\r\n// Map selected by Electric Cherry\r\nset sv_maprotation "map zombietron"\r\n');
|
||||
});
|
||||
|
||||
it('removes conflicting duplicate assignments regardless of case or command form', () => {
|
||||
const result = composeServerCfg([
|
||||
'// keep this comment',
|
||||
'set sv_maprotation "map zombie_theater"',
|
||||
'seta SV_MAPROTATION "map zombie_moon"',
|
||||
'sv_mapRotation "map zombie_pentagon"'
|
||||
].join('\n'), [], 't5', 'zombie_cod5_sumpf');
|
||||
expect(result).toBe('// keep this comment\nset sv_maprotation "map zombie_cod5_sumpf"\n');
|
||||
});
|
||||
|
||||
it.each([
|
||||
[null, null], ['t5', null], ['t5', 'custom_map'], ['t6', 'zombie_theater']
|
||||
])('preserves existing behavior for unsupported game/map %s/%s', (game, map) => {
|
||||
expect(composeServerCfg(BASELINE, [], game, map)).toBe(composeCfg(BASELINE, []));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user