forked from microbit-foundation/python-editor-v3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard-serial-info.test.ts
52 lines (45 loc) · 1.31 KB
/
board-serial-info.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* (c) 2021, Micro:bit Educational Foundation and contributors
*
* SPDX-License-Identifier: MIT
*/
import { BoardId } from "./board-id";
import { BoardSerialInfo } from "./board-serial-info";
import { vi } from "vitest";
describe("BoardSerialInfo", () => {
const valid = {
serialNumber: "9904360251974e450039900a00000041000000009796990b",
} as USBDevice;
const weirdLength = {
serialNumber: "9904360251974e450039900a000000410000000097969",
} as USBDevice;
const missing = { serialNumber: "" } as USBDevice;
const log = vi.fn();
afterEach(() => {
log.mockReset();
});
it("throws if serialNumber missing", () => {
expect(() => BoardSerialInfo.parse(missing, log)).toThrowError();
expect(log.mock.calls).toEqual([]);
});
it("parses serials", () => {
const result = BoardSerialInfo.parse(valid, log);
expect(result).toEqual({
id: BoardId.parse("9904"),
familyId: "3602",
hic: "9796990b",
});
expect(log.mock.calls).toEqual([]);
});
it("logs if unexpected length", () => {
const result = BoardSerialInfo.parse(weirdLength, log);
expect(result).toEqual({
id: BoardId.parse("9904"),
familyId: "3602",
hic: "00097969",
});
expect(log.mock.calls).toEqual([
["USB serial number unexpected length: 45"],
]);
});
});