advlib-ble-services
Version:
Wireless advertising packet decoding library for Bluetooth Low Energy service data. We believe in an open Internet of Things.
102 lines (85 loc) • 3.42 kB
JavaScript
/**
* Copyright reelyActive 2015-2026
* We believe in an open Internet of Things
*/
const service = require('../../lib/eddystone.js');
const assert = require ('assert');
// Input data for the scenario
const INPUT_DATA_INVALID_INPUT = 'ff';
const INPUT_DATA_EDDYSTONE_UID = '00fc00112233445566778899aabbccddeeff0000';
const INPUT_DATA_EDDYSTONE_URL = '10000367657470617265746f07';
const INPUT_DATA_EDDYSTONE_TLM = '20000bb815000000004500000258';
const INPUT_DATA_EDDYSTONE_ETLM = '2001112233445566778899aabbcc5a17c4ec';
const INPUT_DATA_EDDYSTONE_EID = '30fc0011223344556677';
const INPUT_DATA_FIND_HUB = '411b0d83b421ea92034602c6b21119d5b626a3ce4bb0';
// Expected outputs for the scenario
const EXPECTED_DATA_INVALID_INPUT = null;
const EXPECTED_DATA_EDDYSTONE_UID = {
txPower: -4,
deviceIds: [ "00112233445566778899/aabbccddeeff" ]
};
const EXPECTED_DATA_EDDYSTONE_URL = {
txPower: 0,
uri: "https://getpareto.com"
};
const EXPECTED_DATA_EDDYSTONE_TLM = {
batteryVoltage: 3.0,
temperature: 21.0,
txCount: 69,
uptime: 60000
};
const EXPECTED_DATA_EDDYSTONE_ETLM = {
encrypted: { data: "112233445566778899aabbcc",
salt: 23063,
checksum: 50412,
method: "eddystone-etlm" }
};
const EXPECTED_DATA_EDDYSTONE_EID = {
txPower: -4,
deviceIds: [ "0011223344556677/0" ]
};
const EXPECTED_DATA_FIND_HUB = {
uri: "https://sniffypedia.org/Service/Find_Hub/"
};
// Describe the scenario
describe('eddystone', function() {
// Test the process function with no input data
it('should handle no input data', function() {
assert.deepEqual(service.process(), EXPECTED_DATA_INVALID_INPUT);
});
// Test the process function with invalid data
it('should handle a invalid data as input', function() {
assert.deepEqual(service.process(INPUT_DATA_INVALID_INPUT),
EXPECTED_DATA_INVALID_INPUT);
});
// Test the process function with valid Eddystone UID data
it('should handle valid Eddystone-UID data as input', function() {
assert.deepEqual(service.process(INPUT_DATA_EDDYSTONE_UID),
EXPECTED_DATA_EDDYSTONE_UID);
});
// Test the process function with valid Eddystone URL data
it('should handle valid Eddystone-URL data as input', function() {
assert.deepEqual(service.process(INPUT_DATA_EDDYSTONE_URL),
EXPECTED_DATA_EDDYSTONE_URL);
});
// Test the process function with valid Eddystone TLM data
it('should handle valid Eddystone-TLM data as input', function() {
assert.deepEqual(service.process(INPUT_DATA_EDDYSTONE_TLM),
EXPECTED_DATA_EDDYSTONE_TLM);
});
// Test the process function with valid Eddystone ETLM data
it('should handle valid Eddystone-ETLM data as input', function() {
assert.deepEqual(service.process(INPUT_DATA_EDDYSTONE_ETLM),
EXPECTED_DATA_EDDYSTONE_ETLM);
});
// Test the process function with valid Eddystone EID data
it('should handle valid Eddystone-EID data as input', function() {
assert.deepEqual(service.process(INPUT_DATA_EDDYSTONE_EID),
EXPECTED_DATA_EDDYSTONE_EID);
});
// Test the process function with valid Find Hub data
it('should handle valid Find Hub data as input', function() {
assert.deepEqual(service.process(INPUT_DATA_FIND_HUB),
EXPECTED_DATA_FIND_HUB);
});
});