tests: add more tests of web-service example
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent cf5de08 · Browse files · 1 file·+67 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+67 added−6 removed
- tests:+67 added−6 removed
Provenance
- Commit
8d7d80e- Tree
bfa6009- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
cf5de08
1 file changed+67 added−6 removed
modified:test/acceptance/web-service.js+67 added-6 removed
22 unmodified lines232425262728293031272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991004 unmodified lines1051061071084810922 unmodified lines describe('with a valid api key', function(){ it('should respond users json', function(done){ request(app) .get('/api/users?api-key=foo') .end(function(err, res){ res.should.be.json; res.text.should.equal('[{"name":"tobi"},{"name":"loki"},{"name":"jane"}]'); done(); }); .expect('Content-Type', 'application/json; charset=utf-8') .expect(200, '[{"name":"tobi"},{"name":"loki"},{"name":"jane"}]', done) }) }) })
describe('GET /api/repos', function(){ describe('without an api key', function(){ it('should respond with 400 bad request', function(done){ request(app) .get('/api/repos') .expect(400, done); }) })
describe('with an invalid api key', function(){ it('should respond with 401 unauthorized', function(done){ request(app) .get('/api/repos?api-key=rawr') .expect(401, done); }) })
describe('with a valid api key', function(){ it('should respond repos json', function(done){ request(app) .get('/api/repos?api-key=foo') .expect('Content-Type', 'application/json; charset=utf-8') .expect(/"name":"express"/) .expect(/"url":"http:\/\/github.com\/visionmedia\/express"/) .expect(200, done) }) }) })
describe('GET /api/user/:name/repos', function(){ describe('without an api key', function(){ it('should respond with 400 bad request', function(done){ request(app) .get('/api/user/loki/repos') .expect(400, done); }) })
describe('with an invalid api key', function(){ it('should respond with 401 unauthorized', function(done){ request(app) .get('/api/user/loki/repos?api-key=rawr') .expect(401, done); }) })
describe('with a valid api key', function(){ it('should respond user repos json', function(done){ request(app) .get('/api/user/loki/repos?api-key=foo') .expect('Content-Type', 'application/json; charset=utf-8') .expect(/"name":"stylus"/) .expect(/"url":"http:\/\/github.com\/learnboost\/stylus"/) .expect(200, done) })
it('should 404 with unknown user', function(done){ request(app) .get('/api/user/bob/repos?api-key=foo') .expect(404, done) }) }) })
describe('when requesting an invalid route', function(){ it('should respond with 404 json', function(done){ request(app) .get('/api/something?api-key=bar')4 unmodified lines done(); }); }) })})No newline at end of file})