import 'jest' import { handleAmioError, AmioApiError } from '../amioService' describe('amioService', () => { describe('handleAmioError', () => { it('throws an error with error message when it is not an amioError', () => { const errorMessage = 'ERROR_MESSAGE' expect(() => { handleAmioError(new Error(errorMessage)) }).toThrowError(new Error(errorMessage)) }) it('throws an error with error message from amioError', () => { const error: AmioApiError = new Error('ERROR_MESSAGE') error.amioApiError = { status: { code: 'CODE', message: 'AMIO_ERROR_MESSAGE' } } expect(() => { handleAmioError(error) }).toThrowError(new Error('amio error: CODE - AMIO_ERROR_MESSAGE')) }) it('throws an error with error message from amioError with erros', () => { const error: AmioApiError = new Error('ERROR_MESSAGE') error.amioApiError = { status: { code: 'CODE', message: 'AMIO_ERROR_MESSAGE' }, errors: [ { message: 'DETAILED_AMIO_ERROR_MESSAGE' }, { message: 'ANOTHER_DETAILED_AMIO_ERROR_MESSAGE' } ] } expect(() => { handleAmioError(error) }).toThrowError( new Error( 'amio error: CODE - AMIO_ERROR_MESSAGE: DETAILED_AMIO_ERROR_MESSAGE, ANOTHER_DETAILED_AMIO_ERROR_MESSAGE' ) ) }) }) })