forked from koajs/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
36 lines (32 loc) · 824 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
34
35
36
const app = require('./app');
const server = app.listen();
const request = require('supertest').agent(server);
describe('Koa Basic Auth', function() {
after(function() {
server.close();
});
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);
});
});
});