| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import nock from 'nock';
- import { BankClient } from '../src/index';
- import { IWebClient } from '../src/webclient';
- import WebClientNode from '../src/webclient-node';
- import { Storage } from './../src/storage';
- import { IWebClientOptions } from './../src/webclient-options';
- describe('BankClient', () => {
- const storage = new Storage('bankConfig');
- test('should successfully bootstrap', async () => {
- class FakeWebClient implements IWebClient {
- public requestJSON(options: object): Promise<object> {
- throw new Error("Method not implemented.");
- }
- public request(options: IWebClientOptions): Promise<string> {
- throw new Error("Method not implemented.");
- }
- }
- const bankClient = new BankClient('/urlBase', storage, new FakeWebClient());
- const strapped = await bankClient.bootstrap();
- expect(strapped).toBeDefined();
- });
- test('should return hardcoded nonce', async () => {
- class FakeWebClient implements IWebClient {
- public requestJSON(options: object): Promise<object> {
- throw new Error("Method not implemented.");
- }
- public request(options: IWebClientOptions): Promise<string> {
- return Promise.resolve('42');
- }
- }
- const bankClient = new BankClient('/urlBase', storage, new FakeWebClient());
- await bankClient.bootstrap();
- const nonce = await bankClient.getNonce();
- expect(nonce).toEqual(42);
- });
- describe('get nonce', () => {
- test('should work with real http client', async () => {
- const webClient = new WebClientNode();
- const bankClient = new BankClient('http://127.0.0.1:8000', storage, webClient);
- await bankClient.bootstrap();
- nock('http://127.0.0.1:8000')
- .get('/bank/nonce')
- .reply(200, "42");
- const nonce = await bankClient.getNonce();
- expect(nonce).toEqual(42);
- });
- });
- describe('get balance', () => {
- test('should work with real http client', async () => {
- const webClient = new WebClientNode();
- const bankClient = new BankClient('http://127.0.0.1:8000', storage, webClient);
- await bankClient.bootstrap();
- nock('http://127.0.0.1:8000')
- .post('/bank/getbalance')
- .reply(200, {
- what: 'true'
- });
- nock('http://127.0.0.1:8000')
- .get('/bank/nonce')
- .reply(200, "42");
- const balance = await bankClient.getBalance();
- expect(balance).toEqual({what: 'true'});
- });
- });
- });
|