Skip to content

Commit ed4e5e4

Browse files
committed
feat: add tests
1 parent 82594e1 commit ed4e5e4

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/common.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*****************************************************************************/
1616
import { processErrorResponse } from './common'
17-
import { LedgerError } from './consts'
17+
import { LedgerCustomError, LedgerError } from './consts'
1818
import { errorCodeToString } from './errors'
1919
import { ResponseError } from './responseError'
2020

@@ -25,6 +25,18 @@ describe('errorCodeToString', () => {
2525
expect(errorCodeToString(knownErrorCode)).toEqual(expectedMessage)
2626
})
2727

28+
it('should return the correct error message for a custom error code', () => {
29+
const knownErrorCode: LedgerCustomError = 0xabcd
30+
const expectedMessage = 'test custom error'
31+
expect(errorCodeToString(knownErrorCode, { 0xabcd: expectedMessage })).toEqual(expectedMessage)
32+
})
33+
34+
it('should return the correct error message for a known error code, when a custom error list is passed', () => {
35+
const knownErrorCode: LedgerError = 0x9000
36+
const expectedMessage = 'No errors'
37+
expect(errorCodeToString(knownErrorCode, { [knownErrorCode]: 'Custom no errors' })).toEqual(expectedMessage)
38+
})
39+
2840
it('should return "Unknown Return Code" for an unknown error code', () => {
2941
const unknownErrorCode: LedgerError = 0x9999 as LedgerError
3042
const expectedMessage = 'Unknown Return Code: 0x9999'

0 commit comments

Comments
 (0)