From 95d0cee35f2ba89611d9702c42d02ab32d0d111a Mon Sep 17 00:00:00 2001 From: AlecM33 Date: Tue, 28 Nov 2023 18:19:21 -0500 Subject: [PATCH] fix logic that determines whether games are startable when the game is first constructed --- server/model/Game.js | 6 +----- server/modules/singletons/GameManager.js | 6 ++++-- spec/unit/server/modules/Events_Spec.js | 3 +++ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/server/model/Game.js b/server/model/Game.js index 9885b7d..0c5ab09 100644 --- a/server/model/Game.js +++ b/server/model/Game.js @@ -9,8 +9,7 @@ class Game { hasDedicatedModerator, originalModeratorId, createTime, - timerParams = null, - isTestGame = false + timerParams = null ) { this.accessCode = accessCode; this.status = status; @@ -27,9 +26,6 @@ class Game { this.previousModeratorId = null; this.createTime = createTime; this.timerParams = timerParams; - this.isStartable = (this.gameSize === 1 && !this.hasDedicatedModerator) - || (this.gameSize === 0 && this.hasDedicatedModerator) - || isTestGame; this.timeRemaining = null; } } diff --git a/server/modules/singletons/GameManager.js b/server/modules/singletons/GameManager.js index be7f2fd..494db51 100644 --- a/server/modules/singletons/GameManager.js +++ b/server/modules/singletons/GameManager.js @@ -91,10 +91,12 @@ class GameManager { req.hasDedicatedModerator, moderator.id, new Date().toJSON(), - req.timerParams, - req.isTestGame + req.timerParams ); newGame.people = initializePeopleForGame(req.deck, moderator, this.shuffle, req.isTestGame, newGame.gameSize); + newGame.isStartable = newGame.people.filter(person => person.userType === USER_TYPES.PLAYER + || person.userType === USER_TYPES.TEMPORARY_MODERATOR + || person.userType === USER_TYPES.BOT).length === newGame.gameSize; await this.eventManager.publisher.set(newAccessCode, JSON.stringify(newGame), { EX: PRIMITIVES.STALE_GAME_SECONDS }); diff --git a/spec/unit/server/modules/Events_Spec.js b/spec/unit/server/modules/Events_Spec.js index 939f104..493db0f 100644 --- a/spec/unit/server/modules/Events_Spec.js +++ b/spec/unit/server/modules/Events_Spec.js @@ -42,6 +42,9 @@ describe('Events', () => { new Date().toJSON(), null ); + game.isStartable = game.people.filter(person => person.userType === USER_TYPES.PLAYER + || person.userType === USER_TYPES.TEMPORARY_MODERATOR + || person.userType === USER_TYPES.BOT).length === game.gameSize; spyOn(namespace, 'to').and.callThrough(); spyOn(namespace, 'in').and.callThrough(); spyOn(socket, 'to').and.callThrough();