This repository has been archived by the owner on Apr 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.js
105 lines (93 loc) · 2.69 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
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
var chai = require('chai');
var chaiHttp = require('chai-http');
var expect = chai.expect;
chai.use(chaiHttp);
var endpoint = "http://localhost:80";
var test_user_A = {
"device": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"location": {
"longitude": 12345,
"latitude": 54321
}
};
var test_user_B_location_1 = {
"device": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"location": {
"longitude": 1,
"latitude": 1
}
};
var test_user_B_location_2 = {
"device": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"location": {
"longitude": 2,
"latitude": 2
}
};
describe('test location logic', function() {
it('should not return own location', function(done) {
chai.request(endpoint)
.post('/')
.send(test_user_A)
.end(function(err, res) {
expect(err).to.be.null;
expect(res).to.have.status(200);
expect(res).to.be.json;
console.log(res.body)
expect(res.body.locations).to.not.include.keys(test_user_A.device);
done();
});
});
it('should receive previous location from test user A', function(done) {
chai.request(endpoint)
.post('/')
.send(test_user_B_location_1)
.end(function(err, res) {
expect(err).to.be.null;
expect(res).to.have.status(200);
expect(res).to.be.json;
console.log(res.body)
expect(res.body.locations[test_user_A.device])
.to.deep.equal(test_user_A.location)
done();
});
});
it('should save new location test user B', function(done) {
chai.request(endpoint)
.post('/')
.send(test_user_B_location_2)
.end(function(err, res) {
expect(err).to.be.null;
expect(res).to.have.status(200);
expect(res).to.be.json;
done();
});
});
it('should receive new location from test user B', function(done) {
chai.request(endpoint)
.post('/')
.send(test_user_A)
.end(function(err, res) {
expect(err).to.be.null;
expect(res).to.have.status(200);
expect(res).to.be.json;
expect(res.body.locations[test_user_B_location_1.device])
.to.deep.equal(test_user_B_location_2.location)
done();
});
});
// describe('test messaging logic', function() {
// it('should not return own location', function(done) {
// chai.request('http://' + host + ':' + port)
// .post('/')
// .send(test_user_A)
// .end(function(err, res) {
// expect(err).to.be.null;
// expect(res).to.have.status(200);
// expect(res).to.be.json;
// console.log(res.body)
// expect(res.body.locations).to.not.include.keys(test_user_A.device);
// done();
// });
// });
});