1 | var expect = require('chai').expect;
|
2 | var parser = require('../lib/parser');
|
3 |
|
4 | describe("Parser", function() {
|
5 |
|
6 | var testPayload = new Buffer([27, 2, 1, 6, 17, 6, 186, 86, 137, 166, 250, 191, 162, 189, 1, 70, 125, 110, 56, 88, 171, 173, 5, 22, 10, 24, 7, 4]);
|
7 |
|
8 | describe("#split()", function() {
|
9 | it("should split up an advertisement packet into distinct data formats", function() {
|
10 | expect(parser.split(testPayload).length).to.equal(3);
|
11 | });
|
12 | });
|
13 |
|
14 | describe("#parse()", function() {
|
15 | it ("should create the correct number of packets", function() {
|
16 | var parsed = parser.parse(testPayload);
|
17 | expect(parsed.length).to.equal(3);
|
18 | });
|
19 | it("should properly parse a payload into the correct kinds of data", function() {
|
20 | var parsed = parser.parse(testPayload);
|
21 | parsed.forEach(function(packet) {
|
22 | expect(packet.type).to.not.equal("Unknown");
|
23 | expect(packet.byteOrder).to.not.equal(undefined);
|
24 | });
|
25 |
|
26 | expect(parsed[0].type).to.equal("Flags");
|
27 | expect(parsed[0].data.length).to.equal(1);
|
28 |
|
29 | expect(parsed[1].type).to.equal('Incomplete List of 128-bit Service Class UUIDs');
|
30 | expect(parsed[1].data.length).to.equal(1);
|
31 |
|
32 | expect(parsed[2].type).to.equal('Service Data');
|
33 | expect(parsed[2].data.length).to.equal(4);
|
34 | expect(parsed[1].data[0]).to.equal('0xadab58386e7d4601bda2bffaa68956ba');
|
35 | });
|
36 |
|
37 | it("should be able to switch byte order of bytes based on endian-ness", function() {
|
38 | var parsed = parser.parseLE(testPayload);
|
39 | expect(parsed[1].data[0]).to.equal('0xba5689a6fabfa2bd01467d6e3858abad');
|
40 |
|
41 | var parsed = parser.parseBE(testPayload);
|
42 | expect(parsed[1].data[0]).to.equal('0xadab58386e7d4601bda2bffaa68956ba');
|
43 | });
|
44 | });
|
45 | }); |
\ | No newline at end of file |