-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.test.ts
More file actions
68 lines (47 loc) · 3.16 KB
/
common.test.ts
File metadata and controls
68 lines (47 loc) · 3.16 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
import { createEncoder, encode } from "../src/EncoderLib";
import { CharacTypeCommon_3_5_0, Charac_DB_common, LoramodeType, TriggerMeasType } from "../src/Sensors/3.5.0/Common";
import { FirmwareVersion, DeviceModel, Characteristic, Operation, UserPayloadType } from "../src/Sensors/Mapping";
describe('ERROR HANDLING', () => {
test('Should throw error when missing UUID', () => {
var charac = { charac_name: "test", ble: "r", lora: "r", payload_size: "3", type: CharacTypeCommon_3_5_0.APP_EUI } as Characteristic
expect(() => encode(charac, Operation.READ, {} as UserPayloadType)).toThrow("UUID field is missing in the characteristic.")
});
test('Should throw error when wrong payload format', () => {
expect(() => encode(Charac_DB_common.battery, Operation.WRITE, {} as UserPayloadType)).toThrow("The payload does not fit with this charactheristic. Take a look at Schemas.")
});
test('Should throw error when Wrong UUID size', () => {
var charac: Characteristic = { charac_name: "test", ble: "r", lora: "r", payload_size: "3", uuid: "A", type: CharacTypeCommon_3_5_0.APP_EUI }
expect(() => encode(charac, Operation.WRITE, {} as UserPayloadType)).toThrow("UUID shall be 2 bytes long.")
});
test('Should throw error when LoRa rights missing from charac object', () => {
var charac = { charac_name: "test", ble: "r", payload_size: "3", uuid: "AABB", type: CharacTypeCommon_3_5_0.APP_EUI } as Characteristic
expect(() => encode(charac, Operation.WRITE, {} as UserPayloadType)).toThrow("LoRa rights needs to be mentionned inside the charac object. Check Schemas.")
});
test('Should throw error when trying to write a read-only parameter', () => {
expect(() => encode(Charac_DB_common.app_eui, Operation.WRITE, {} as UserPayloadType)).toThrow("This charactheristic is not writeable.")
});
test('Trying to write incompatible version lora mode ', () => {
const encoder = createEncoder(FirmwareVersion.V3_5, DeviceModel.SINGLEPOINT)
// @ts-expect-error
let payload: LoramodeType = { mode: "merged", type: CharacTypeCommon_3_5_0.LORA_MODE }
expect(() => encoder.lora_mode.write(payload)[0].toHexString()).toThrow("does not accept this value")
});
})
describe('TRIGGER MEAS', () => {
test('Write trigger measurement', () => {
var payload: TriggerMeasType = { disconnect: true, type: CharacTypeCommon_3_5_0.TRIGGER_MEASUREMENT }
expect(encode(Charac_DB_common.trig_meas, Operation.WRITE, payload).toHexString()).toEqual("01 B3 03 81")
});
})
describe('BASE64', () => {
test('Base64 conversion', () => {
var payload: TriggerMeasType = { disconnect: true, type: CharacTypeCommon_3_5_0.TRIGGER_MEASUREMENT }
expect(encode(Charac_DB_common.trig_meas, Operation.WRITE, payload).toBase64()).toEqual("AbMDgQ==")
});
})
describe('MODEL NUMBER', () => {
test('Read model number', () => {
expect(encode(Charac_DB_common.model_number, Operation.READ, {} as UserPayloadType).toHexString()).toEqual("00 2A 24")
expect(encode(Charac_DB_common.model_number, Operation.READ, {} as UserPayloadType).fport).toEqual(20)
});
})