diff --git a/.travis.yml b/.travis.yml index 00f03cf0c3..966481510e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,14 +16,12 @@ script: - touch ./ts-docs/.nojekyll - if [ "$TRAVIS_NODE_VERSION" = "8" ]; then npm run coveralls-report; fi deploy: - - provider: pages + - provider: script skip_cleanup: true - local_dir: ts-docs - keep_history: true - github_token: $GITHUB_TOKEN + script: /bin/sh travis/github-pages.sh on: branch: master - node_js: "8" + node_js: "9" - provider: script skip_cleanup: true script: /bin/sh travis/uploadArchives.sh diff --git a/src/infrastructure/ChainHttp.ts b/src/infrastructure/ChainHttp.ts index afbbffcc1b..feed73768a 100644 --- a/src/infrastructure/ChainHttp.ts +++ b/src/infrastructure/ChainHttp.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { from as observableFrom, Observable, throwError } from 'rxjs'; -import { catchError, map } from 'rxjs/operators'; +import { Observable } from 'rxjs'; import { ChainRoutesApi } from 'symbol-openapi-typescript-node-client'; import { BlockchainScore } from '../model/blockchain/BlockchainScore'; import { UInt64 } from '../model/UInt64'; @@ -48,10 +47,7 @@ export class ChainHttp extends Http implements ChainRepository { * @returns Observable */ public getBlockchainHeight(): Observable { - return observableFrom(this.chainRoutesApi.getChainHeight()).pipe( - map(({body}) => UInt64.fromNumericString(body.height)), - catchError((error) => throwError(this.errorHandling(error))), - ); + return this.call(this.chainRoutesApi.getChainHeight(), (body) => UInt64.fromNumericString(body.height)); } /** @@ -59,12 +55,10 @@ export class ChainHttp extends Http implements ChainRepository { * @returns Observable */ public getChainScore(): Observable { - return observableFrom(this.chainRoutesApi.getChainScore()).pipe( - map(({body}) => new BlockchainScore( - UInt64.fromNumericString(body.scoreLow), - UInt64.fromNumericString(body.scoreHigh), - )), - catchError((error) => throwError(this.errorHandling(error))), + return this.call(this.chainRoutesApi.getChainScore(), (body) => new BlockchainScore( + UInt64.fromNumericString(body.scoreLow), + UInt64.fromNumericString(body.scoreHigh), + ), ); } } diff --git a/test/infrastructure/ChainHttp.spec.ts b/test/infrastructure/ChainHttp.spec.ts new file mode 100644 index 0000000000..502e39869b --- /dev/null +++ b/test/infrastructure/ChainHttp.spec.ts @@ -0,0 +1,56 @@ +/* + * Copyright 2020 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { expect } from 'chai'; +import * as http from 'http'; +import { ChainRoutesApi, ChainScoreDTO, HeightInfoDTO, } from 'symbol-openapi-typescript-node-client'; +import { instance, mock, reset, when } from 'ts-mockito'; +import { DtoMapping } from '../../src/core/utils/DtoMapping'; +import { ChainHttp } from '../../src/infrastructure/ChainHttp'; +import { ChainRepository } from '../../src/infrastructure/ChainRepository'; + +describe('ChainHttp', () => { + + const url = 'http://someHost'; + const response: http.IncomingMessage = mock(); + const chainRoutesApi: ChainRoutesApi = mock(); + const chainRepository: ChainRepository = DtoMapping.assign(new ChainHttp(url), {chainRoutesApi: instance(chainRoutesApi)}); + + before(() => { + reset(response); + reset(chainRoutesApi); + }); + + it('getBlockchainHeight', async () => { + const heightInfoDTO = new HeightInfoDTO(); + heightInfoDTO.height = '3'; + when(chainRoutesApi.getChainHeight()).thenReturn(Promise.resolve({response, body: heightInfoDTO})); + const heightInfo = await chainRepository.getBlockchainHeight().toPromise(); + expect(heightInfo).to.be.not.null; + expect(heightInfo.toString()).to.be.equals('3'); + }); + + it('getChainScore', async () => { + const chainScoreDTO = new ChainScoreDTO(); + chainScoreDTO.scoreLow = '2'; + chainScoreDTO.scoreHigh = '3'; + when(chainRoutesApi.getChainScore()).thenReturn(Promise.resolve({response, body: chainScoreDTO})); + const chainScore = await chainRepository.getChainScore().toPromise(); + expect(chainScore).to.be.not.null; + expect(chainScore.scoreLow.toString()).to.be.equals('2'); + expect(chainScore.scoreHigh.toString()).to.be.equals('3'); + }); + +}); diff --git a/travis/github-pages.sh b/travis/github-pages.sh new file mode 100644 index 0000000000..a3e78de3d5 --- /dev/null +++ b/travis/github-pages.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -e + +PUBLICATION_BRANCH=gh-pages +# Checkout the branch +REPO_PATH=$PWD +CURRENT_VERSION=$(npm run version --silent) +rm -rf $HOME/publish +cd $HOME +git clone --branch=$PUBLICATION_BRANCH https://${GITHUB_TOKEN}@github.com/$TRAVIS_REPO_SLUG publish 2>&1 > /dev/null +cd publish +# Update pages + +cp -r $REPO_PATH/ts-docs/. ./ +# Commit and push latest version +git add . +git config user.name "Travis" +git config user.email "travis@travis-ci.org" +git commit -m "Uploading $CURRENT_VERSION docs." +git push -fq origin $PUBLICATION_BRANCH 2>&1 > /dev/null +cd $REPO_PATH