Skip to content

Commit

Permalink
Merge 69b26fd into 65bc682
Browse files Browse the repository at this point in the history
  • Loading branch information
kenware committed Jul 19, 2018
2 parents 65bc682 + 69b26fd commit 883153b
Show file tree
Hide file tree
Showing 11 changed files with 3,812 additions and 3,708 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"root": true,
"extends": "airbnb-base",
"env": {
"browser": true,
"node": true,
"es6": true,
"mocha": true,
Expand Down
15 changes: 4 additions & 11 deletions app/models/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,10 @@ const GameSchema = new Schema({
gameId: {
type: Number
},
gameWinner: {
type: Schema.Types.ObjectId,
trim: true,
ref: 'User'
},
players: [{
type: Schema.Types.ObjectId,
ref: 'User'
}]
}, {
timestamps: true
players: [],
meta: {
type: Object
}
});

GameSchema.statics = {
Expand Down
52 changes: 51 additions & 1 deletion backend-test/game/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,62 @@ describe('Game Server', () => {
client2.on('connect', () => {
client2.emit('joinGame', { userId: 'unauthenticated', room: '', createPrivate: false });
client1.on('notification', (data) => {
data.notification.should.match(/ has joined the game\!/);
data.notification.should.match(/ has joined the game!/);
});
});
setTimeout(disconnect, 200);
});
});
describe('Game Server', () => {
it('Should update leftPlayers array when a player left a game', (done) => {
let client2, client3, client4, client5;
const client1 = io.connect(socketURL, options);
const disconnect = () => {
client1.disconnect();
client2.disconnect();
client3.disconnect();
client4.disconnect();
client5.disconnect();
done();
};
const expectStartGame = () => {
client1.emit('startGame');
client1.on('gameUpdate', (data) => {
data.state.should.equal('waiting for players to pick');
});
client2.on('gameUpdate', (data) => {
data.state.should.equal('waiting for players to pick');
});
client3.on('gameUpdate', (data) => {
data.state.should.equal('waiting for players to pick');
});
client4.on('gameUpdate', (data) => {
data.state.should.equal('waiting for players to pick');
});
setTimeout(disconnect, 200);
};
client1.on('connect', () => {
client1.emit('joinGame', { userId, room: '', createPrivate: false });
client2 = io.connect(socketURL, options);
client2.on('connect', () => {
client2.emit('joinGame', { userId: 'unauthenticated', room: '', createPrivate: false });
client3 = io.connect(socketURL, options);
client3.on('connect', () => {
client3.emit('joinGame', { userId: 'unauthenticated', room: '', createPrivate: false });
client4 = io.connect(socketURL, options);
client4.on('connect', () => {
client4.emit('joinGame', { userId: 'unauthenticated', room: '', createPrivate: false });
client5 = io.connect(socketURL, options);
client5.on('connect', () => {
client5.emit('joinGame', { userId: 'unauthenticated', room: '', createPrivate: false });
setTimeout(expectStartGame, 100);
});
});
});
});
});
});
});

it('Should start game when startGame event is sent with 3 players', (done) => {
let client2, client3;
Expand Down
16 changes: 0 additions & 16 deletions backend-test/startGame/startGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ const mockPlayers = {
players: []
};

let mockUser;

const userMock = {
name: 'kelvin',
password: '12345',
Expand All @@ -28,7 +26,6 @@ describe('Player endpoints', () => {
if (err) throw err;
mockPlayers.players.push(user._id);
mockPlayers.gameWinner = user._id;
mockUser = user;
}));
});

Expand All @@ -46,19 +43,6 @@ describe('Player endpoints', () => {
});
});

it('POST /api/game/:id/start endpoint should return the the game players', (done) => {
request(app)
.post('/api/game/3/start')
.set('authorization', token)
.send(mockPlayers)
.end((err, res) => {
if (err) return done(err);
expect(res.statusCode).to.equal(201);
expect(res.body.gameWinner).to.equal(mockUser._id.toString());
done();
});
});

it('POST /api/tour/:id endpoint should update the tour option to true', (done) => {
request(app)
.post(`/api/tour/${id}`)
Expand Down
6 changes: 0 additions & 6 deletions backend-test/unit/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,23 @@ const { handleFetchProfile } = Services;

let mocks = [];
const User = mongoose.model('User');
const Game = mongoose.model('Game');


describe('User service objects', () => {
describe('handleFetchProfile', () => {
before(() => Promise.all(dataStore.map(user => User.create(user)))
.then((users) => {
mocks = users;
Game.create({ gameWinner: users[0]._id, players: [...users] });
}));

after(() => {
Promise.resolve(Game.remove({}));
Promise.resolve(User.remove({}));
});

it('handleFetchProfile should fetch the a users profile along with the game history', () => handleFetchProfile(mocks[0]._id)
.then((data) => {
expect(data.email).to.equal('Test@user1.com');
expect(data.name).to.equal('Test user 1');
expect(data.gamesWon.length).to.equal(1);
expect(data.gamesWon[0].gameWinner.name).to.equal(mocks[0].name);
expect(data.games[0].players.length).to.equal(5);
}));
});
});
Loading

0 comments on commit 883153b

Please sign in to comment.