1
0

stop creating games on session creation

This is necessary to allow users to create new sessions with different
game point goals, and have that goal be in effect for the very first
game.
This commit is contained in:
Adrian Wannenmacher 2026-02-09 23:20:41 +01:00
parent 220a9b40e4
commit 7aeba40043
Signed by: tfld
GPG Key ID: 19D986ECB1E492D5
2 changed files with 12 additions and 4 deletions

View File

@ -80,7 +80,6 @@ export default class Session {
constructor(value) { constructor(value) {
if (value === undefined) { if (value === undefined) {
this.anotherGame();
} else if (typeof value === "object") { } else if (typeof value === "object") {
if (!("goal" in value)) if (!("goal" in value))
throw new TypeError("missing goal in deserialization object"); throw new TypeError("missing goal in deserialization object");

View File

@ -10,7 +10,7 @@ QUnit.module("models", function() {
let session = new Session(); let session = new Session();
assert.strictEqual(session.goal, 11, "initial goal"); assert.strictEqual(session.goal, 11, "initial goal");
assert.strictEqual(session.games.length, 0, "no finished games"); assert.strictEqual(session.games.length, 0, "no finished games");
assert.notStrictEqual(session.currentGame, null, "game in progress"); assert.strictEqual(session.currentGame, null, "no game in progress");
assert.deepEqual( assert.deepEqual(
session.result, session.result,
{ ourPoints: 0, theirPoints: 0 }, { ourPoints: 0, theirPoints: 0 },
@ -19,8 +19,15 @@ QUnit.module("models", function() {
assert.strictEqual(session.theirTeam, "", "their team name"); assert.strictEqual(session.theirTeam, "", "their team name");
}); });
QUnit.test("start game", function(assert) {
let session = new Session();
session.anotherGame();
assert.notStrictEqual(session.currentGame, null, "game in progress");
});
QUnit.test("single game finished", function(assert) { QUnit.test("single game finished", function(assert) {
let session = new Session(); let session = new Session();
session.anotherGame();
session.currentGame.currentRound.winner = Team.We; session.currentGame.currentRound.winner = Team.We;
for (let i = 0; i < session.goal; i += 2) for (let i = 0; i < session.goal; i += 2)
session.currentGame.currentRound.winner = Team.They; session.currentGame.currentRound.winner = Team.They;
@ -43,6 +50,7 @@ QUnit.module("models", function() {
QUnit.test("two games finished", function(assert) { QUnit.test("two games finished", function(assert) {
let session = new Session(); let session = new Session();
session.anotherGame();
session.currentGame.currentRound.winner = Team.We; session.currentGame.currentRound.winner = Team.We;
for (let i = 0; i < session.goal; i += 2) for (let i = 0; i < session.goal; i += 2)
session.currentGame.currentRound.winner = Team.They; session.currentGame.currentRound.winner = Team.They;
@ -68,6 +76,7 @@ QUnit.module("models", function() {
QUnit.test("new game doesn't overwrite existing", function(assert) { QUnit.test("new game doesn't overwrite existing", function(assert) {
let session = new Session(); let session = new Session();
session.anotherGame();
session.currentGame.currentRound.winner = Team.We; session.currentGame.currentRound.winner = Team.We;
assert.notStrictEqual(session.currentGame, null, "ongoing game"); assert.notStrictEqual(session.currentGame, null, "ongoing game");
@ -86,7 +95,6 @@ QUnit.module("models", function() {
QUnit.test("serialization - new session", function(assert) { QUnit.test("serialization - new session", function(assert) {
let session = new Session(); let session = new Session();
let json = session.toJSON(); let json = session.toJSON();
json.currentGame = session.currentGame.toJSON();
assert.deepEqual( assert.deepEqual(
json, json,
@ -95,13 +103,14 @@ QUnit.module("models", function() {
ourTeam: "", ourTeam: "",
theirTeam: "", theirTeam: "",
games: [], games: [],
currentGame: session.currentGame.toJSON() currentGame: null,
}, },
"correct serialization"); "correct serialization");
}); });
QUnit.test("serialization - finished & unfinished game", function(assert) { QUnit.test("serialization - finished & unfinished game", function(assert) {
let session = new Session(); let session = new Session();
session.anotherGame();
session.currentGame.currentRound.winner = Team.We; session.currentGame.currentRound.winner = Team.We;
for ( for (
let i = 0; let i = 0;