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){
15 describe('with an invalid api key', function(){
16 it('should respond with 401 unauthorized', function(done){
18 .get('/api/users?api-key=rawr')
23 describe('with a valid api key', function(){
24 it('should respond users json', function(done){
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)
33 describe('GET /api/repos', function(){
34 describe('without an api key', function(){
35 it('should respond with 400 bad request', function(done){
42 describe('with an invalid api key', function(){
43 it('should respond with 401 unauthorized', function(done){
45 .get('/api/repos?api-key=rawr')
50 describe('with a valid api key', function(){
51 it('should respond repos json', function(done){
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"/)
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){
66 .get('/api/user/loki/repos')
71 describe('with an invalid api key', function(){
72 it('should respond with 401 unauthorized', function(done){
74 .get('/api/user/loki/repos?api-key=rawr')
79 describe('with a valid api key', function(){
80 it('should respond user repos json', function(done){
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"/)
89 it('should 404 with unknown user', function(done){
91 .get('/api/user/bob/repos?api-key=foo')
97 describe('when requesting an invalid route', function(){
98 it('should respond with 404 json', function(done){
100 .get('/api/something?api-key=bar')
101 .expect('Content-Type', /json/)
102 .expect(404, '{"error":"Lame, can\'t find that"}', done)