35 lines
1001 B
TypeScript
35 lines
1001 B
TypeScript
import { expect } from "chai";
|
|
|
|
import { DPTS, DataPointType } from "../src/index"
|
|
import { BufferLengthError } from "../src/errors/BufferLengthError";
|
|
import { InvalidValueError } from "../src/errors/InvalidValueError";
|
|
|
|
import { compareBuffers } from "./util"
|
|
|
|
|
|
describe("Test DPT001", (): void => {
|
|
|
|
let dpt = new DataPointType();
|
|
const message: string = "0C1E"
|
|
|
|
it("Decode valid", async function () {
|
|
const dpt_ = DataPointType.resolve('DPT9.1')
|
|
expect(dpt_.id).is.equal('9');
|
|
expect(dpt_.decoder(Buffer.from(message, 'hex'))).is.equal(21.08)
|
|
});
|
|
|
|
it("Decode invalid DPT string", async function () {
|
|
var testFunction = function () {
|
|
const dpt_ = DataPointType.resolve('More of the same')
|
|
}
|
|
expect(testFunction).to.throw(InvalidValueError);
|
|
});
|
|
|
|
it("Decode unsupported DPT", async function () {
|
|
var testFunction = function () {
|
|
const dpt_ = DataPointType.resolve('DPT49.1')
|
|
}
|
|
expect(testFunction).to.throw(InvalidValueError);
|
|
});
|
|
});
|