Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 35998ff

Browse files
committed
fixed previous test, added test for removal of old entries.
1 parent b087e0d commit 35998ff

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

app/imports/server/api/endpoints.app-test.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import { chai } from 'meteor/practicalmeteor:chai';
44
var assert = chai.assert,
55
expect = chai.expect;
66

7-
const CorrectTable = 'IP address HW type Flags HW address Mask Device\r\n192.168.1.11 0x1 0x2 8c:3a:e3:93:83:93 * br0\r\n192.168.1.50 0x1 0x2 00:26:bb:07:54:80 * br0\r\n192.168.1.18 0x1 0x2 3c:15:c2:cc:dc:2a * br0';
8-
7+
const ThreeEntries = 'IP address HW type Flags HW address Mask Device\r\n192.168.1.11 0x1 0x2 8c:3a:e3:93:83:93 * br0\r\n192.168.1.50 0x1 0x2 00:26:bb:07:54:80 * br0\r\n192.168.1.18 0x1 0x2 3c:15:c2:cc:dc:2a * br0';
8+
const TwoEntries = 'IP address HW type Flags HW address Mask Device\r\n192.168.1.11 0x1 0x2 8c:3a:e3:93:83:93 * br0\r\n192.168.1.50 0x1 0x2 00:26:bb:07:54:80 * br0';
99
describe('API', function() {
1010

1111
it('accepts correct call', function() {
1212
HTTP.call(
1313
'POST',
14-
Meteor.absoluteUrl() + 'routerapi/v1/arp/candra',
15-
{ headers: { 'Authorization': 'Bearer abcd' }, data: { arpTable: CorrectTable } },
14+
Meteor.absoluteUrl() + 'routerapi/v1/arp/candra', { headers: { 'Authorization': 'Bearer abcd' }, data: { arpTable: ThreeEntries } },
1615
function(error, result) {
1716
assert(!error, 'there was an error: \n' + error);
1817
assert(result.statusCode == 200, 'Status code didn\'t match 200 it was ' + result.statusCode);
@@ -77,4 +76,26 @@ describe('API', function() {
7776
done();
7877
});
7978
});
79+
80+
it('removes old MAC addresses', function() {
81+
var entriesBefore;
82+
HTTP.call(
83+
'POST',
84+
Meteor.absoluteUrl() + 'routerapi/v1/arp/candra', { headers: { 'Authorization': 'Bearer abcd' }, data: { arpTable: ThreeEntries } },
85+
function(error, result) {
86+
assert(!error, 'there was an error: \n' + error);
87+
assert(result.statusCode == 200, 'Status code didn\'t match 200 it was ' + result.statusCode);
88+
entriesBefore = App.Collections.ARPEntries.find().count();
89+
}
90+
);
91+
HTTP.call(
92+
'POST',
93+
Meteor.absoluteUrl() + 'routerapi/v1/arp/candra', { headers: { 'Authorization': 'Bearer abcd' }, data: { arpTable: TwoEntries } },
94+
function(error, result) {
95+
assert(!error, 'there was an error: \n' + error);
96+
assert(result.statusCode == 200, 'Status code didn\'t match 200 it was ' + result.statusCode);
97+
assert(App.Collections.ARPEntries.find().count() == entriesBefore - 1, 'An entry was not removed correctly');
98+
}
99+
);
100+
});
80101
});

app/server/api/endpoints.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ RouterApi.addRoute(
8282
statusCode: 400,
8383
body: {
8484
success: false,
85-
message: 'invalid request, missing arpTable body: \n ' + JSON.stringify(request.body)
85+
message: 'invalid request, missing arpTable'
8686
}
8787
};
8888
}

0 commit comments

Comments
 (0)