2 var request
= require('supertest')
3 , app
= require('../../examples/mvc');
5 describe('mvc', function(){
6 describe('GET /', function(){
7 it('should redirect to /users', function(done
){
10 .expect('Location', '/users')
15 describe('GET /pet/0', function(){
16 it('should get pet', function(done
){
19 .expect(200, /Tobi/, done
)
23 describe('GET /pet/0/edit', function(){
24 it('should get pet edit page', function(done
){
28 .expect(200, /Tobi/, done
)
32 describe('PUT /pet/2', function(){
33 it('should update the pet', function(done
){
36 .set('Content-Type', 'application/x-www-form-urlencoded')
37 .send({ pet
: { name
: 'Boots' } })
38 .expect(302, function (err
, res
) {
39 if (err
) return done(err
);
42 .expect(200, /Boots/, done
)
47 describe('GET /users', function(){
48 it('should display a list of users', function(done
){
51 .expect(/<h1>Users<\/h1>/)
53 .expect(/>Guillermo</)
59 describe('GET /user/:id', function(){
60 describe('when present', function(){
61 it('should display the user', function(done
){
64 .expect(200, /<h1>TJ <a href="\/user\/0\/edit">edit/, done
)
67 it('should display the users pets', function(done
){
70 .expect(/\/pet\/0">Tobi/)
71 .expect(/\/pet\/1">Loki/)
72 .expect(/\/pet\/2">Jane/)
77 describe('when not present', function(){
78 it('should 404', function(done
){
86 describe('GET /user/:id/edit', function(){
87 it('should display the edit form', function(done
){
91 .expect(200, /<form/, done
)
95 describe('PUT /user/:id', function(){
96 it('should 500 on error', function(done
){
103 it('should update the user', function(done
){
106 .set('Content-Type', 'application/x-www-form-urlencoded')
107 .send({ user
: { name
: 'Tobo' }})
108 .expect(302, function (err
, res
) {
109 if (err
) return done(err
);
112 .expect(200, /Tobo/, done
)
117 describe('POST /user/:id/pet', function(){
118 it('should create a pet for user', function(done
){
121 .set('Content-Type', 'application/x-www-form-urlencoded')
122 .send({ pet
: { name
: 'Snickers' }})
123 .expect('Location', '/user/2')
124 .expect(302, function(err
, res
){
125 if (err
) return done(err
)
128 .expect(200, /Snickers/, done
)