Adjust Discord publication and lobby capacity defaults
CI / checks (push) Failing after 7m21s

This commit is contained in:
2026-10-18 17:23:50 -04:00
parent fd00ef5357
commit d715173719
15 changed files with 304 additions and 89 deletions
+75 -11
View File
@@ -31,7 +31,7 @@ function snapshot(): DiscordAdminState {
enabled: false,
guildId,
channels: { t5: channelId, t6: '' },
publishedServers: [],
excludedServers: [],
showPlayers: false,
showAddresses: false,
leaderboardEnabled: false
@@ -57,7 +57,25 @@ function snapshot(): DiscordAdminState {
map: 'Kino der Toten'
}
],
preview: { t5: [], t6: [] }
preview: {
t5: [
{
name: serverName,
game: 't5',
label: 'Kino der Toten · Lobby 1',
map: 'Kino der Toten',
mapKey: 't5:zombie_theater',
state: 'empty',
players: 0,
capacity: 4,
round: null,
observedAt: '2026-10-18T20:00:00.000Z',
playerNames: [],
connection: null
}
],
t6: []
}
};
}
@@ -103,8 +121,9 @@ async function show(role = 'admin') {
});
}
it('saves explicit publication choices without credentials and restores saved values on discard', async () => {
it('includes servers by default, saves an exclusion without credentials, and restores it on discard', async () => {
const initial = snapshot();
initial.preview.t5[0].capacity = null;
let submitted: DiscordSettings | undefined;
const fetch = vi.fn(async (_url: string, init?: RequestInit) => {
if (init?.method === 'PUT') {
@@ -117,11 +136,15 @@ it('saves explicit publication choices without credentials and restores saved va
await show();
expect(checkbox('Enable Discord companion').checked).toBe(false);
expect(checkbox(serverName).checked).toBe(false);
expect(checkbox(serverName).checked).toBe(true);
expect(checkbox('Show player names').checked).toBe(false);
expect(checkbox('Show public server connection addresses').checked).toBe(false);
expect(checkbox('Publish fleet leaderboards').checked).toBe(false);
expect(document.body.textContent).toContain('including servers outside the selection above');
expect(document.body.textContent).toContain('including excluded servers');
expect(document.body.textContent).toContain('1 server included.');
expect(document.querySelector('.preview-server')?.textContent?.replace(/\s+/g, ' ')).toContain(
'0 / 4 players'
);
toggle('Enable Discord companion');
toggle(serverName);
@@ -136,7 +159,7 @@ it('saves explicit publication choices without credentials and restores saved va
...initial.settings,
enabled: true,
guildId: '45678901234567890',
publishedServers: [serverName],
excludedServers: [serverName],
showPlayers: true,
leaderboardEnabled: true
});
@@ -149,7 +172,7 @@ it('saves explicit publication choices without credentials and restores saved va
button('Discard').click();
flushSync();
expect(checkbox('Show player names').checked).toBe(true);
expect(checkbox(serverName).checked).toBe(true);
expect(checkbox(serverName).checked).toBe(false);
expect(button('Save changes').disabled).toBe(true);
});
@@ -174,11 +197,18 @@ it('keeps Super Viewer controls read-only and rejects a directly submitted mutat
);
});
it('preserves publication edits and the last snapshot across polling failures and recovery', async () => {
it('automatically includes new servers on polling while retaining draft exclusions and recovering from errors', async () => {
vi.useFakeTimers();
const initial = snapshot();
const updated = snapshot();
updated.status.activeSubscriptions = 3;
const newServer = 't6_zm_tomb_1';
updated.servers.push({
name: newServer,
game: 't6',
label: 'Origins · Lobby 1',
map: 'Origins'
});
const fetch = vi
.fn()
.mockResolvedValueOnce(Response.json(initial))
@@ -195,17 +225,51 @@ it('preserves publication edits and the last snapshot across polling failures an
'Discord status unavailable.'
);
expect(document.body.textContent).toContain('Kino der Toten · Lobby 1');
expect(checkbox(serverName).checked).toBe(true);
expect(checkbox(serverName).checked).toBe(false);
expect(field('Discord server ID').value).toBe('45678901234567890');
button('Retry loading').click();
await vi.advanceTimersByTimeAsync(60_000);
await vi.waitFor(() => expect(document.querySelector('[role="alert"]')).toBeNull());
expect(checkbox(serverName).checked).toBe(true);
expect(checkbox(serverName).checked).toBe(false);
expect(checkbox(newServer).checked).toBe(true);
expect(document.body.textContent).toContain('1 server included.');
expect(field('Discord server ID').value).toBe('45678901234567890');
expect(button('Save changes').disabled).toBe(false);
expect(document.body.textContent).toContain('Unsaved changes');
});
it('retains exclusions for removed servers until the administrator explicitly removes them', async () => {
const initial = snapshot();
const removedServer = 't5_zombie_cosmodrome_1';
initial.settings.excludedServers = [removedServer];
const writes: DiscordSettings[] = [];
vi.stubGlobal(
'fetch',
vi.fn(async (_url: string, init?: RequestInit) => {
if (init?.method === 'PUT') {
const settings = JSON.parse(String(init.body)) as DiscordSettings;
writes.push(settings);
return Response.json({ ...initial, settings });
}
return Response.json(initial);
})
);
await show();
expect(checkbox(removedServer).checked).toBe(false);
expect(document.body.textContent).toContain('Excluded if this server returns.');
expect(document.body.textContent).toContain('1 server included.');
toggle('Show player names');
button('Save changes').click();
await vi.waitFor(() => expect(button('Save changes').disabled).toBe(true));
expect(writes[0].excludedServers).toEqual([removedServer]);
toggle(removedServer);
button('Save changes').click();
await vi.waitFor(() => expect(writes).toHaveLength(2));
expect(writes[1].excludedServers).toEqual([]);
expect(document.body.textContent).not.toContain('Excluded servers no longer in the fleet');
});
it('registers commands only on an explicit action and retains its error through successful refreshes', async () => {
const fetch = vi.fn(async (url: string) =>
url.endsWith('/register')