Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/lib/server/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,50 @@ test('changeTeam moves the faction then kills the player', async () => {
expect(r.message).toContain('respawn');
});

test('kill sends an empty JSON body', async () => {
const calls: { method: string; path: string; body: unknown }[] = [];
const client: any = {
json: async (method: string, path: string, body?: unknown) => {
calls.push({ method, path, body });
return { message: 'OK: killed Player.' };
}
};
await ACTIONS.kill.run(client, { steamId: '76561198000000001' });
expect(calls).toEqual([
{
method: 'POST',
path: '/v1/players/76561198000000001/kill',
body: {}
}
]);
});

test('changeTeam sends an empty JSON body with its respawn kill', async () => {
const calls: { method: string; path: string; body: unknown }[] = [];
const client: any = {
json: async (method: string, path: string, body?: unknown) => {
calls.push({ method, path, body });
return { message: 'OK.' };
}
};
await ACTIONS.changeTeam.run(client, {
steamId: '76561198000000001',
faction: 'Valkyra'
});
expect(calls).toEqual([
{
method: 'PATCH',
path: '/v1/players/76561198000000001',
body: { faction: 'Valkyra' }
},
{
method: 'POST',
path: '/v1/players/76561198000000001/kill',
body: {}
}
]);
});

test('changeTeam with kill: false sends the move alone', async () => {
const { client, calls } = fakeClient(false);
const r: any = await ACTIONS.changeTeam.run(client, {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/server/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ export const ACTIONS: Record<string, ActionDef> = {
cap: 'players.kill',
mutating: true,
target: (p) => str(p.steamId, 32),
run: (c, p) => c.json('POST', `/v1/players/${steamId(p.steamId)}/kill`)
run: (c, p) => c.json('POST', `/v1/players/${steamId(p.steamId)}/kill`, {})
},
// As the official console does it: move the faction, then kill the player so they respawn on the
// new side. A failed kill is not an error; the move already happened. A kill refused for sending
Expand All @@ -678,7 +678,7 @@ export const ACTIONS: Record<string, ActionDef> = {
let respawned = true;
let retryAfterMs = 0;
try {
await c.json('POST', `/v1/players/${id}/kill`);
await c.json('POST', `/v1/players/${id}/kill`, {});
} catch (err) {
if (!(err instanceof GameError)) throw err;
respawned = false;
Expand Down