Skip to content

Commit 0c4577b

Browse files
authored
Merge pull request #491 from NEMStudios/travis-releases
Uploading multiple versions of ts-docs into git hub pages
2 parents 41d6c77 + 50a81ac commit 0c4577b

File tree

4 files changed

+86
-17
lines changed

4 files changed

+86
-17
lines changed

.travis.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@ script:
1616
- touch ./ts-docs/.nojekyll
1717
- if [ "$TRAVIS_NODE_VERSION" = "8" ]; then npm run coveralls-report; fi
1818
deploy:
19-
- provider: pages
19+
- provider: script
2020
skip_cleanup: true
21-
local_dir: ts-docs
22-
keep_history: true
23-
github_token: $GITHUB_TOKEN
21+
script: /bin/sh travis/github-pages.sh
2422
on:
2523
branch: master
26-
node_js: "8"
24+
node_js: "9"
2725
- provider: script
2826
skip_cleanup: true
2927
script: /bin/sh travis/uploadArchives.sh

src/infrastructure/ChainHttp.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { from as observableFrom, Observable, throwError } from 'rxjs';
18-
import { catchError, map } from 'rxjs/operators';
17+
import { Observable } from 'rxjs';
1918
import { ChainRoutesApi } from 'symbol-openapi-typescript-node-client';
2019
import { BlockchainScore } from '../model/blockchain/BlockchainScore';
2120
import { UInt64 } from '../model/UInt64';
@@ -48,23 +47,18 @@ export class ChainHttp extends Http implements ChainRepository {
4847
* @returns Observable<UInt64>
4948
*/
5049
public getBlockchainHeight(): Observable<UInt64> {
51-
return observableFrom(this.chainRoutesApi.getChainHeight()).pipe(
52-
map(({body}) => UInt64.fromNumericString(body.height)),
53-
catchError((error) => throwError(this.errorHandling(error))),
54-
);
50+
return this.call(this.chainRoutesApi.getChainHeight(), (body) => UInt64.fromNumericString(body.height));
5551
}
5652

5753
/**
5854
* Gets current blockchain score
5955
* @returns Observable<BlockchainScore>
6056
*/
6157
public getChainScore(): Observable<BlockchainScore> {
62-
return observableFrom(this.chainRoutesApi.getChainScore()).pipe(
63-
map(({body}) => new BlockchainScore(
64-
UInt64.fromNumericString(body.scoreLow),
65-
UInt64.fromNumericString(body.scoreHigh),
66-
)),
67-
catchError((error) => throwError(this.errorHandling(error))),
58+
return this.call(this.chainRoutesApi.getChainScore(), (body) => new BlockchainScore(
59+
UInt64.fromNumericString(body.scoreLow),
60+
UInt64.fromNumericString(body.scoreHigh),
61+
),
6862
);
6963
}
7064
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2020 NEM
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import { expect } from 'chai';
17+
import * as http from 'http';
18+
import { ChainRoutesApi, ChainScoreDTO, HeightInfoDTO, } from 'symbol-openapi-typescript-node-client';
19+
import { instance, mock, reset, when } from 'ts-mockito';
20+
import { DtoMapping } from '../../src/core/utils/DtoMapping';
21+
import { ChainHttp } from '../../src/infrastructure/ChainHttp';
22+
import { ChainRepository } from '../../src/infrastructure/ChainRepository';
23+
24+
describe('ChainHttp', () => {
25+
26+
const url = 'http://someHost';
27+
const response: http.IncomingMessage = mock();
28+
const chainRoutesApi: ChainRoutesApi = mock();
29+
const chainRepository: ChainRepository = DtoMapping.assign(new ChainHttp(url), {chainRoutesApi: instance(chainRoutesApi)});
30+
31+
before(() => {
32+
reset(response);
33+
reset(chainRoutesApi);
34+
});
35+
36+
it('getBlockchainHeight', async () => {
37+
const heightInfoDTO = new HeightInfoDTO();
38+
heightInfoDTO.height = '3';
39+
when(chainRoutesApi.getChainHeight()).thenReturn(Promise.resolve({response, body: heightInfoDTO}));
40+
const heightInfo = await chainRepository.getBlockchainHeight().toPromise();
41+
expect(heightInfo).to.be.not.null;
42+
expect(heightInfo.toString()).to.be.equals('3');
43+
});
44+
45+
it('getChainScore', async () => {
46+
const chainScoreDTO = new ChainScoreDTO();
47+
chainScoreDTO.scoreLow = '2';
48+
chainScoreDTO.scoreHigh = '3';
49+
when(chainRoutesApi.getChainScore()).thenReturn(Promise.resolve({response, body: chainScoreDTO}));
50+
const chainScore = await chainRepository.getChainScore().toPromise();
51+
expect(chainScore).to.be.not.null;
52+
expect(chainScore.scoreLow.toString()).to.be.equals('2');
53+
expect(chainScore.scoreHigh.toString()).to.be.equals('3');
54+
});
55+
56+
});

travis/github-pages.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
PUBLICATION_BRANCH=gh-pages
5+
# Checkout the branch
6+
REPO_PATH=$PWD
7+
CURRENT_VERSION=$(npm run version --silent)
8+
rm -rf $HOME/publish
9+
cd $HOME
10+
git clone --branch=$PUBLICATION_BRANCH https://${GITHUB_TOKEN}@github.com/$TRAVIS_REPO_SLUG publish 2>&1 > /dev/null
11+
cd publish
12+
# Update pages
13+
14+
cp -r $REPO_PATH/ts-docs/. ./
15+
# Commit and push latest version
16+
git add .
17+
git config user.name "Travis"
18+
git config user.email "travis@travis-ci.org"
19+
git commit -m "Uploading $CURRENT_VERSION docs."
20+
git push -fq origin $PUBLICATION_BRANCH 2>&1 > /dev/null
21+
cd $REPO_PATH

0 commit comments

Comments
 (0)