Skip to content

gitflarePublicPartly agent-ready40

orbit-duel

Real-time two-player orbital combat game on Cloudflare Workers and Durable Objects.

main
Add the Apache-2.0 licence0413e56
JavaScript31 lines1.1 KB
import test from 'node:test';import assert from 'node:assert/strict';import { planJoin, newRoster, join } from '../src/room-logic.ts'; function fakeSocket() { return { id: 0, role: 'spectator', name: '', token: '', joined: false }; } test('watch-only socket is a spectator and counts no player', () => {  const r = newRoster(8);  const ws = fakeSocket();  assert.equal(planJoin(ws, true), 'spectate');  ws.joined = true;  assert.equal(r.slots.length, 0);}); test('join on same socket upgrades to exactly one player; repeats ignored', () => {  const r = newRoster(8);  const ws = fakeSocket();  ws.joined = true;  assert.equal(planJoin(ws, false), 'upgrade');  const res = join(r, null, () => 't1', 0, false);  ws.role = 'player'; ws.id = res.slot.id; ws.name = 'Director';  assert.equal(r.slots.length, 1);  assert.equal(planJoin(ws, false), 'ignore');  assert.equal(planJoin(ws, true), 'ignore');  assert.equal(r.slots.length, 1);}); test('fresh non-watch socket becomes a new player', () => {  assert.equal(planJoin(fakeSocket(), false), 'new');});