forked from onestay/CR-Unblocker-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
68 lines (62 loc) · 1.9 KB
/
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
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
/* global describe, it */
// eslint-disable-next-line
process.env.NODE_ENV = 'test';
const chai = require('chai');
const chaiHttp = require('chai-http');
const server = require('./server.js');
// eslint-disable-next-line
const should = chai.should();
chai.use(chaiHttp);
describe('/start_session', () => {
it('should return a valid session id from the cr server', (done) => {
chai.request(server)
.get('/start_session')
.end((err, res) => {
if (err) {
done(`Server returned an error: ${err}`);
}
res.should.have.status(200);
res.body.should.be.a('object');
res.body.should.have.property('data');
res.body.should.have.property('error').eql(false);
res.body.should.have.property('code').eql('ok');
done();
});
});
it('should return an error due to an invalid version', (done) => {
chai.request(server)
.get('/start_session?version=555')
// eslint-disable-next-line
.end((err, res) => {
res.should.have.status(500);
res.body.should.have.property('error').eql(true);
res.body.should.have.property('code').eql('error');
done();
});
});
it('should return an error because auth in v1.0 is not supported', (done) => {
chai.request(server)
.get('/start_session?version=1.0&auth=123')
// eslint-disable-next-line
.end((err, res) => {
res.should.have.status(500);
res.body.should.have.property('error').eql(true);
res.body.should.have.property('code').eql('error');
done();
});
});
it('should return a valid session id with auth provided', (done) => {
chai.request(server)
.get('/start_session?version=1.1&auth=123&user_id=123')
.end((err, res) => {
if (err) {
done(`Server returned an error: ${err}`);
}
res.should.have.status(200);
res.body.should.have.property('data');
res.body.should.have.property('error').eql(false);
res.body.should.have.property('code').eql('ok');
done();
});
});
});