-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathhardware-error-mappings.test.ts
More file actions
215 lines (188 loc) · 8.33 KB
/
Copy pathhardware-error-mappings.test.ts
File metadata and controls
215 lines (188 loc) · 8.33 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import {
LEDGER_ERROR_MAPPINGS,
BLE_ERROR_MAPPINGS,
MOBILE_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('has 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.code).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.code).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.code).toBe(ErrorCode.AuthenticationPinAttemptsRemaining);
expect(mapping.severity).toBe(Severity.Warning);
});
it('map 0x5515 to device locked', () => {
const mapping = errorMappings['0x5515'];
expect(mapping.code).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.code).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.code).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.code).toBe(ErrorCode.UserRejected);
expect(mapping.severity).toBe(Severity.Warning);
});
});
describe('connection errors', () => {
it('map 0x650f to connection issue', () => {
const mapping = errorMappings['0x650f'];
expect(mapping.code).toBe(ErrorCode.ConnectionClosed);
expect(mapping.category).toBe(Category.Connection);
});
});
it('has valid structure for all mappings', () => {
Object.entries(errorMappings).forEach(([_, mapping]) => {
expect(mapping).toHaveProperty('code');
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.code);
expect(Object.values(Severity)).toContain(mapping.severity);
expect(Object.values(Category)).toContain(mapping.category);
expect(typeof mapping.message).toBe('string');
});
});
it('has 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('BLE mappings', () => {
const errorMappings = BLE_ERROR_MAPPINGS;
it('has errorMappings object', () => {
expect(errorMappings).toBeDefined();
expect(typeof errorMappings).toBe('object');
});
describe('permission errors', () => {
it('maps BLUETOOTH_PERMISSION_DENIED correctly', () => {
const mapping = errorMappings.BLUETOOTH_PERMISSION_DENIED;
expect(mapping.code).toBe(ErrorCode.PermissionBluetoothDenied);
expect(mapping.severity).toBe(Severity.Err);
expect(mapping.category).toBe(Category.Configuration);
});
it('maps LOCATION_PERMISSION_DENIED correctly', () => {
const mapping = errorMappings.LOCATION_PERMISSION_DENIED;
expect(mapping.code).toBe(ErrorCode.PermissionLocationDenied);
expect(mapping.severity).toBe(Severity.Err);
expect(mapping.category).toBe(Category.Configuration);
expect(mapping.userMessage).toContain('Location');
});
it('maps NEARBY_DEVICES_PERMISSION_DENIED correctly', () => {
const mapping = errorMappings.NEARBY_DEVICES_PERMISSION_DENIED;
expect(mapping.code).toBe(ErrorCode.PermissionNearbyDevicesDenied);
expect(mapping.severity).toBe(Severity.Err);
expect(mapping.category).toBe(Category.Configuration);
});
});
describe('bluetooth state errors', () => {
it('maps BLUETOOTH_DISABLED correctly', () => {
const mapping = errorMappings.BLUETOOTH_DISABLED;
expect(mapping.code).toBe(ErrorCode.BluetoothDisabled);
expect(mapping.severity).toBe(Severity.Warning);
expect(mapping.category).toBe(Category.Connection);
});
it('maps BLUETOOTH_SCAN_FAILED correctly', () => {
const mapping = errorMappings.BLUETOOTH_SCAN_FAILED;
expect(mapping.code).toBe(ErrorCode.BluetoothScanFailed);
expect(mapping.severity).toBe(Severity.Err);
expect(mapping.category).toBe(Category.Connection);
});
it('maps BLUETOOTH_CONNECTION_FAILED correctly', () => {
const mapping = errorMappings.BLUETOOTH_CONNECTION_FAILED;
expect(mapping.code).toBe(ErrorCode.BluetoothConnectionFailed);
expect(mapping.severity).toBe(Severity.Err);
expect(mapping.category).toBe(Category.Connection);
});
});
it('has valid structure for all mappings', () => {
Object.entries(errorMappings).forEach(([_, mapping]) => {
expect(mapping).toHaveProperty('code');
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.code);
expect(Object.values(Severity)).toContain(mapping.severity);
expect(Object.values(Category)).toContain(mapping.category);
expect(typeof mapping.message).toBe('string');
});
});
});
describe('Mobile mappings', () => {
const errorMappings = MOBILE_ERROR_MAPPINGS;
it('has errorMappings object', () => {
expect(errorMappings).toBeDefined();
expect(typeof errorMappings).toBe('object');
});
it('maps NOT_SUPPORTED correctly', () => {
const mapping = errorMappings.NOT_SUPPORTED;
expect(mapping.code).toBe(ErrorCode.MobileNotSupported);
expect(mapping.severity).toBe(Severity.Err);
expect(mapping.category).toBe(Category.DeviceState);
});
it('has valid structure for all mappings', () => {
Object.entries(errorMappings).forEach(([_, mapping]) => {
expect(mapping).toHaveProperty('code');
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.code);
expect(Object.values(Severity)).toContain(mapping.severity);
expect(Object.values(Category)).toContain(mapping.category);
expect(typeof mapping.message).toBe('string');
});
});
});
});