diff --git a/server/controllers/api/apiRoom.js b/server/controllers/api/apiRoom.js new file mode 100644 index 0000000..819cacc --- /dev/null +++ b/server/controllers/api/apiRoom.js @@ -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 +} \ No newline at end of file diff --git a/server/routes/api.js b/server/routes/api.js index db73972..ac8c265 100644 --- a/server/routes/api.js +++ b/server/routes/api.js @@ -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); diff --git a/server/routes/api/room.js b/server/routes/api/room.js new file mode 100644 index 0000000..9f8e56c --- /dev/null +++ b/server/routes/api/room.js @@ -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; diff --git a/server/test/room/api.room.spec.js b/server/test/room/api.room.spec.js index 24dab35..048760b 100644 --- a/server/test/room/api.room.spec.js +++ b/server/test/room/api.room.spec.js @@ -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; \ No newline at end of file