-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom.test.js
More file actions
58 lines (53 loc) · 1.59 KB
/
Copy pathcustom.test.js
File metadata and controls
58 lines (53 loc) · 1.59 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const request = require('supertest');
const assert = require('assert');
const support = require('./support');
const koaAuth = require('../index');
let mark = false;
const app = support.getApp();
app.use(koaAuth({
authorFunc: function () {
return mark;
},
invalidCallback: function (ctx, next) {
ctx.status = 401;
ctx.body = {
message: 'Invalid request'
};
},
exceptUrls: [],
apiRegxStr: '^\/api\/.+',
redirectUrl: '/login2'
}));
let server = support.getServer(app);
describe('test/custom.test.js', () => {
describe('use', () => {
it('should return 302 status with correct url', async () => {
return request(server)
.get('/')
.set('Accept', 'text/html')
.expect(302)
.expect('location', '/login2');
});
it('should return 401 status', async () => {
return request(server)
.get('/login')
.set('Accept', 'application/json')
.expect(401)
});
it('should return 200 status', async () => {
return request(server)
.get('/api/hello')
.set('Accept', 'text/html')
.expect(401);
});
it('should return correct body', async () => {
mark = true;
return request(server)
.get('/api/hello')
.expect(200)
.then(response => {
assert.equal(response.body.message, 'hello world');
});
});
})
});