Skip to content

Commit

Permalink
Fix tests - Enable RPC service
Browse files Browse the repository at this point in the history
  • Loading branch information
rynomster committed Jun 29, 2017
1 parent 244b953 commit 865a76e
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ describe('AppComponent', () => {
}).compileComponents();
}));

it('should create the app', async(() => {
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));
});

/*
it('should render title in a h1 tag', async(() => {
Expand Down
2 changes: 2 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ export class AppComponent implements OnInit {
.filter(route => route.outlet === 'primary')
.flatMap(route => route.data)
.subscribe(data => this.title = data['title']);

this.appService.rpc.poll();
}
}
11 changes: 0 additions & 11 deletions src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,5 @@ export class AppService {
constructor(public rpc: RPCService) {
this.isElectron = this.rpc.electronService.isElectronApp;
rpc.postConstruct(this);
this.testRpc();
}

testRpc(): void {
this.rpc.register(this, 'getwalletinfo', null, this.testRpcResult, 'both');
this.rpc.poll();
//setTimeout(() => { this.rpc.stopPolling() }, 10000);
}

testRpcResult(asd: any) {
console.log(asd);
}
}
6 changes: 5 additions & 1 deletion src/app/core/rpc/rpc.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { TestBed, inject } from '@angular/core/testing';
import { HttpModule } from '@angular/http';

import { RPCService } from './rpc.service';
import { ElectronService } from 'ngx-electron';

describe('RPCService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpModule],
providers: [RPCService]
providers: [
RPCService,
ElectronService
]
});
});

Expand Down
23 changes: 9 additions & 14 deletions src/app/core/rpc/rpc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ export class RPCService {
.post(`http://${this.hostname}:${this.port}`, postData, { headers: headers })
.subscribe(
response => {
//callback(response.json().result);
callback.call(instance, response.json().result);
},
error => {
// TODO: Call error modal?
console.log('RPC Call returned an error', error);
});
// httperr => this._observer.error(error)); // TODO: Handle error
}
}

Expand All @@ -76,24 +78,17 @@ export class RPCService {

poll(): void {
// TODO: Actual polling... Check block height and last transaction
console.log('cb', this._callOnBlock);
this._callOnBlock.forEach(element => {
let _call = (element) => {
this.call(
element.instance,
element.method,
element.params && element.params.typeOf === 'function' ? element.params() : element.params,
element.callback);
});
console.log(this._callOnBlock);
this._callOnTransaction.forEach(element => {
this.call(
element.instance,
element.method,
element.params && element.params.typeOf === 'function' ? element.params() : element.params,
element.callback);
});
};

this._pollTimout = setTimeout(() => { this.poll(); }, 1000);
this._callOnBlock.forEach(_call);
this._callOnTransaction.forEach(_call);
this._pollTimout = setTimeout(() => { this.poll(); }, 3000);
}

startPolling(): void {
Expand Down
11 changes: 10 additions & 1 deletion src/app/overview/overview.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { ElectronService } from 'ngx-electron';

import { OverviewComponent } from './overview.component';

import { SharedModule } from '../shared/shared.module';
import { WalletModule } from '../wallet/wallet.module';
import { AppService } from '../app.service';
import { RPCService } from '../core/rpc/rpc.service';

describe('OverviewComponent', () => {
let component: OverviewComponent;
Expand All @@ -15,7 +19,12 @@ describe('OverviewComponent', () => {
SharedModule,
WalletModule.forRoot()
],
declarations: [ OverviewComponent ]
declarations: [ OverviewComponent ],
providers: [
AppService,
ElectronService,
RPCService
]
})
.compileComponents();
}));
Expand Down
10 changes: 10 additions & 0 deletions src/app/wallet/balances/balance.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { ElectronService } from 'ngx-electron';

import { BalanceComponent } from './balance.component';

import { SharedModule } from '../../shared/shared.module';
import { WalletModule } from '../wallet.module';

import { AppService } from '../../app.service';
import { RPCService } from '../../core/rpc/rpc.service';

describe('BalanceComponent', () => {
let component: BalanceComponent;
let fixture: ComponentFixture<BalanceComponent>;
Expand All @@ -14,6 +19,11 @@ describe('BalanceComponent', () => {
imports: [
SharedModule,
WalletModule.forRoot()
],
providers: [
AppService,
ElectronService,
RPCService
]
})
.compileComponents();
Expand Down
15 changes: 14 additions & 1 deletion src/app/wallet/balances/balance.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import { TestBed, inject } from '@angular/core/testing';

import { ElectronService } from 'ngx-electron';

import { BalanceService } from './balance.service';

import { SharedModule } from '../../shared/shared.module';

import { AppService } from '../../app.service';
import { RPCService } from '../../core/rpc/rpc.service';

describe('BalanceService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [BalanceService]
imports: [SharedModule],
providers: [
BalanceService,
AppService,
ElectronService,
RPCService
]
});
});

Expand Down

0 comments on commit 865a76e

Please sign in to comment.