more refactor

This commit is contained in:
DavidVentura
2024-01-31 14:30:30 +01:00
parent 2d2e56231a
commit 89534822ab
4 changed files with 40 additions and 39 deletions
+9 -8
View File
@@ -5,7 +5,7 @@ import assert from "assert";
import { XqBytesDec, XqBytesEnc } from "../func_replacements.js";
import { createResponseForControlCommand } from "../handlers.js";
import { hexdump } from "../hexdump.js";
import { SendDevStatus, SendUsrChk, SendWifiDetails } from "../impl.ts";
import { SendStartVideo, SendDevStatus, SendUsrChk, SendWifiDetails } from "../impl.ts";
import { placeholderTypes, sprintf } from "../utils.js";
describe("debug_tools", () => {
@@ -123,6 +123,11 @@ describe("module", () => {
});
const hstrToBA = (hs) => new Uint8Array(hs.match(/../g).map((h) => parseInt(h, 16))).buffer;
describe("events", () => {
it("emits login event upon logging in", () => {
// TODO
});
});
describe("make packet", () => {
it("builds a good SendUsrChk", () => {
const expected_str =
@@ -132,16 +137,12 @@ describe("make packet", () => {
assert.deepEqual(SendUsrChk(sess, "admin", "admin").buffer, expected);
});
it("builds a good SendStartVideo", () => {
const input_pkt_str = "f1d00018d1000000110a20110c00ff000000000064504737fe010101";
// token-in = 0x64 0x50 0x47 0x37
const _expected_str = "f1d00010d1000000110a10300400000065514636";
// output is 0x3010; 'start video'; hardcoded but shouldnt
const _expected_str = "f1d00010d1000000110a10300400000001020304";
const expected = hstrToBA(_expected_str);
const sess = { outgoingCommandId: 0, ticket: [0, 0, 0, 0] };
const got = createResponseForControlCommand(sess, new DataView(hstrToBA(input_pkt_str)));
const sess = { outgoingCommandId: 0, ticket: [1, 2, 3, 4] };
const got = SendStartVideo(sess);
assert.deepEqual(got.buffer, expected);
assert.deepEqual(sess.ticket, [0x65, 0x51, 0x46, 0x36]);
});
it("builds a good SendDevStatus", () => {
const sess = { outgoingCommandId: 0, ticket: [1, 2, 3, 4] };