tests: add more tests of mvc example
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 83b8b7a · Browse files · 2 files·+52 added−14 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+52 added−14 removed
- tests:+51 added−13 removed
- other:+1 added−1 removed
Provenance
- Commit
602e5a8- Tree
8ab50a1- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
83b8b7a
2 files changed+52 added−14 removed
modified:examples/mvc/controllers/pet/index.js+1 added-1 removed
18 unmodified lines19202122232324252618 unmodified lines};
exports.update = function(req, res, next){ var body = req.body; req.pet.name = body.user.name; req.pet.name = body.pet.name; res.message('Information updated!'); res.redirect('/pet/' + req.pet.id);};modified:test/acceptance/mvc.js+51 added-13 removed
5 unmodified lines678910111213141516171819202122232425262728293031323334353637111213383940414243444546 unmodified lines9293949568697071729697989910010110210310410510610710810984858687110111112113114115116117118119120121122123124125911261271281295 unmodified lines describe('GET /', function(){ it('should redirect to /users', function(done){ request(app) .get('/') .expect('Location', '/users') .expect(302, done) }) })
describe('GET /pet/0', function(){ it('should get pet', function(done){ request(app) .get('/pet/0') .expect(200, /Tobi/, done) }) })
describe('GET /pet/0/edit', function(){ it('should get pet edit page', function(done){ request(app) .get('/pet/0/edit') .expect(/<form/) .expect(200, /Tobi/, done) }) })
describe('PUT /pet/2', function(){ it('should update the pet', function(done){ request(app) .put('/pet/3') .send({ pet: { name: 'Boots' } }) .end(function(err, res){ res.should.have.status(302); res.headers.location.should.include('/users'); done(); if (err) return done(err); request(app) .get('/pet/3/edit') .expect(200, /Boots/, done) }) }) })
46 unmodified lines describe('GET /user/:id/edit', function(){ it('should display the edit form', function(done){ request(app) .get('/user/1/edit') .end(function(err, res){ res.text.should.include('<h1>Guillermo</h1>'); res.text.should.include('value="put"'); done(); }) .expect(/Guillermo/) .expect(200, /<form/, done) }) })
describe('PUT /user/:id', function(){ it('should update the user', function(done){ request(app) .put('/user/1') .send({ user: { name: 'Tobo' }}) .end(function(err, res){ if (err) return done(err); request(app) .get('/user/1/edit') .end(function(err, res){ res.text.should.include('<h1>Tobo</h1>'); done(); }) .expect(200, /Tobo/, done) }) }) })
describe('POST /user/:id/pet', function(){ it('should create a pet for user', function(done){ request(app) .post('/user/2/pet') .send({ pet: { name: 'Snickers' }}) .expect('Location', '/user/2') .expect(302, function(err, res){ if (err) return done(err) request(app) .get('/user/2') .expect(200, /Snickers/, done)}) }) }) })})