stub rooms index route and controller
This commit is contained in:
parent
e6fb148bdc
commit
493a1f3e82
4 changed files with 40 additions and 10 deletions
18
server/controllers/api/apiRoom.js
Normal file
18
server/controllers/api/apiRoom.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
// const roomQueries = require('../../data/queries/room');
|
||||
|
||||
const roomIndex = async (req, res, next) => {
|
||||
try {
|
||||
// TODO eventually add check for user's private rooms
|
||||
|
||||
|
||||
res.status(200).json({rooms: [{id: 1, name: 'main', description: 'A general place to play Go'}]})
|
||||
}
|
||||
|
||||
catch (err) {
|
||||
res.status(500).json(err);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
roomIndex
|
||||
}
|
|
@ -1,6 +1,9 @@
|
|||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const apiIndexController = require('../controllers/api/apiIndex');
|
||||
const apiRoomRouter = require('./api/room');
|
||||
|
||||
router.use('/rooms', apiRoomRouter);
|
||||
|
||||
router.get('/', apiIndexController.apiIndex);
|
||||
|
||||
|
|
7
server/routes/api/room.js
Normal file
7
server/routes/api/room.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const apiRoomController = require('../../controllers/api/apiRoom');
|
||||
|
||||
router.get('/', apiRoomController.roomIndex);
|
||||
|
||||
module.exports = router;
|
|
@ -1,4 +1,6 @@
|
|||
const apiRoomSpec = (chai, knex, server) => {
|
||||
const roomEndpoint = '/api/v1/rooms';
|
||||
const publicRooms = {rooms: [{id: 1, name: 'main', description: 'A general place to play Go'}]};
|
||||
|
||||
it('seeded rooms should be present in db', done => {
|
||||
knex('room').where('id', 1).orWhere('id', 2).select('name').then(roomResults => {
|
||||
|
@ -8,7 +10,7 @@ const apiRoomSpec = (chai, knex, server) => {
|
|||
|
||||
it('request to api rooms should return 200', done => {
|
||||
chai.request(server)
|
||||
.get('api/v1/rooms')
|
||||
.get(roomEndpoint)
|
||||
.end((err,res)=> {
|
||||
if(err) done(err);
|
||||
res.should.status(200);
|
||||
|
@ -16,15 +18,15 @@ const apiRoomSpec = (chai, knex, server) => {
|
|||
});
|
||||
})
|
||||
|
||||
// it('request to api rooms should return all public rooms', done => {
|
||||
// chai.request(server)
|
||||
// .get('api/v1/rooms')
|
||||
// .end((err,res)=> {
|
||||
// if(err) done(err);
|
||||
// res.body.should.have.property('rooms');
|
||||
// done();
|
||||
// });
|
||||
// })
|
||||
it('request to api rooms should return all public rooms', done => {
|
||||
chai.request(server)
|
||||
.get(roomEndpoint)
|
||||
.end((err,res)=> {
|
||||
if(err) done(err);
|
||||
res.body.should.eql(publicRooms);
|
||||
done();
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = apiRoomSpec;
|
Loading…
Reference in a new issue