Skip to content
Myr

web-service.js

This file

Path

test/acceptance/web-service.js

105 lines · 3.1 KiB · JavaScript

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than 2027b87 point at it.

fix(deps): cookie@0.7.0Josh Bukerbefore adoption2027b87

lines 1–105why, one step back
1
2var request = require('supertest')3 , app = require('../../examples/web-service');45describe('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 })1415 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 })2223 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 })3233 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 })4142 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 })4950 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 })6162 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 })7071 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 })7879 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 })8889 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 })9697 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":"Sorry, can\'t find that"}', done)103 })104 })105})