forked from mailchain/mailchain-web
/
balance.service.spec.ts
72 lines (59 loc) · 2.65 KB
/
balance.service.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { TestBed } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { BalanceService } from './balance.service';
import { MailchainTestService } from 'src/app/test/test-helpers/mailchain-test.service';
import { HttpHelpersService } from '../../helpers/http-helpers/http-helpers.service';
import { ProtocolsServiceStub } from '../protocols/protocols.service.stub';
import { ProtocolsService } from '../protocols/protocols.service';
import { Observable, of } from 'rxjs';
describe('BalanceService', () => {
let balanceService: BalanceService;
let httpTestingController: HttpTestingController;
let mailchainTestService: MailchainTestService
let serverResponse
const currentAccount = '0x92d8f10248c6a3953cc3692a894655ad05d61efb';
const desiredUrl = `http://127.0.0.1:8080/api/addresses/` + currentAccount + `/balance?protocol=ethereum&network=mainnet`
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
HttpHelpersService,
{ provide: ProtocolsService, useClass: ProtocolsServiceStub },
BalanceService,
],
imports: [HttpClientTestingModule]
});
balanceService = TestBed.inject(BalanceService);
mailchainTestService = TestBed.inject(MailchainTestService);
httpTestingController = TestBed.inject(HttpTestingController);
//serverResponse = mailchainTestService.senderAddressesEthereumObserveResponse()
// expectedAddresses = mailchainTestService.senderAddresses()
});
afterEach(() => {
httpTestingController.verify();
});
describe('initUrl', () => {
it('should initialize the url', () => {
balanceService.initUrl()
expect(balanceService['url']).toEqual('http://127.0.0.1:8080/api')
});
})
it('should be created', () => {
expect(balanceService).toBeTruthy();
});
describe('getBalance', () => {
beforeEach(() => {
let obs: Observable<any> = of(mailchainTestService.senderBalanceEthereumObserveResponse())
spyOn(balanceService, 'getBalance').and.returnValue(
obs.toPromise()
)
});
it('should get balance for addresses', async () => {
let result
await balanceService.getBalance(currentAccount, 'ethereum', 'mainnet').then(res => {
result = res
});
expect(result).toEqual(mailchainTestService.senderBalanceEthereumObserveResponse())
expect(balanceService.getBalance).toHaveBeenCalled()
});
})
});