-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstract error handling for addresses into AbstractService (#842)
* Abstract error handling for addresses into AbstractService * Add yarn cache, jest cov and fixed unit test
- Loading branch information
Showing
14 changed files
with
198 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { ApiPromise } from '@polkadot/api'; | ||
import { Hash } from '@polkadot/types/interfaces'; | ||
import { BadRequest, HttpError } from 'http-errors'; | ||
|
||
import { | ||
AbstractService, | ||
EtheuremAddressNotSupported, | ||
} from './AbstractService'; | ||
import { defaultMockApi } from './test-helpers/mock'; | ||
|
||
class TestAbstractService extends AbstractService { | ||
public handleEtheuremAddressError(): HttpError { | ||
return this.createHttpErrorForAddr( | ||
'0x0000000000000000000000000000000000000000', | ||
new Error('Ups! something is wrong.') | ||
); | ||
} | ||
|
||
public handlePolkadotAddressError(): HttpError { | ||
return this.createHttpErrorForAddr( | ||
'EQBwtmKWCyRrQ8yGWg7LkB8p7hpEKXZz4qUg9WR8hZmieCM', | ||
new Error('Ups! something is wrong.') | ||
); | ||
} | ||
} | ||
|
||
const mockApi = { | ||
...defaultMockApi, | ||
at: (_hash: Hash) => ({}), | ||
} as unknown as ApiPromise; | ||
|
||
const testService = new TestAbstractService(mockApi); | ||
|
||
describe('AbstractService', () => { | ||
describe('createHttpErrorForAddr', () => { | ||
it('should throws an error instanceof EtheuremAddressNotSupported', () => { | ||
const err = testService.handleEtheuremAddressError(); | ||
|
||
expect(err.expose).toBeTruthy(); | ||
expect(err.headers).toBeUndefined(); | ||
expect(err.message).not.toBeUndefined(); | ||
expect(err.name).toEqual(EtheuremAddressNotSupported.name); | ||
expect(err.stack).not.toBeUndefined(); | ||
expect(err.status).toEqual(400); | ||
expect(err.statusCode).toEqual(400); | ||
expect(err).toBeInstanceOf(EtheuremAddressNotSupported); | ||
}); | ||
|
||
it('should throws an error instanceof BadRequest', () => { | ||
const err = testService.handlePolkadotAddressError(); | ||
|
||
expect(err.expose).toBeTruthy(); | ||
expect(err.headers).toBeUndefined(); | ||
expect(err.message).not.toBeUndefined(); | ||
expect(err.name).toEqual(BadRequest.name); | ||
expect(err.stack).not.toBeUndefined(); | ||
expect(err.status).toEqual(400); | ||
expect(err.statusCode).toEqual(400); | ||
expect(err).toBeInstanceOf(BadRequest); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.