-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathhardware-error-mappings.test.ts
More file actions
117 lines (104 loc) · 4.44 KB
/
Copy pathhardware-error-mappings.test.ts
File metadata and controls
117 lines (104 loc) · 4.44 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { LEDGER_ERROR_MAPPINGS } from './hardware-error-mappings';
import { ErrorCode, Severity, Category } from './hardware-errors-enums';
describe('HARDWARE_ERROR_MAPPINGS', () => {
describe('Ledger mappings', () => {
const errorMappings = LEDGER_ERROR_MAPPINGS;
it('have errorMappings object', () => {
expect(errorMappings).toBeDefined();
expect(typeof errorMappings).toBe('object');
});
describe('success codes', () => {
it('map 0x9000 to success', () => {
const mapping = errorMappings['0x9000'];
expect(mapping).toBeDefined();
expect(mapping.customCode).toBe(ErrorCode.Success);
expect(mapping.severity).toBe(Severity.Info);
expect(mapping.category).toBe(Category.Success);
});
});
describe('authentication errors', () => {
it('map 0x6300 to authentication failed', () => {
const mapping = errorMappings['0x6300'];
expect(mapping.customCode).toBe(ErrorCode.AuthenticationFailed);
expect(mapping.severity).toBe(Severity.Err);
expect(mapping.category).toBe(Category.Authentication);
expect(mapping.userMessage).toBeDefined();
});
it('map 0x63c0 to PIN attempts remaining', () => {
const mapping = errorMappings['0x63c0'];
expect(mapping.customCode).toBe(
ErrorCode.AuthenticationPinAttemptsRemaining,
);
expect(mapping.severity).toBe(Severity.Warning);
});
it('map 0x5515 to device locked', () => {
const mapping = errorMappings['0x5515'];
expect(mapping.customCode).toBe(ErrorCode.AuthenticationDeviceLocked);
expect(mapping.severity).toBe(Severity.Err);
expect(mapping.userMessage).toContain('unlock');
});
it('map 0x9840 to device blocked', () => {
const mapping = errorMappings['0x9840'];
expect(mapping.customCode).toBe(ErrorCode.AuthenticationDeviceBlocked);
expect(mapping.severity).toBe(Severity.Critical);
});
});
describe('user action errors', () => {
it('map 0x6985 to user rejected', () => {
const mapping = errorMappings['0x6985'];
expect(mapping.customCode).toBe(ErrorCode.UserRejected);
expect(mapping.severity).toBe(Severity.Warning);
expect(mapping.category).toBe(Category.UserAction);
});
it('map 0x5501 to user refused', () => {
const mapping = errorMappings['0x5501'];
expect(mapping.customCode).toBe(ErrorCode.UserRejected);
expect(mapping.severity).toBe(Severity.Warning);
});
});
describe('connection errors', () => {
it('map 0x650f to connection issue', () => {
const mapping = errorMappings['0x650f'];
expect(mapping.customCode).toBe(ErrorCode.ConnClosed);
expect(mapping.category).toBe(Category.Connection);
});
});
it('have valid structure for all mappings', () => {
Object.entries(errorMappings).forEach(([_, mapping]) => {
expect(mapping).toHaveProperty('customCode');
expect(mapping).toHaveProperty('message');
expect(mapping).toHaveProperty('severity');
expect(mapping).toHaveProperty('category');
const numericErrorCodes = Object.values(ErrorCode).filter(
(value): value is number => typeof value === 'number',
);
expect(numericErrorCodes).toContain(mapping.customCode);
expect(Object.values(Severity)).toContain(mapping.severity);
expect(Object.values(Category)).toContain(mapping.category);
expect(typeof mapping.message).toBe('string');
});
});
it('have valid userMessage when present', () => {
const mappingsWithUserMessage = Object.values(errorMappings).filter(
(mapping): mapping is typeof mapping & { userMessage: string } =>
'userMessage' in mapping &&
typeof mapping.userMessage === 'string' &&
mapping.userMessage.length > 0,
);
expect(mappingsWithUserMessage.length).toBeGreaterThan(0);
mappingsWithUserMessage.forEach((mapping) => {
expect(typeof mapping.userMessage).toBe('string');
expect(mapping.userMessage.length).toBeGreaterThan(0);
});
});
});
describe('consistency checks', () => {
it('have unique error codes', () => {
const ledgerCodes = Object.values(LEDGER_ERROR_MAPPINGS);
const ledgerCustomCodes = ledgerCodes.map(
(mapping) => mapping.customCode,
);
expect(ledgerCustomCodes.length).toBeGreaterThan(0);
});
});
});