stub rooms index route and controller
This commit is contained in:
parent
47856773eb
commit
762c4d93a8
4 changed files with 40 additions and 10 deletions
|
@ -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 express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const apiIndexController = require('../controllers/api/apiIndex');
|
const apiIndexController = require('../controllers/api/apiIndex');
|
||||||
|
const apiRoomRouter = require('./api/room');
|
||||||
|
|
||||||
|
router.use('/rooms', apiRoomRouter);
|
||||||
|
|
||||||
router.get('/', apiIndexController.apiIndex);
|
router.get('/', apiIndexController.apiIndex);
|
||||||
|
|
||||||
|
|
|
@ -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 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 => {
|
it('seeded rooms should be present in db', done => {
|
||||||
knex('room').where('id', 1).orWhere('id', 2).select('name').then(roomResults => {
|
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 => {
|
it('request to api rooms should return 200', done => {
|
||||||
chai.request(server)
|
chai.request(server)
|
||||||
.get('api/v1/rooms')
|
.get(roomEndpoint)
|
||||||
.end((err,res)=> {
|
.end((err,res)=> {
|
||||||
if(err) done(err);
|
if(err) done(err);
|
||||||
res.should.status(200);
|
res.should.status(200);
|
||||||
|
@ -16,15 +18,15 @@ const apiRoomSpec = (chai, knex, server) => {
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
// it('request to api rooms should return all public rooms', done => {
|
it('request to api rooms should return all public rooms', done => {
|
||||||
// chai.request(server)
|
chai.request(server)
|
||||||
// .get('api/v1/rooms')
|
.get(roomEndpoint)
|
||||||
// .end((err,res)=> {
|
.end((err,res)=> {
|
||||||
// if(err) done(err);
|
if(err) done(err);
|
||||||
// res.body.should.have.property('rooms');
|
res.body.should.eql(publicRooms);
|
||||||
// done();
|
done();
|
||||||
// });
|
});
|
||||||
// })
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = apiRoomSpec;
|
module.exports = apiRoomSpec;
|
Loading…
Reference in a new issue