Skip to content
This repository has been archived by the owner on May 28, 2018. It is now read-only.

Commit

Permalink
Retrieve PEPITE with its id
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrohee committed Nov 23, 2016
1 parent f5700c4 commit 5f31f20
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion server/api/pepite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ module.exports = (options) => {
var pepiteController = new Controller(options)
router.get('/ping', pepiteController.ping)
router.get('/', pepiteController.getAll)
router.get('/:id', pepiteController.getPepite)
router.get('/:id(\\d+)', pepiteController.getPepite)
return router
}
4 changes: 0 additions & 4 deletions server/api/pepite/pepite.controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const Pepite = require('./pepite.model')
const mongoose = require('mongoose')

class PepiteController {
ping(req, res) {
Expand All @@ -20,9 +19,6 @@ class PepiteController {
}

getPepite(req, res) {
if (!mongoose.Types.ObjectId.isValid(req.params.id)) {
return res.sendStatus(404)
}
return Pepite
.findById(req.params.id).exec()
.then((pepite) => {
Expand Down
33 changes: 33 additions & 0 deletions server/api/pepite/test/pepite.api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,37 @@ describe('api: pepite', () => {
})
})
})

describe('When requesting /api/pepite/:id', () => {
describe('When the id is valid and exists', () => {
it('should return a specific pepite', (done) => {
supertest(app)
.get('/api/pepite/1')
.expect(200)
.end((err, res) => {
if (err) {
return done(err)
}
expect(res.body.name).toEqual('ETENA')
done()
})
})
})

describe('When the id is valid but does not exist', () => {
it('should return a not found error', () => {
supertest(app)
.get('/api/pepite/42')
.expect(404)
})
})

describe('When the id is invalid', () => {
it('should return a bad request', () => {
supertest(app)
.get('/api/pepite/invalid_id')
.expect(400)
})
})
})
})

0 comments on commit 5f31f20

Please sign in to comment.