Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpeintner committed Aug 11, 2023
1 parent d7894b1 commit e2dfcb7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
24 changes: 16 additions & 8 deletions packages/binding-opcua/test/full-opcua-thing-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,10 @@ describe("Full OPCUA Thing Test", () => {
thing.setPropertyReadHandler("temperature", async () => temperature);

const expThing = thing as ExposedThing;
const readHandler = expThing.__propertyHandlers.get("temperature").readHandler;
expect(readHandler, "must have a readHandler");
const readHandler = expThing.__propertyHandlers.get("temperature")?.readHandler;
if (!readHandler) {
expect.fail("must have a readHandler");
}
const temperatureCheck1 = await readHandler();
expect(temperatureCheck1).to.equal(10);

Expand Down Expand Up @@ -396,7 +398,7 @@ describe("Full OPCUA Thing Test", () => {
const json2 = await doTest(thing, propertyName, { formIndex: 2 });
expect(json2).to.eql({ Type: 11, Body: 25 });

expect(thingDescription.properties.temperature.forms[3].contentType).eql(
expect(thingDescription.properties?.temperature.forms[3].contentType).eql(
"application/opcua+json;type=DataValue"
);
const json3 = await doTest(thing, propertyName, { formIndex: 3 });
Expand All @@ -423,7 +425,7 @@ describe("Full OPCUA Thing Test", () => {
expect(temperatureBefore).to.eql(27);

// ---------------------------------------------- application/json
expect(thingDescription.properties.temperatureSetPoint.forms[0].contentType).eql("application/json");
expect(thingDescription.properties?.temperatureSetPoint.forms[0].contentType).eql("application/json");
await thing.writeProperty("temperatureSetPoint", 110);
const temperatureAfter = await readTemperature(thing);
expect(temperatureAfter).to.eql(110);
Expand All @@ -436,7 +438,7 @@ describe("Full OPCUA Thing Test", () => {
const { thing, servient } = await makeThing();
try {
// ---------------------------------------------- application/opcua+json;type=DataValue
expect(thingDescription.properties.temperatureSetPoint.forms[3].contentType).eql(
expect(thingDescription.properties?.temperatureSetPoint.forms[3].contentType).eql(
"application/opcua+json;type=DataValue"
);
await thing.writeProperty(
Expand All @@ -455,7 +457,7 @@ describe("Full OPCUA Thing Test", () => {
const { thing, servient } = await makeThing();
try {
// ---------------------------------------------- application/opcua+json;type=Variant
expect(thingDescription.properties.temperatureSetPoint.forms[2].contentType).eql(
expect(thingDescription.properties?.temperatureSetPoint.forms[2].contentType).eql(
"application/opcua+json;type=Variant"
);
await thing.writeProperty("temperatureSetPoint", { Type: 11, Body: 90 }, { formIndex: 2 });
Expand All @@ -475,6 +477,9 @@ describe("Full OPCUA Thing Test", () => {
try {
// read temperature before
const contentA = await thing.invokeAction("setTemperatureSetPoint", { TargetTemperature: 26 });
if (!contentA) {
expect.fail("contentA null");
}
const returnedValue = await contentA.value();

debug(`Temperature setpoint before ${returnedValue}`);
Expand All @@ -498,6 +503,9 @@ describe("Full OPCUA Thing Test", () => {
const contentA = await thing.invokeAction("$OPCUA$setTemperatureSetPoint", {
TargetTemperature: { Type: 11, Body: 26 },
});
if (!contentA) {
expect.fail("contentA null");
}
const returnedValue = await contentA.value();

debug(`Temperature setpoint before ${returnedValue}`);
Expand All @@ -520,7 +528,7 @@ describe("Full OPCUA Thing Test", () => {
SongList: ["Jingle Bell", "Mary has a little lamb"],
Volume: 100,
})
).value();
)?.value();
const returnedValue = content;
debug(`Return value ${JSON.stringify(returnedValue, null, " ")}`);
expect(returnedValue).to.eql({
Expand Down Expand Up @@ -553,7 +561,7 @@ describe("Full OPCUA Thing Test", () => {
SongList: ["Jingle Bell", "Mary has a little lamb"],
Volume: 100,
})
).value();
)?.value();
const returnedValue = content;
debug(`Return value ${JSON.stringify(returnedValue, null, " ")}`);
expect(returnedValue).to.eql({
Expand Down
4 changes: 2 additions & 2 deletions packages/binding-opcua/test/opcua-codec-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { ObjectSchema } from "@node-wot/td-tools";
import { DataValue } from "node-opcua-data-value";
import { DataType, VariantArrayType } from "node-opcua-variant";
import { coerceLocalizedText } from "node-opcua-data-model";
import { opcuaJsonEncodeDataValue } from "node-opcua-json";
import { opcuaJsonEncodeDataValue, DataValueJSON } from "node-opcua-json";
import { StatusCodes } from "node-opcua-status-code";

import { OpcuaBinaryCodec, OpcuaJSONCodec, theOpcuaBinaryCodec, theOpcuaJSONCodec } from "../src/codec";
Expand Down Expand Up @@ -63,7 +63,7 @@ describe("OPCUA Binary Serdes ", () => {
const schema: ObjectSchema = { type: "object", properties: {} };

it("should encode and decode a dataValue with application/opcua+binary codec " + index, () => {
const payload = theOpcuaBinaryCodec.valueToBytes(dataValue, schema);
const payload = theOpcuaBinaryCodec.valueToBytes(dataValue as DataValue | DataValueJSON, schema);
const dataValueReloaded = theOpcuaBinaryCodec.bytesToValue(payload, schema);
expect(dataValue).to.eql(jsonify(dataValueReloaded));
});
Expand Down

0 comments on commit e2dfcb7

Please sign in to comment.