stub rooms index route and controller

This commit is contained in:
Sorrel Bri 2020-01-18 15:42:45 -08:00 committed by sorrelbri
parent 47856773eb
commit 762c4d93a8
4 changed files with 40 additions and 10 deletions

View 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
}

View file

@ -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);

View 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;

View file

@ -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;