-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathendpoints.app-test.js
More file actions
92 lines (83 loc) · 2.93 KB
/
endpoints.app-test.js
File metadata and controls
92 lines (83 loc) · 2.93 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
import { HTTP } from 'meteor/http';
import { chai } from 'meteor/practicalmeteor:chai';
var assert = chai.assert,
expect = chai.expect;
const testFilesPath = 'test/arpTable/';
describe('API', function() {
it('accepts correct call', function() {
HTTP.call(
'POST',
Meteor.absoluteUrl() + 'routerapi/v1/arp/candra', { headers: { 'Authorization': 'Bearer abcd' }, data: { arpTable: Assets.getText(testFilesPath + 'threeEntries.txt') } },
function(error, result) {
assert(!error, 'there was an error: \n' + error);
assert(result.statusCode == 200, 'Status code didn\'t match 200 it was ' + result.statusCode);
assert(App.Collections.ARPEntries.find().count() >= 3, 'test addresses were not added successfully')
}
);
});
it('no router', function(done) {
HTTP.call('POST', Meteor.absoluteUrl() + 'routerapi/v1/arp/unknown', {},
function(err, res) {
assert.deepEqual(res.data, {
success: false,
message: 'this router does not exist in configuration'
});
assert.equal(res.statusCode, 404);
done();
});
});
it('no authorization token', function(done) {
HTTP.call('POST', Meteor.absoluteUrl() + 'routerapi/v1/arp/candra', {},
function(err, res) {
assert.deepEqual(res.data, {
success: false,
message: 'authorization token missing'
});
assert.equal(res.statusCode, 401);
done();
});
});
it('wrong authorization key', function(done) {
HTTP.call('POST', Meteor.absoluteUrl() + 'routerapi/v1/arp/candra', {
headers: {
Authorization: 'Bearer WRONG'
}
},
function(err, res) {
assert.deepEqual(res.data, {
success: false,
message: 'wrong authorization key'
});
assert.equal(res.statusCode, 401);
done();
});
});
it('no data', function(done) {
console.log(Meteor.absoluteUrl());
HTTP.call('POST', Meteor.absoluteUrl() + 'routerapi/v1/arp/candra', {
headers: {
Authorization: 'Bearer abcd'
}
},
function(err, res) {
assert.deepEqual(res.data, {
success: false,
message: 'invalid request, missing arpTable'
});
assert.equal(res.statusCode, 400);
done();
});
});
it('removes old MAC addresses', function() {
HTTP.call(
'POST',
Meteor.absoluteUrl() + 'routerapi/v1/arp/candra', { headers: { 'Authorization': 'Bearer abcd' }, data: { arpTable: Assets.getText(testFilesPath + 'threeEntries.txt') } }
);
var entriesBefore = App.Collections.ARPEntries.find().count();
result = HTTP.call(
'POST',
Meteor.absoluteUrl() + 'routerapi/v1/arp/candra', { headers: { 'Authorization': 'Bearer abcd' }, data: { arpTable: Assets.getText(testFilesPath + 'twoEntries.txt') } }
);
assert.equal(App.Collections.ARPEntries.find().count(), entriesBefore - 1);
});
});