UNPKG

1.95 kBJavaScriptView Raw
1var expect = require('chai').expect;
2var packet = require('../lib/packet');
3var Packet = packet.Packet;
4var toOctetStringArray = packet.toOctetStringArray;
5
6describe("Packet", function() {
7 describe("#new Packet()", function() {
8
9 var types = [0x1, 0x5, 0xa, 0x1f, 0x21, 0x3d];
10
11 it("should create a new packet with the correct data type", function() {
12 expect(new Packet(types[0]).type).to.equal("Flags");
13 expect(new Packet(types[1]).type).to.equal("Complete List of 32-bit Service Class UUIDs");
14 expect(new Packet(types[2]).type).to.equal("Tx Power Level");
15 expect(new Packet(types[3]).type).to.equal("List of 32-bit Service Solicitation UUIDs");
16 expect(new Packet(types[4]).type).to.equal("Service Data - 128-bit UUID");
17 expect(new Packet(types[5]).type).to.equal("3D Information Data");
18 });
19
20 it("should parse buffers into the correct kind of string", function() {
21 expect(toOctetStringArray(2, new Buffer([15, 89, 254, 14, 37, 89]), null, "BE")).to.have.a.property("length").to.equal(3);
22 expect(toOctetStringArray(4, new Buffer([15, 89, 254, 14]), null, "LE")).to.have.a.property("length").to.equal(1);
23 expect(toOctetStringArray(8, new Buffer([15, 89, 254, 14, 145, 65, 24, 98]), null, "LE")).to.have.a.property("length").to.equal(1);
24 expect(toOctetStringArray(16, new Buffer([15, 89, 254, 14, 145, 65, 24, 98, 15, 89, 254, 14, 145, 65, 24, 98, 15, 89, 254, 14, 145, 65, 24, 98, 15, 89, 254, 14, 145, 65, 24, 98]), null, "LE")).to.have.a.property("length").to.equal(2);
25 });
26
27 it("should make sure packet data is being resolved to the correct type", function() {
28 expect(Array.isArray(new Packet(types[0]).data)).to.equal(true);
29 expect(Array.isArray(new Packet(types[1]).data)).to.equal(true);
30 expect(Array.isArray(new Packet(types[2]).data)).to.equal(false);
31 expect(typeof (new Packet(types[2]).data)).to.equal("number");
32 })
33 });
34});
\No newline at end of file