16
16
import { expect } from 'chai' ;
17
17
import { of as observableOf , of } from 'rxjs' ;
18
18
import { catchError , map } from 'rxjs/operators' ;
19
- import { NetworkConfigurationDTO } from 'symbol-openapi-typescript-fetch-client' ;
19
+ import { NetworkConfigurationDTO , NodeRoutesApi } from 'symbol-openapi-typescript-fetch-client' ;
20
20
import { instance , mock , when } from 'ts-mockito' ;
21
- import { AccountHttp } from '../../src/infrastructure/AccountHttp' ;
22
- import { BlockHttp } from '../../src/infrastructure/BlockHttp' ;
23
- import { ChainHttp } from '../../src/infrastructure/ChainHttp' ;
24
- import { FinalizationHttp } from '../../src/infrastructure/FinalizationHttp' ;
25
- import { HashLockHttp } from '../../src/infrastructure/HashLockHttp' ;
26
- import { Listener } from '../../src/infrastructure/Listener' ;
27
- import { MetadataHttp } from '../../src/infrastructure/MetadataHttp' ;
28
- import { MosaicHttp } from '../../src/infrastructure/MosaicHttp' ;
29
- import { MultisigHttp } from '../../src/infrastructure/MultisigHttp' ;
30
- import { NamespaceHttp } from '../../src/infrastructure/NamespaceHttp' ;
31
- import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository' ;
32
- import { NetworkHttp } from '../../src/infrastructure/NetworkHttp' ;
33
- import { NetworkRepository } from '../../src/infrastructure/NetworkRepository' ;
34
- import { NodeHttp } from '../../src/infrastructure/NodeHttp' ;
35
- import { NodeRepository } from '../../src/infrastructure/NodeRepository' ;
36
- import { ReceiptHttp } from '../../src/infrastructure/ReceiptHttp' ;
37
- import { RepositoryFactoryHttp } from '../../src/infrastructure/RepositoryFactoryHttp' ;
38
- import { RestrictionAccountHttp } from '../../src/infrastructure/RestrictionAccountHttp' ;
39
- import { RestrictionMosaicHttp } from '../../src/infrastructure/RestrictionMosaicHttp' ;
40
- import { SecretLockHttp } from '../../src/infrastructure/SecretLockHttp' ;
41
- import { TransactionGroup } from '../../src/infrastructure/TransactionGroup' ;
42
- import { TransactionHttp } from '../../src/infrastructure/TransactionHttp' ;
43
- import { TransactionStatusHttp } from '../../src/infrastructure/TransactionStatusHttp' ;
44
- import { NetworkCurrencies } from '../../src/model/mosaic/NetworkCurrencies' ;
45
- import { NetworkType } from '../../src/model/network/NetworkType' ;
46
- import { NodeInfo } from '../../src/model/node/NodeInfo' ;
21
+ import {
22
+ AccountHttp ,
23
+ BlockHttp ,
24
+ ChainHttp ,
25
+ FinalizationHttp ,
26
+ HashLockHttp ,
27
+ Listener ,
28
+ MetadataHttp ,
29
+ MosaicHttp ,
30
+ MultisigHttp ,
31
+ NamespaceHttp ,
32
+ NamespaceRepository ,
33
+ NetworkHttp ,
34
+ NetworkRepository ,
35
+ NodeHttp ,
36
+ NodeRepository ,
37
+ ReceiptHttp ,
38
+ RepositoryFactoryHttp ,
39
+ RestrictionAccountHttp ,
40
+ RestrictionMosaicHttp ,
41
+ SecretLockHttp ,
42
+ TransactionGroup ,
43
+ TransactionHttp ,
44
+ TransactionStatusHttp ,
45
+ } from '../../src/infrastructure' ;
46
+ import { NetworkCurrencies } from '../../src/model/mosaic' ;
47
+ import { NetworkType } from '../../src/model/network' ;
48
+ import { NodeInfo } from '../../src/model/node' ;
47
49
48
50
describe ( 'RepositoryFactory' , ( ) => {
49
51
it ( 'Should create repositories' , ( ) => {
@@ -70,6 +72,27 @@ describe('RepositoryFactory', () => {
70
72
expect ( repositoryFactory . createFinalizationRepository ( ) ) . to . be . not . null ;
71
73
} ) ;
72
74
75
+ it ( 'Raise error without unhandled-rejections' , async ( ) => {
76
+ const nodeRoutesApi : NodeRoutesApi = mock ( ) ;
77
+
78
+ const fetchResponseMock : Partial < Response > = {
79
+ status : 666 ,
80
+ statusText : 'Some status text error' ,
81
+ text : ( ) => Promise . resolve ( 'This is the body' ) ,
82
+ } ;
83
+ when ( nodeRoutesApi . getNodeHealth ( ) ) . thenReturn ( Promise . reject ( fetchResponseMock ) ) ;
84
+ const url = 'https://invalid' ;
85
+ const repositoryFactory = new RepositoryFactoryHttp ( url ) ;
86
+ try {
87
+ const nodeRepository = repositoryFactory . createNodeRepository ( ) ;
88
+ ( nodeRepository as any ) . nodeRoutesApi = instance ( nodeRoutesApi ) ;
89
+ await nodeRepository . getNodeHealth ( ) . toPromise ( ) ;
90
+ expect ( true ) . to . be . false ;
91
+ } catch ( e ) {
92
+ expect ( e . message ) . eq ( '{"statusCode":666,"statusMessage":"Some status text error","body":"This is the body"}' ) ;
93
+ }
94
+ } ) ;
95
+
73
96
it ( 'Should get GenerationHash from cache' , ( done ) => {
74
97
let counter = 0 ;
75
98
const repositoryMock : NodeRepository = mock ( ) ;
0 commit comments