Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 6 additions & 12 deletions src/infrastructure/ChainHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -48,23 +47,18 @@ export class ChainHttp extends Http implements ChainRepository {
* @returns Observable<UInt64>
*/
public getBlockchainHeight(): Observable<UInt64> {
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));
}

/**
* Gets current blockchain score
* @returns Observable<BlockchainScore>
*/
public getChainScore(): Observable<BlockchainScore> {
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),
),
);
}
}
56 changes: 56 additions & 0 deletions test/infrastructure/ChainHttp.spec.ts
Original file line number Diff line number Diff line change
@@ -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');
});

});
21 changes: 21 additions & 0 deletions travis/github-pages.sh
Original file line number Diff line number Diff line change
@@ -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