Implemented remaining payload types
This commit is contained in:
34
test/frame.capabilities.test.ts
Normal file
34
test/frame.capabilities.test.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { Frame } from "../src/frame";
|
||||
import type { Payload, StationCapabilitiesPayload } from "../src/frame.types";
|
||||
import { Dissected } from "@hamradio/packet";
|
||||
|
||||
describe("Frame.decodeCapabilities", () => {
|
||||
it("parses comma separated capabilities", () => {
|
||||
const data = "CALL>APRS:<IGATE,MSG_CNT";
|
||||
const frame = Frame.fromString(data);
|
||||
const decoded = frame.decode() as StationCapabilitiesPayload;
|
||||
expect(decoded).not.toBeNull();
|
||||
expect(decoded.type).toBe("capabilities");
|
||||
expect(Array.isArray(decoded.capabilities)).toBeTruthy();
|
||||
expect(decoded.capabilities).toContain("IGATE");
|
||||
expect(decoded.capabilities).toContain("MSG_CNT");
|
||||
});
|
||||
|
||||
it("emits structure sections when requested", () => {
|
||||
const data = "CALL>APRS:<IGATE MSG_CNT>";
|
||||
const frame = Frame.fromString(data);
|
||||
const res = frame.decode(true) as {
|
||||
payload: Payload | null;
|
||||
structure: Dissected;
|
||||
};
|
||||
expect(res.payload).not.toBeNull();
|
||||
if (res.payload && res.payload.type !== "capabilities")
|
||||
throw new Error("expected capabilities payload");
|
||||
expect(res.structure).toBeDefined();
|
||||
const caps = res.structure.find((s) => s.name === "capabilities");
|
||||
expect(caps).toBeDefined();
|
||||
const capEntry = res.structure.find((s) => s.name === "capability");
|
||||
expect(capEntry).toBeDefined();
|
||||
});
|
||||
});
|
||||
38
test/frame.userdefined.test.ts
Normal file
38
test/frame.userdefined.test.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { Dissected } from "@hamradio/packet";
|
||||
import { Frame } from "../src/frame";
|
||||
import type { UserDefinedPayload } from "../src/frame.types";
|
||||
|
||||
describe("Frame.decodeUserDefined", () => {
|
||||
it("parses packet type only", () => {
|
||||
const data = "CALL>APRS:{01";
|
||||
const frame = Frame.fromString(data);
|
||||
const decoded = frame.decode() as UserDefinedPayload;
|
||||
expect(decoded).not.toBeNull();
|
||||
expect(decoded.type).toBe("user-defined");
|
||||
expect(decoded.userPacketType).toBe("01");
|
||||
expect(decoded.data).toBe("");
|
||||
});
|
||||
|
||||
it("parses packet type and data and emits sections", () => {
|
||||
const data = "CALL>APRS:{TEX Hello world";
|
||||
const frame = Frame.fromString(data);
|
||||
const res = frame.decode(true) as {
|
||||
payload: UserDefinedPayload;
|
||||
structure: Dissected;
|
||||
};
|
||||
expect(res.payload).not.toBeNull();
|
||||
expect(res.payload.type).toBe("user-defined");
|
||||
expect(res.payload.userPacketType).toBe("TEX");
|
||||
expect(res.payload.data).toBe("Hello world");
|
||||
|
||||
const raw = res.structure.find((s) => s.name === "user-defined");
|
||||
const typeSection = res.structure.find(
|
||||
(s) => s.name === "user-packet-type",
|
||||
);
|
||||
const dataSection = res.structure.find((s) => s.name === "user-data");
|
||||
expect(raw).toBeDefined();
|
||||
expect(typeSection).toBeDefined();
|
||||
expect(dataSection).toBeDefined();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user