build: update example dependencies
[express.git] / test / acceptance / web-service.js
blobfa2c10bfdb48df0fd7cf5a006c00aeb17372aa07
2 var request = require('supertest')
3   , app = require('../../examples/web-service');
5 describe('web-service', function(){
6   describe('GET /api/users', function(){
7     describe('without an api key', function(){
8       it('should respond with 400 bad request', function(done){
9         request(app)
10         .get('/api/users')
11         .expect(400, done);
12       })
13     })
15     describe('with an invalid api key', function(){
16       it('should respond with 401 unauthorized', function(done){
17         request(app)
18         .get('/api/users?api-key=rawr')
19         .expect(401, done);
20       })
21     })
23     describe('with a valid api key', function(){
24       it('should respond users json', function(done){
25         request(app)
26         .get('/api/users?api-key=foo')
27         .expect('Content-Type', 'application/json; charset=utf-8')
28         .expect(200, '[{"name":"tobi"},{"name":"loki"},{"name":"jane"}]', done)
29       })
30     })
31   })
33   describe('GET /api/repos', function(){
34     describe('without an api key', function(){
35       it('should respond with 400 bad request', function(done){
36         request(app)
37         .get('/api/repos')
38         .expect(400, done);
39       })
40     })
42     describe('with an invalid api key', function(){
43       it('should respond with 401 unauthorized', function(done){
44         request(app)
45         .get('/api/repos?api-key=rawr')
46         .expect(401, done);
47       })
48     })
50     describe('with a valid api key', function(){
51       it('should respond repos json', function(done){
52         request(app)
53         .get('/api/repos?api-key=foo')
54         .expect('Content-Type', 'application/json; charset=utf-8')
55         .expect(/"name":"express"/)
56         .expect(/"url":"https:\/\/github.com\/expressjs\/express"/)
57         .expect(200, done)
58       })
59     })
60   })
62   describe('GET /api/user/:name/repos', function(){
63     describe('without an api key', function(){
64       it('should respond with 400 bad request', function(done){
65         request(app)
66         .get('/api/user/loki/repos')
67         .expect(400, done);
68       })
69     })
71     describe('with an invalid api key', function(){
72       it('should respond with 401 unauthorized', function(done){
73         request(app)
74         .get('/api/user/loki/repos?api-key=rawr')
75         .expect(401, done);
76       })
77     })
79     describe('with a valid api key', function(){
80       it('should respond user repos json', function(done){
81         request(app)
82         .get('/api/user/loki/repos?api-key=foo')
83         .expect('Content-Type', 'application/json; charset=utf-8')
84         .expect(/"name":"stylus"/)
85         .expect(/"url":"https:\/\/github.com\/learnboost\/stylus"/)
86         .expect(200, done)
87       })
89       it('should 404 with unknown user', function(done){
90         request(app)
91         .get('/api/user/bob/repos?api-key=foo')
92         .expect(404, done)
93       })
94     })
95   })
97   describe('when requesting an invalid route', function(){
98     it('should respond with 404 json', function(done){
99       request(app)
100       .get('/api/something?api-key=bar')
101       .expect('Content-Type', /json/)
102       .expect(404, '{"error":"Lame, can\'t find that"}', done)
103     })
104   })