Skip to content

Commit

Permalink
add unit test for extractFields
Browse files Browse the repository at this point in the history
  • Loading branch information
erossignon committed Jul 15, 2023
1 parent 9024dda commit 1cd110f
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions packages/node-opcua-address-space/test/test_extract_fields.ts
@@ -0,0 +1,84 @@
import fs from "fs";
import should from "should";
import { nodesets } from "node-opcua-nodesets";
import { checkDebugFlag, make_debugLog } from "node-opcua-debug";

import { extractFields, simpleBrowsePathsToString} from "node-opcua-pseudo-session";

import { generateAddressSpace } from "../nodeJS";
import { AddressSpace, PseudoSession } from "..";
import { resolveNodeId } from "node-opcua-nodeid";

const debugLog = make_debugLog("TEST");
const doDebug = checkDebugFlag("TEST");

describe("extractFields", () => {
let addressSpace: AddressSpace;
before(async () => {
const xmlFiles = [nodesets.standard, nodesets.di, nodesets.autoId];
addressSpace = AddressSpace.create();
fs.existsSync(xmlFiles[0]).should.eql(true);
await generateAddressSpace(addressSpace, xmlFiles);
addressSpace.registerNamespace("urn:OwnNamespace");
});
after(() => {
addressSpace.dispose();
});

describe("testing extractFields", () => {
it("on AutoIdScanEventType", async () => {
//
const nsAuditId = addressSpace.getNamespace("http://opcfoundation.org/UA/AutoID/");
should.exist(nsAuditId, "expecting to find AutoID namespace");
const AutoIdScanEventType = nsAuditId.findObjectType("AutoIdScanEventType");
if (!AutoIdScanEventType) throw new Error("");
const session = new PseudoSession(addressSpace);
const e = await extractFields(session, AutoIdScanEventType.nodeId);

const b = simpleBrowsePathsToString(e.map((a) => a.path));
b.sort().should.eql([
"2:DeviceName",
"2:ScanResult",
"ConditionClassId",
"ConditionClassName",
"ConditionSubClassId",
"ConditionSubClassName",
"EventId",
"EventType",
"LocalTime",
"Message",
"ReceiveTime",
"Severity",
"SourceName",
"SourceNode",
"Time"
]);
});
it("on TransitionEventType", async () => {
const session = new PseudoSession(addressSpace);
const e = await extractFields(session, resolveNodeId("TransitionEventType"));
const b = simpleBrowsePathsToString(e.map((a) => a.path));
b.sort().should.eql([
"ConditionClassId",
"ConditionClassName",
"ConditionSubClassId",
"ConditionSubClassName",
"EventId",
"EventType",
"FromState",
"FromState.Id",
"LocalTime",
"Message",
"ReceiveTime",
"Severity",
"SourceName",
"SourceNode",
"Time",
"ToState",
"ToState.Id",
"Transition",
"Transition.Id"
]);
});
});
});

0 comments on commit 1cd110f

Please sign in to comment.