|
1 | | -import { LEDGER_ERROR_MAPPINGS } from './hardware-error-mappings'; |
| 1 | +import { |
| 2 | + LEDGER_ERROR_MAPPINGS, |
| 3 | + BLE_ERROR_MAPPINGS, |
| 4 | + MOBILE_ERROR_MAPPINGS, |
| 5 | +} from './hardware-error-mappings'; |
2 | 6 | import { ErrorCode, Severity, Category } from './hardware-errors-enums'; |
3 | 7 |
|
4 | 8 | describe('HARDWARE_ERROR_MAPPINGS', () => { |
@@ -102,4 +106,110 @@ describe('HARDWARE_ERROR_MAPPINGS', () => { |
102 | 106 | }); |
103 | 107 | }); |
104 | 108 | }); |
| 109 | + |
| 110 | + describe('BLE mappings', () => { |
| 111 | + const errorMappings = BLE_ERROR_MAPPINGS; |
| 112 | + |
| 113 | + it('has errorMappings object', () => { |
| 114 | + expect(errorMappings).toBeDefined(); |
| 115 | + expect(typeof errorMappings).toBe('object'); |
| 116 | + }); |
| 117 | + |
| 118 | + describe('permission errors', () => { |
| 119 | + it('maps BLUETOOTH_PERMISSION_DENIED correctly', () => { |
| 120 | + const mapping = errorMappings.BLUETOOTH_PERMISSION_DENIED; |
| 121 | + expect(mapping.code).toBe(ErrorCode.PermissionBluetoothDenied); |
| 122 | + expect(mapping.severity).toBe(Severity.Err); |
| 123 | + expect(mapping.category).toBe(Category.Configuration); |
| 124 | + }); |
| 125 | + |
| 126 | + it('maps LOCATION_PERMISSION_DENIED correctly', () => { |
| 127 | + const mapping = errorMappings.LOCATION_PERMISSION_DENIED; |
| 128 | + expect(mapping.code).toBe(ErrorCode.PermissionLocationDenied); |
| 129 | + expect(mapping.severity).toBe(Severity.Err); |
| 130 | + expect(mapping.category).toBe(Category.Configuration); |
| 131 | + expect(mapping.userMessage).toContain('Location'); |
| 132 | + }); |
| 133 | + |
| 134 | + it('maps NEARBY_DEVICES_PERMISSION_DENIED correctly', () => { |
| 135 | + const mapping = errorMappings.NEARBY_DEVICES_PERMISSION_DENIED; |
| 136 | + expect(mapping.code).toBe(ErrorCode.PermissionNearbyDevicesDenied); |
| 137 | + expect(mapping.severity).toBe(Severity.Err); |
| 138 | + expect(mapping.category).toBe(Category.Configuration); |
| 139 | + }); |
| 140 | + }); |
| 141 | + |
| 142 | + describe('bluetooth state errors', () => { |
| 143 | + it('maps BLUETOOTH_DISABLED correctly', () => { |
| 144 | + const mapping = errorMappings.BLUETOOTH_DISABLED; |
| 145 | + expect(mapping.code).toBe(ErrorCode.BluetoothDisabled); |
| 146 | + expect(mapping.severity).toBe(Severity.Warning); |
| 147 | + expect(mapping.category).toBe(Category.Connection); |
| 148 | + }); |
| 149 | + |
| 150 | + it('maps BLUETOOTH_SCAN_FAILED correctly', () => { |
| 151 | + const mapping = errorMappings.BLUETOOTH_SCAN_FAILED; |
| 152 | + expect(mapping.code).toBe(ErrorCode.BluetoothScanFailed); |
| 153 | + expect(mapping.severity).toBe(Severity.Err); |
| 154 | + expect(mapping.category).toBe(Category.Connection); |
| 155 | + }); |
| 156 | + |
| 157 | + it('maps BLUETOOTH_CONNECTION_FAILED correctly', () => { |
| 158 | + const mapping = errorMappings.BLUETOOTH_CONNECTION_FAILED; |
| 159 | + expect(mapping.code).toBe(ErrorCode.BluetoothConnectionFailed); |
| 160 | + expect(mapping.severity).toBe(Severity.Err); |
| 161 | + expect(mapping.category).toBe(Category.Connection); |
| 162 | + }); |
| 163 | + }); |
| 164 | + |
| 165 | + it('has valid structure for all mappings', () => { |
| 166 | + Object.entries(errorMappings).forEach(([_, mapping]) => { |
| 167 | + expect(mapping).toHaveProperty('code'); |
| 168 | + expect(mapping).toHaveProperty('message'); |
| 169 | + expect(mapping).toHaveProperty('severity'); |
| 170 | + expect(mapping).toHaveProperty('category'); |
| 171 | + |
| 172 | + const numericErrorCodes = Object.values(ErrorCode).filter( |
| 173 | + (value): value is number => typeof value === 'number', |
| 174 | + ); |
| 175 | + expect(numericErrorCodes).toContain(mapping.code); |
| 176 | + expect(Object.values(Severity)).toContain(mapping.severity); |
| 177 | + expect(Object.values(Category)).toContain(mapping.category); |
| 178 | + expect(typeof mapping.message).toBe('string'); |
| 179 | + }); |
| 180 | + }); |
| 181 | + }); |
| 182 | + |
| 183 | + describe('Mobile mappings', () => { |
| 184 | + const errorMappings = MOBILE_ERROR_MAPPINGS; |
| 185 | + |
| 186 | + it('has errorMappings object', () => { |
| 187 | + expect(errorMappings).toBeDefined(); |
| 188 | + expect(typeof errorMappings).toBe('object'); |
| 189 | + }); |
| 190 | + |
| 191 | + it('maps NOT_SUPPORTED correctly', () => { |
| 192 | + const mapping = errorMappings.NOT_SUPPORTED; |
| 193 | + expect(mapping.code).toBe(ErrorCode.MobileNotSupported); |
| 194 | + expect(mapping.severity).toBe(Severity.Err); |
| 195 | + expect(mapping.category).toBe(Category.DeviceState); |
| 196 | + }); |
| 197 | + |
| 198 | + it('has valid structure for all mappings', () => { |
| 199 | + Object.entries(errorMappings).forEach(([_, mapping]) => { |
| 200 | + expect(mapping).toHaveProperty('code'); |
| 201 | + expect(mapping).toHaveProperty('message'); |
| 202 | + expect(mapping).toHaveProperty('severity'); |
| 203 | + expect(mapping).toHaveProperty('category'); |
| 204 | + |
| 205 | + const numericErrorCodes = Object.values(ErrorCode).filter( |
| 206 | + (value): value is number => typeof value === 'number', |
| 207 | + ); |
| 208 | + expect(numericErrorCodes).toContain(mapping.code); |
| 209 | + expect(Object.values(Severity)).toContain(mapping.severity); |
| 210 | + expect(Object.values(Category)).toContain(mapping.category); |
| 211 | + expect(typeof mapping.message).toBe('string'); |
| 212 | + }); |
| 213 | + }); |
| 214 | + }); |
105 | 215 | }); |
0 commit comments