-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: fix up route-separation code
closes #2341
- Loading branch information
1 parent
621d074
commit 33bb8fc
Showing
3 changed files
with
111 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
|
||
var app = require('../../examples/route-separation') | ||
var request = require('supertest') | ||
|
||
describe('route-separation', function () { | ||
describe('GET /', function () { | ||
it('should respond with index', function (done) { | ||
request(app) | ||
.get('/') | ||
.expect(200, /Route Separation Example/, done) | ||
}) | ||
}) | ||
|
||
describe('GET /users', function () { | ||
it('should list users', function (done) { | ||
request(app) | ||
.get('/users') | ||
.expect(/TJ/) | ||
.expect(/Tobi/) | ||
.expect(200, done) | ||
}) | ||
}) | ||
|
||
describe('GET /user/:id', function () { | ||
it('should get a user', function (done) { | ||
request(app) | ||
.get('/user/0') | ||
.expect(200, /Viewing user TJ/, done) | ||
}) | ||
|
||
it('should 404 on missing user', function (done) { | ||
request(app) | ||
.get('/user/10') | ||
.expect(404, done) | ||
}) | ||
}) | ||
|
||
describe('GET /user/:id/view', function () { | ||
it('should get a user', function (done) { | ||
request(app) | ||
.get('/user/0/view') | ||
.expect(200, /Viewing user TJ/, done) | ||
}) | ||
|
||
it('should 404 on missing user', function (done) { | ||
request(app) | ||
.get('/user/10/view') | ||
.expect(404, done) | ||
}) | ||
}) | ||
|
||
describe('GET /user/:id/edit', function () { | ||
it('should get a user to edit', function (done) { | ||
request(app) | ||
.get('/user/0/edit') | ||
.expect(200, /Editing user TJ/, done) | ||
}) | ||
}) | ||
|
||
describe('PUT /user/:id/edit', function () { | ||
it('should edit a user', function (done) { | ||
request(app) | ||
.put('/user/0/edit') | ||
.set('Content-Type', 'application/x-www-form-urlencoded') | ||
.send({ user: { name: 'TJ', email: 'tj-invalid@vision-media.ca' } }) | ||
.expect(302, function (err) { | ||
if (err) return done(err) | ||
request(app) | ||
.get('/user/0') | ||
.expect(200, /tj-invalid@vision-media\.ca/, done) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('POST /user/:id/edit?_method=PUT', function () { | ||
it('should edit a user', function (done) { | ||
request(app) | ||
.post('/user/1/edit?_method=PUT') | ||
.set('Content-Type', 'application/x-www-form-urlencoded') | ||
.send({ user: { name: 'Tobi', email: 'tobi-invalid@vision-media.ca' } }) | ||
.expect(302, function (err) { | ||
if (err) return done(err) | ||
request(app) | ||
.get('/user/1') | ||
.expect(200, /tobi-invalid@vision-media\.ca/, done) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('GET /posts', function () { | ||
it('should get a list of posts', function (done) { | ||
request(app) | ||
.get('/posts') | ||
.expect(200, /Posts/, done) | ||
}) | ||
}) | ||
}) |