|
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 | 21 | import {
|
22 | 22 | AccountHttp,
|
@@ -73,13 +73,23 @@ describe('RepositoryFactory', () => {
|
73 | 73 | });
|
74 | 74 |
|
75 | 75 | it('Raise error without unhandled-rejections', async () => {
|
76 |
| - const url = 'https://www.google.com'; |
| 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'; |
77 | 85 | const repositoryFactory = new RepositoryFactoryHttp(url);
|
78 | 86 | try {
|
79 |
| - await repositoryFactory.createNodeRepository().getNodeHealth().toPromise(); |
| 87 | + const nodeRepository = repositoryFactory.createNodeRepository(); |
| 88 | + (nodeRepository as any).nodeRoutesApi = instance(nodeRoutesApi); |
| 89 | + await nodeRepository.getNodeHealth().toPromise(); |
80 | 90 | expect(true).to.be.false;
|
81 | 91 | } catch (e) {
|
82 |
| - expect(e.message).contains('{"statusCode":404,"statusMessage":"Not Found","body":"<!DOCTYPE html>'); |
| 92 | + expect(e.message).eq('{"statusCode":666,"statusMessage":"Some status text error","body":"This is the body"}'); |
83 | 93 | }
|
84 | 94 | });
|
85 | 95 |
|
|
0 commit comments