user 6 lat temu
rodzic
commit
97e4f99f8d

+ 2 - 2
__tests__/index.test.ts

@@ -58,13 +58,13 @@ describe('BankClient', () => {
       nock('http://127.0.0.1:8000')
         .post('/bank/getbalance')
         .reply(200, {
-          what: 'true'
+          balance: 42
         });
       nock('http://127.0.0.1:8000')
       .get('/bank/nonce')
       .reply(200, "42");
       const balance = await bankClient.getBalance();
-      expect(balance).toEqual({what: 'true'});
+      expect(balance).toEqual(42);
     });
   });
 });

+ 1 - 1
lib/index.d.ts

@@ -11,7 +11,7 @@ export declare class BankClient {
     getPub(): Promise<string>;
     bootstrap(): any;
     getNonce(): Promise<number>;
-    getBalance(): Promise<object>;
+    getBalance(): Promise<number>;
     private getPriv;
     private makePlaintextPayload;
 }

+ 3 - 2
lib/index.js

@@ -93,12 +93,13 @@ class BankClient {
                 _nonce: nonce
             }));
             const topicURL = this.urlBase + '/bank/getbalance';
-            const postResponse = this.webClient.requestJSON({
+            const postResponse = yield this.webClient.requestJSON({
                 body: retrieveRequest,
                 method: 'POST',
                 url: topicURL
             });
-            return postResponse;
+            console.log('postResponse', postResponse);
+            return postResponse.balance;
         });
     }
     getPriv() {

Plik diff jest za duży
+ 1 - 1
lib/index.js.map


+ 1 - 1
lib/webclient-node.js

@@ -18,7 +18,7 @@ class WebClientNode {
                 body: options.body,
                 headers: options.headers
             };
-            const result = request(rpOptions);
+            const result = yield request(rpOptions);
             return result;
         });
     }

Plik diff jest za duży
+ 1 - 1
lib/webclient-node.js.map


+ 4 - 3
src/index.ts

@@ -80,7 +80,7 @@ export class BankClient {
       return Number(nonce);
     }
 
-    public async getBalance() {
+    public async getBalance(): Promise<number> {
       const nonce = await this.getNonce();
       const retrieveRequest = await this.makePlaintextPayload(JSON.stringify({
         _date: new Date().toISOString(),
@@ -88,12 +88,13 @@ export class BankClient {
       }));
   
       const topicURL = this.urlBase + '/bank/getbalance';
-      const postResponse = this.webClient.requestJSON({
+      const postResponse:any = await this.webClient.requestJSON({
         body: retrieveRequest,
         method: 'POST',
         url: topicURL
       });
-      return postResponse;
+      console.log('postResponse', postResponse);
+      return postResponse.balance;
     }
 
 

+ 1 - 1
src/webclient-node.ts

@@ -11,7 +11,7 @@ export default class WebClientNode implements IWebClient {
             body: options.body,
             headers: options.headers
         };
-        const result = request(rpOptions);
+        const result = await request(rpOptions);
         return result;
     }