forked from koajs/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
33 lines (29 loc) · 768 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var app = require('./app');
var request = require('supertest').agent(app.listen());
var assert = require('assert');
describe('Koa Basic Auth', function(){
describe('with no credentials', function(){
it('should `throw` 401', function(done){
request
.get('/')
.expect(401, done);
})
})
describe('with invalid credentials', function(){
it('should `throw` 401', function(done){
request
.get('/')
.auth('user', 'invalid password')
.expect(401, done);
})
})
describe('with valid credentials', function(){
it('should call the next middleware', function(done){
request
.get('/')
.auth('tj', 'tobi')
.expect(200)
.expect('secret', done);
})
})
})