Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Oct 15, 2024
1 parent 6437856 commit 7f0342c
Show file tree
Hide file tree
Showing 23 changed files with 71 additions and 107 deletions.
12 changes: 6 additions & 6 deletions packages/zwave-js/src/lib/driver/Transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ test("NodeQuery comparisons should prioritize listening nodes", (t) => {
) {
const driver = driverMock as any as Driver;
const msg = nodeId != undefined
? new SendDataRequest(driver, {
? new SendDataRequest({
command: new NoOperationCC({
nodeId,
}),
})
: new GetControllerVersionRequest(driver);
: new GetControllerVersionRequest();
const ret = createDummyTransaction(driverMock, {
priority,
message: msg,
Expand Down Expand Up @@ -273,7 +273,7 @@ test("Messages in the wakeup queue should be preferred over lesser priorities on

function createTransaction(nodeId: number, priority: MessagePriority) {
const driver = driverMock as any as Driver;
const msg = new SendDataRequest(driver, {
const msg = new SendDataRequest({
command: new NoOperationCC({ nodeId }),
});
const ret = createDummyTransaction(driverMock, {
Expand Down Expand Up @@ -380,14 +380,14 @@ test("Controller message should be preferred over messages for sleeping nodes",
return ret;
}

const msgForSleepingNode = new SendDataRequest(driverMock, {
command: new NoOperationCC(driverMock, { nodeId: 2 }),
const msgForSleepingNode = new SendDataRequest({
command: new NoOperationCC({ nodeId: 2 }),
});
const tSleepingNode = createTransaction(
msgForSleepingNode,
MessagePriority.WakeUp,
);
const msgForController = new RemoveFailedNodeRequest(driverMock, {
const msgForController = new RemoveFailedNodeRequest({
failedNodeId: 3,
});
const tController = createTransaction(msgForController);
Expand Down
2 changes: 1 addition & 1 deletion packages/zwave-js/src/lib/log/Driver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function createMessage(
driver: Driver,
options: Partial<CreateTransactionOptions>,
) {
return new Message(driver, {
return new Message({
type: options.type || MessageType.Request,
functionType: options.functionType || (0x00 as any),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test("BridgeApplicationCommandRequest can be parsed without RSSI", async (t) =>

// Repro for https://github.com/zwave-js/node-zwave-js/issues/4335
t.notThrows(() =>
Message.from(host, {
Message.from({
data: Buffer.from(
"011200a80001020a320221340000000000000069",
"hex",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test("GetSupportedCommandsResponse with extended bitmask parses correctly (pre-7
"hex",
);

const msg = Message.from(host, {
const msg = Message.from({
data,
sdkVersion: "7.19.0",
ctx: {} as any,
Expand All @@ -32,7 +32,7 @@ test("GetSupportedCommandsResponse with extended bitmask parses correctly (post-
"hex",
);

const msg = Message.from(host, {
const msg = Message.from({
data,
sdkVersion: "7.19.1",
ctx: {} as any,
Expand Down
8 changes: 4 additions & 4 deletions packages/zwave-js/src/lib/test/cc/CRC16CC.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ test("should be detected as an encapsulating CC", (t) => {
nodeId: 3,
targetValue: 89,
});
const crc16 = CRC16CC.encapsulate(host, basicCCSet);
const crc16 = CRC16CC.encapsulate(basicCCSet);
t.true(isEncapsulatingCommandClass(crc16));
});

test("should match the specs", (t) => {
// SDS13783 contains the following sample encapsulated command:
const basicCCGet = new BasicCCGet({ nodeId: 1 });
const crc16 = CRC16CC.encapsulate(host, basicCCGet);
const crc16 = CRC16CC.encapsulate(basicCCGet);
const serialized = crc16.serialize({} as any);
const expected = Buffer.from("560120024d26", "hex");
t.deepEqual(serialized, expected);
Expand All @@ -35,7 +35,7 @@ test("serialization and deserialization should be compatible", (t) => {
nodeId: 3,
targetValue: 89,
});
const crc16 = CRC16CC.encapsulate(host, basicCCSet);
const crc16 = CRC16CC.encapsulate(basicCCSet);
t.is(crc16.nodeId, basicCCSet.nodeId);
t.is(crc16.encapsulated, basicCCSet);
const serialized = crc16.serialize({} as any);
Expand All @@ -58,7 +58,7 @@ test("deserializing a CC with a wrong checksum should result in an invalid CC",
nodeId: 3,
targetValue: 89,
});
const crc16 = CRC16CC.encapsulate(host, basicCCSet);
const crc16 = CRC16CC.encapsulate(basicCCSet);
t.is(crc16.nodeId, basicCCSet.nodeId);
t.is(crc16.encapsulated, basicCCSet);
const serialized = crc16.serialize({} as any);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ integrationTest(

async testBody(t, driver, node, mockController, mockNode) {
// This CC will never be supported (certification requirement)
const cc = new CommandClass(driver, {
const cc = new CommandClass({
nodeId: 2,
ccId: CommandClasses["Anti-Theft"],
ccCommand: 0x02,
Expand Down
14 changes: 3 additions & 11 deletions packages/zwave-js/src/lib/test/cc/MultiChannelCC.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test("is an encapsulating CommandClass", (t) => {
nodeId: 1,
targetValue: 50,
});
cc = MultiChannelCC.encapsulate(host, cc);
cc = MultiChannelCC.encapsulate(cc);
t.true(isEncapsulatingCommandClass(cc));
});

Expand Down Expand Up @@ -85,7 +85,7 @@ test("the CommandEncapsulation command should serialize correctly", (t) => {
targetValue: 5,
endpoint: 7,
});
cc = MultiChannelCC.encapsulate(host, cc);
cc = MultiChannelCC.encapsulate(cc);
const expected = buildCCBuffer(
Buffer.from([
MultiChannelCommand.CommandEncapsulation, // CC Command
Expand Down Expand Up @@ -189,7 +189,6 @@ test("deserializing an unsupported command should return an unspecified version

test("MultiChannelCC/BasicCCGet should expect a response", (t) => {
const ccRequest = MultiChannelCC.encapsulate(
host,
new BasicCCGet({
nodeId: 2,
endpoint: 2,
Expand All @@ -200,7 +199,6 @@ test("MultiChannelCC/BasicCCGet should expect a response", (t) => {

test("MultiChannelCC/BasicCCGet (multicast) should expect NO response", (t) => {
const ccRequest = MultiChannelCC.encapsulate(
host,
new BasicCCGet({
nodeId: 2,
endpoint: 2,
Expand All @@ -213,7 +211,6 @@ test("MultiChannelCC/BasicCCGet (multicast) should expect NO response", (t) => {

test("MultiChannelCC/BasicCCSet should expect NO response", (t) => {
const ccRequest = MultiChannelCC.encapsulate(
host,
new BasicCCSet({
nodeId: 2,
endpoint: 2,
Expand All @@ -225,14 +222,12 @@ test("MultiChannelCC/BasicCCSet should expect NO response", (t) => {

test("MultiChannelCC/BasicCCGet => MultiChannelCC/BasicCCReport = expected", (t) => {
const ccRequest = MultiChannelCC.encapsulate(
host,
new BasicCCGet({
nodeId: 2,
endpoint: 2,
}),
);
const ccResponse = MultiChannelCC.encapsulate(
host,
new BasicCCReport({
nodeId: ccRequest.nodeId,
currentValue: 7,
Expand All @@ -245,14 +240,12 @@ test("MultiChannelCC/BasicCCGet => MultiChannelCC/BasicCCReport = expected", (t)

test("MultiChannelCC/BasicCCGet => MultiChannelCC/BasicCCGet = unexpected", (t) => {
const ccRequest = MultiChannelCC.encapsulate(
host,
new BasicCCGet({
nodeId: 2,
endpoint: 2,
}),
);
const ccResponse = MultiChannelCC.encapsulate(
host,
new BasicCCGet({
nodeId: ccRequest.nodeId,
endpoint: 2,
Expand All @@ -265,13 +258,12 @@ test("MultiChannelCC/BasicCCGet => MultiChannelCC/BasicCCGet = unexpected", (t)

test("MultiChannelCC/BasicCCGet => MultiCommandCC/BasicCCReport = unexpected", (t) => {
const ccRequest = MultiChannelCC.encapsulate(
host,
new BasicCCGet({
nodeId: 2,
endpoint: 2,
}),
);
const ccResponse = MultiCommandCC.encapsulate(host, [
const ccResponse = MultiCommandCC.encapsulate([
new BasicCCReport({
nodeId: ccRequest.nodeId,
currentValue: 7,
Expand Down
2 changes: 1 addition & 1 deletion packages/zwave-js/src/lib/test/cc/MultiCommandCC.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ test("is a multi-encapsulating CommandClass", (t) => {
nodeId: 1,
targetValue: 50,
});
cc = MultiCommandCC.encapsulate(host, [cc]);
cc = MultiCommandCC.encapsulate([cc]);
t.true(isMultiEncapsulatingCommandClass(cc));
});
3 changes: 0 additions & 3 deletions packages/zwave-js/src/lib/test/cc/SupervisionCC.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const host = createTestingHost();

test("SupervisionCCGet should expect a response", (t) => {
const ccRequest = SupervisionCC.encapsulate(
host,
new BasicCCSet({
nodeId: 2,
targetValue: 5,
Expand All @@ -18,7 +17,6 @@ test("SupervisionCCGet should expect a response", (t) => {

test("SupervisionCC/BasicCCSet => SupervisionCCReport (correct session ID) = expected", (t) => {
const ccRequest = SupervisionCC.encapsulate(
host,
new BasicCCSet({
nodeId: 2,
targetValue: 5,
Expand All @@ -36,7 +34,6 @@ test("SupervisionCC/BasicCCSet => SupervisionCCReport (correct session ID) = exp

test("SupervisionCC/BasicCCSet => SupervisionCCReport (wrong session ID) = unexpected", (t) => {
const ccRequest = SupervisionCC.encapsulate(
host,
new BasicCCSet({
nodeId: 2,
targetValue: 5,
Expand Down
2 changes: 0 additions & 2 deletions packages/zwave-js/src/lib/test/cc/WakeUpCC.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ test("WakeUpCCNoMoreInformation should expect no response", (t) => {

test("MultiChannelCC/WakeUpCCNoMoreInformation should expect NO response", (t) => {
const ccRequest = MultiChannelCC.encapsulate(
host,
new WakeUpCCNoMoreInformation({
nodeId: 2,
endpoint: 2,
Expand All @@ -42,7 +41,6 @@ test("SecurityCC/WakeUpCCNoMoreInformation should expect NO response", (t) => {
};

const ccRequest = SecurityCC.encapsulate(
host,
host.ownNodeId,
securityManager as any,
new WakeUpCCNoMoreInformation({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ integrationTest("Response to Z-Wave Plus Info Get", {
},

testBody: async (t, driver, node, mockController, mockNode) => {
const zwpRequest = new ZWavePlusCCGet(mockController.host, {
const zwpRequest = new ZWavePlusCCGet({
nodeId: mockNode.id,
});
await mockNode.sendToController(
Expand Down
26 changes: 13 additions & 13 deletions packages/zwave-js/src/lib/test/driver/assemblePartialCCs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test.afterEach.always(async (t) => {
test.serial("returns true when a non-partial CC is received", (t) => {
const { driver } = t.context;
const cc = new BasicCCSet({ nodeId: 2, targetValue: 50 });
const msg = new ApplicationCommandRequest(driver, {
const msg = new ApplicationCommandRequest({
command: cc,
});
t.true(driver["assemblePartialCCs"](msg));
Expand All @@ -75,7 +75,7 @@ test.serial(
]),
context: {} as any,
});
const msg = new ApplicationCommandRequest(driver, {
const msg = new ApplicationCommandRequest({
command: cc,
});
t.true(driver["assemblePartialCCs"](msg));
Expand All @@ -100,7 +100,7 @@ test.serial(
]),
context: {} as any,
});
const msg = new ApplicationCommandRequest(driver, {
const msg = new ApplicationCommandRequest({
command: cc,
});
t.false(driver["assemblePartialCCs"](msg));
Expand Down Expand Up @@ -139,12 +139,12 @@ test.serial(
]),
context: {} as any,
});
const msg1 = new ApplicationCommandRequest(driver, {
const msg1 = new ApplicationCommandRequest({
command: cc1,
});
t.false(driver["assemblePartialCCs"](msg1));

const msg2 = new ApplicationCommandRequest(driver, {
const msg2 = new ApplicationCommandRequest({
command: cc2,
});
t.true(driver["assemblePartialCCs"](msg2));
Expand All @@ -164,7 +164,7 @@ test.serial("does not crash when receiving a Multi Command CC", (t) => {
nodeId: 2,
encapsulated: [cc1, cc2],
});
const msg = new ApplicationCommandRequest(driver, {
const msg = new ApplicationCommandRequest({
command: cc,
});
t.true(driver["assemblePartialCCs"](msg));
Expand All @@ -181,7 +181,7 @@ test.serial("supports nested partial/non-partial CCs", (t) => {
});
cc.encapsulated = undefined as any;
cc["decryptedCCBytes"] = cc1.serialize({} as any);
const msg = new ApplicationCommandRequest(driver, {
const msg = new ApplicationCommandRequest({
command: cc,
});
t.true(driver["assemblePartialCCs"](msg));
Expand All @@ -206,7 +206,7 @@ test.serial("supports nested partial/partial CCs (part 1)", (t) => {
2,
3,
]);
const msg = new ApplicationCommandRequest(driver, {
const msg = new ApplicationCommandRequest({
command: cc,
});
t.false(driver["assemblePartialCCs"](msg));
Expand All @@ -231,7 +231,7 @@ test.serial("supports nested partial/partial CCs (part 2)", (t) => {
2,
3,
]);
const msg = new ApplicationCommandRequest(driver, {
const msg = new ApplicationCommandRequest({
command: cc,
});
t.true(driver["assemblePartialCCs"](msg));
Expand Down Expand Up @@ -261,7 +261,7 @@ test.serial(
ZWaveErrorCodes.Deserialization_NotImplemented,
);
};
const msg = new ApplicationCommandRequest(driver, {
const msg = new ApplicationCommandRequest({
command: cc,
});
t.false(driver["assemblePartialCCs"](msg));
Expand Down Expand Up @@ -292,7 +292,7 @@ test.serial(
ZWaveErrorCodes.CC_NotImplemented,
);
};
const msg = new ApplicationCommandRequest(driver, {
const msg = new ApplicationCommandRequest({
command: cc,
});
t.false(driver["assemblePartialCCs"](msg));
Expand Down Expand Up @@ -323,7 +323,7 @@ test.serial(
ZWaveErrorCodes.PacketFormat_InvalidPayload,
);
};
const msg = new ApplicationCommandRequest(driver, {
const msg = new ApplicationCommandRequest({
command: cc,
});
t.false(driver["assemblePartialCCs"](msg));
Expand All @@ -349,7 +349,7 @@ test.serial("passes other errors during merging through", (t) => {
cc.mergePartialCCs = () => {
throw new ZWaveError("invalid", ZWaveErrorCodes.Argument_Invalid);
};
const msg = new ApplicationCommandRequest(driver, {
const msg = new ApplicationCommandRequest({
command: cc,
});
t.throws(() => driver["assemblePartialCCs"](msg), { message: /invalid/ });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test.afterEach.always(async (t) => {

test("should compute the correct net payload sizes", (t) => {
const { driver } = t.context;
const testMsg1 = new SendDataRequest(driver, {
const testMsg1 = new SendDataRequest({
command: new SecurityCCCommandEncapsulation({
nodeId: 2,
ownNodeId: driver.ownNodeId,
Expand All @@ -60,7 +60,7 @@ test("should compute the correct net payload sizes", (t) => {
destination: 1,
encapsulated: {} as any,
});
const testMsg2 = new SendDataRequest(driver, {
const testMsg2 = new SendDataRequest({
command: new SecurityCCCommandEncapsulation({
nodeId: 2,
ownNodeId: driver.ownNodeId,
Expand Down
Loading

0 comments on commit 7f0342c

Please sign in to comment.