diff --git a/packages/server/services/Game.js b/packages/server/services/Game.js index 54fcd23..a6883f2 100644 --- a/packages/server/services/Game.js +++ b/packages/server/services/Game.js @@ -263,6 +263,13 @@ const Game = ({gameData = {}, gameRecord = []} = {}) => { gameData: { komi, handicap, boardSize }, gameRecord: [...this.gameRecord.slice(0, index)] }); + }, + + submitResign: function(player) { + if (player === 'black') this.winner = -1; + if (player === 'white') this.winner = 1; + this.turn = 0; + return this; } } }; diff --git a/packages/server/test/Game.spec.js b/packages/server/test/Game.spec.js index 365df4f..f001a8d 100644 --- a/packages/server/test/Game.spec.js +++ b/packages/server/test/Game.spec.js @@ -489,6 +489,14 @@ describe('Game history functionality', () => { fifthMoveGame.boardState['10-4'].stone.should.eql(1) fifthMoveGame.boardState['4-10'].stone.should.eql(0) done(); + }); +}); + +describe('Game end logic', () => { + it('resignation results in game end', done => { + Game().initGame().submitResign('black') + .getMeta().should.eql({...initialMeta, winner: -1}); + done(); }) })