Repository navigation
Expand file tree
/
Copy pathauth.test.js
More file actions
134 lines (126 loc) · 4.47 KB
/
Copy pathauth.test.js
File metadata and controls
134 lines (126 loc) · 4.47 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
const { app } = require('../../../bin/app');
const request = require('supertest')(app);
const should = require('should');
const _ = require('lodash');
const { config } = require('../../../bin/core/config');
describe('api/auth/test.js', function () {
var account = '522539441@qq.com';
var password = '123456';
describe('sign in view', function (done) {
it('should show sign in view successful', function (done) {
request
.get('/auth/login')
.send()
.end(function (err, res) {
should.not.exist(err);
res.status.should.equal(200);
done();
});
});
});
describe('sign up view', function (done) {
it('should show sign in redirect view if sign up not enabled', function (done) {
_.set(config, 'common.allowRegistration', false);
request
.get('/auth/register')
.send()
.end(function (err, res) {
should.not.exist(err);
res.status.should.equal(302);
done();
});
});
it('should show sign up view successful', function (done) {
_.set(config, 'common.allowRegistration', true);
request
.get('/auth/register')
.send()
.end(function (err, res) {
should.not.exist(err);
res.status.should.equal(200);
done();
});
});
});
describe('sign in', function (done) {
it('should not sign in successful when account is empty', function (done) {
request
.post('/auth/login')
.send({
account: '',
password: password,
})
.end(function (err, res) {
should.not.exist(err);
JSON.parse(res.text).should.containEql({
status: 'ERROR',
message: '请您输入邮箱地址',
});
done();
});
});
it('should not sign in successful when account is not exist', function (done) {
request
.post('/auth/login')
.send({
account: account + '1',
password: password,
})
.end(function (err, res) {
should.not.exist(err);
JSON.parse(res.text).should.containEql({
status: 'ERROR',
message: '您输入的邮箱或密码有误',
});
done();
});
});
it('should not sign in successful when password is wrong', function (done) {
request
.post('/auth/login')
.send({
account: account,
password: password + '1',
})
.end(function (err, res) {
should.not.exist(err);
JSON.parse(res.text).should.containEql({
status: 'ERROR',
message: '您输入的邮箱或密码有误',
});
done();
});
});
it('should sign in successful', function (done) {
request
.post('/auth/login')
.send({
account: account,
password: password,
})
.end(function (err, res) {
should.not.exist(err);
JSON.parse(res.text).should.containEql({ status: 'OK' });
done();
});
});
});
describe('logout', function (done) {
it('should logout successful', function (done) {
request.post('/auth/logout').end(function (err, res) {
should.not.exist(err);
res.text.should.equal('ok');
done();
});
});
});
describe('link', function (done) {
it('should link successful', function (done) {
request.get('/auth/link').end(function (err, res) {
should.not.exist(err);
res.headers.location.should.equal('/auth/login');
done();
});
});
});
});