-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
4,442 additions
and
3,419 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ | |
] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/public/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
eslint: | ||
enabled: true | ||
config_file: .eslintrc.js | ||
config_file: .eslintrc | ||
ignore_file: .eslintignore |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
import mongoose from 'mongoose'; | ||
|
||
const Game = mongoose.model('Game'); | ||
|
||
/** | ||
* @function gameResult | ||
* @description without friends parameter, it returns a status code 401 | ||
* with a warning message | ||
* It saves the game result to the database | ||
* | ||
* @param {object} req | ||
* @param {object} res | ||
* | ||
* @returns {object} returns the game result | ||
*/ | ||
const gameResult = (req, res) => { | ||
let gameId = req.params.id; | ||
gameId = parseInt(gameId, 10); | ||
const { gameWinner, players } = req.body; | ||
if (!players) { | ||
return res.status(401).json({ message: 'Players have not joined the game' }); | ||
} | ||
const payload = { | ||
gameWinner, | ||
players, | ||
gameId | ||
}; | ||
const game = new Game(payload); | ||
game.save((err) => { | ||
if (err) { | ||
return res.status(500).json({ message: 'Error saving game' }); | ||
} | ||
return res.status(201).json(game); | ||
}); | ||
}; | ||
|
||
export default gameResult; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import 'babel-polyfill'; | ||
import jwt from 'jsonwebtoken'; | ||
|
||
/** | ||
* @function auth | ||
* @param {string} data - A token | ||
* @returns { null } returns Unauthorized Access if token is undfefined | ||
* @returns { expired } returns Please login | ||
* @description used to access authenticated route | ||
* @description if token is valid, decode the payload and pass it controller | ||
*/ | ||
|
||
const auth = (req, res, next) => { | ||
const token = req.headers.authorization || req.headers['x-access-token']; | ||
if (!token) { | ||
return res.status(401).json({ message: 'Unauthorized Access' }); | ||
} | ||
|
||
jwt.verify(token, process.env.SECRET_KEY, (err, result) => { | ||
if (err) { | ||
return res.status(401).json({ message: 'Please login!' }); | ||
} | ||
req.decoded = result; | ||
next(); | ||
}); | ||
}; | ||
|
||
export default auth; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
import mongoose from 'mongoose'; | ||
|
||
const { Schema } = mongoose; | ||
|
||
/** | ||
* Game Schema | ||
*/ | ||
const GameSchema = new Schema({ | ||
id: { | ||
type: Number | ||
}, | ||
gameId: { | ||
type: Number | ||
}, | ||
gameWinner: { | ||
type: String, | ||
default: '', | ||
trim: true | ||
}, | ||
players: { | ||
type: [String] | ||
} | ||
}); | ||
|
||
GameSchema.statics = { | ||
load(id, cb) { | ||
this.findOne({ | ||
id | ||
}).select('-_id').exec(cb); | ||
} | ||
}; | ||
|
||
mongoose.model('Game', GameSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import 'babel-polyfill'; | ||
import request from 'supertest'; | ||
import { expect } from 'chai'; | ||
import mongoose from 'mongoose'; | ||
import app from '../../server'; | ||
|
||
const User = mongoose.model('User'); | ||
|
||
const mockPlayers = { | ||
gameWinner: 'kevin', | ||
players: [1, 2, 3] | ||
}; | ||
|
||
const userMock = { | ||
name: 'kelvin', | ||
password: '12345', | ||
username: 'kelvin', | ||
email: 'kelvin@email.com' | ||
}; | ||
|
||
let userToken = ''; | ||
describe('Player endpoints', () => { | ||
before(() => { | ||
Promise.resolve(User.create(userMock)); | ||
}); | ||
|
||
it('POST /api/auth/endpoint should return the user token along with the user', (done) => { | ||
request(app) | ||
.post('/api/auth/login') | ||
.send(userMock) | ||
.end((err, res) => { | ||
if (err) return done(err); | ||
expect(res.statusCode).to.equal(200); | ||
userToken = res.body.token; | ||
done(); | ||
}); | ||
}); | ||
|
||
it('POST /api/game/:id/start endpoint should return the the game players', (done) => { | ||
request(app) | ||
.post('/api/game/3/start') | ||
.set('authorization', userToken) | ||
.send(mockPlayers) | ||
.end((err, res) => { | ||
if (err) return done(err); | ||
expect(res.statusCode).to.equal(201); | ||
expect(res.body.gameWinner).to.equal('kevin'); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.