Skip to content

Judy day 12#15

Open
JudyVue wants to merge 12 commits intocodefellows-seattle-javascript-401d10:masterfrom
JudyVue:judy-day-12
Open

Judy day 12#15
JudyVue wants to merge 12 commits intocodefellows-seattle-javascript-401d10:masterfrom
JudyVue:judy-day-12

Conversation

@JudyVue
Copy link
Copy Markdown

@JudyVue JudyVue commented Sep 28, 2016

No description provided.

Comment thread lab-judy/lib/storage.js Outdated

const Promise = require('bluebird');
const createError = require('http-errors');
const debug = require('debug')('note:storage');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should name your debug module after your model -- so it'll be like 'person:storage'.

Comment thread lab-judy/lib/error-middleware.js Outdated
'use strict';

const createError = require('http-errors');
const debug = require('debug')('note:error-middleware');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should name your debug module after your model -- so it'll be like 'person:storage'.

Comment thread lab-judy/model/person.js
Person.updatePerson = function(id, person) {
debug('updatePerson');
if (!id) return Promise.reject(createError(400, 'bad request'));
if (!person) return Promise.reject(createError(400, 'bad request'));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good error handling!

Comment thread lab-judy/package.json Outdated
"description": "![cf](https://i.imgur.com/7v5ASc8.png) lab 11 single resource express api ======",
"main": "index.js",
"scripts": {
"start": "DEBUG='note*' node server.js",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you change your debug require statements to use the name of your model (which is a best practice), remember to change your scripts to reflect that.

Comment thread lab-judy/package.json
"morgan": "^1.7.0",
"node-uuid": "^1.4.7"
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should manually go in and delete dependencies that are not in the right spot. devDependencies should include chai, eslint, and mocha. Everything else is a regular dependency, and shouldn't be duplicated in dev dependencies.

personRouter.delete('/api/person/:id', function(req, res, next){
debug ('hit route DELETE /api/person');
Person.deletePerson(req.params.id)
.then (() => res.sendStatus(204))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job handling the delete response :)


Person.updatePerson(req.params.id, req.body)
.then ((person) => res.json(person))
.catch (next);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catch(next) is doing the same thing as catch((err) => next(err)) but you should be consistent in your style... so if you write it one way in one route, keep writing it that way.

Comment thread lab-judy/server.js




Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are currently not making use of your error-handling middleware. You'll need an app.use where you pass in your error-handling middleware after your router.

let updatedPerson = {name: 'updated', age: '45'};
request.put(`${url}/api/person/${this.tempPerson.id}`)
.send(updatedPerson)
.end((err, res) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should do error handling in a test where you expect everything to go well (200):

if (err) return next(err);

Comment thread lab-judy/test/person-route-test.js Outdated
});
// * TODO: `POST` - test 200, response body like `{<data>}` for a post request with a valid body
describe('testing for POST request with valid body', function(){
before(done => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to create a person in your database to set up your test environment for POST tests, as you'll be posting a person and you don't need that person to exist beforehand to properly test that route.

Comment thread lab-judy/test/person-route-test.js Outdated
});
// `POST` - test 400, responds with 'bad request' for if no `body provided` or `invalid body`
describe('testing post for bad request if no body provided', function(){
before(done => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above - you won't need to create a person here or delete one (as no person will be created through your POST test if it's a bad request).

Comment thread lab-judy/test/person-route-test.js Outdated
//DELETE - test 404, for a DELETE request with an invalid or missing id
//404 for missing id because DELETE /api/<simple-resource-name>/ is not a route
describe('testing DELETE for request with invalid/missing id', function(){
before(done => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to create a person if you're testing a 404 -- nothing will be deleted if the request is bad or the person is not found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants