39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
import { findCardByName } from '../src/cards.js'
|
|
import { createMatch, getMatchView, joinMatch, leaveMatch, setDeck, startMatch } from '../src/game/rooms.js'
|
|
|
|
function deck(commanderName: string) {
|
|
const commander = findCardByName(commanderName)
|
|
const forest = findCardByName('Forest')
|
|
assert.ok(commander && forest)
|
|
return {
|
|
commander: commander.oracle_id,
|
|
cards: Array.from({ length: 99 }, () => forest.oracle_id),
|
|
}
|
|
}
|
|
|
|
test('lobby decks can be swapped and invalid decks are rejected', () => {
|
|
const first = deck("Atraxa, Praetors' Voice")
|
|
const second = deck('Kenrith, the Returned King')
|
|
const { matchId, token } = createMatch('Host', first, 2)
|
|
|
|
setDeck(matchId, token, second)
|
|
assert.equal(getMatchView(matchId, token).players[0].commander?.name, 'Kenrith, the Returned King')
|
|
|
|
assert.throws(() => setDeck(matchId, token, { ...second, cards: [] }), /100/)
|
|
assert.equal(getMatchView(matchId, token).players[0].commander?.name, 'Kenrith, the Returned King')
|
|
})
|
|
|
|
test('leaving a started game forfeits the seat instead of erroring', () => {
|
|
const host = createMatch('Host', deck("Atraxa, Praetors' Voice"), 2)
|
|
const guest = joinMatch(host.matchId, 'Guest', deck('Kenrith, the Returned King'))
|
|
startMatch(host.matchId, host.token)
|
|
|
|
leaveMatch(host.matchId, host.token)
|
|
|
|
const view = getMatchView(host.matchId, guest.token)
|
|
assert.equal(view.status, 'finished')
|
|
assert.equal(view.players.find(player => player.id === host.playerId)?.lost, true)
|
|
})
|