Skip to content

Commit

Permalink
fix(plugins): Fix PluginPlayer setup (#543)
Browse files Browse the repository at this point in the history
* test(plugins): Add test for PluginPlayer with game phases

* fix(plugins): Don’t restore player & opponent to G.players if undefined

Fixes #530

Co-authored-by: Nicolo John Davis <nicolodavis@gmail.com>
  • Loading branch information
delucis and nicolodavis authored Feb 11, 2020
1 parent 6a10e59 commit fd34df9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/plugins/plugin-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ export default {

const players = {
...G.players,
[current]: G.player,
[current]: 'player' in G ? G.player : G.players[current],
};

if (other !== null) {
players[other] = G.opponent;
players[other] = 'opponent' in G ? G.opponent : G.players[other];
}

{
Expand Down
29 changes: 29 additions & 0 deletions src/plugins/plugin-player.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,32 @@ describe('3 player game', () => {
});
});
});

describe('game with phases', () => {
let client;

beforeAll(() => {
const game = {
playerSetup: id => ({ id }),
plugins: [PluginPlayer],
phases: {
phase: {},
},
};

client = Client({ game });
});

test('includes playerSetup state', () => {
expect(client.getState().G).toEqual({
players: {
0: {
id: '0',
},
1: {
id: '1',
},
},
});
});
});

0 comments on commit fd34df9

Please sign in to comment.