@@ -3,11 +3,14 @@ import axios, { AxiosHeaders, AxiosResponse } from 'axios';
33import sinon from 'sinon' ;
44import {
55 NormalizedInput , NormalizedOutput , NormalizedTx , SatoshiBig ,
6+ TxInfo ,
7+ TxStatusType ,
68} from '@/common/types' ;
79import ApiService from '@/common/services/ApiService' ;
810import { BridgeService } from '@/common/services/BridgeService' ;
911import { EnvironmentAccessorService } from '@/common/services/enviroment-accessor.service' ;
1012import * as constants from '@/common/store/constants' ;
13+ import { FlyoverCallFunction , FlyoverCallResult } from '@/common/store/constants' ;
1114import { ApiInformation } from '../../../../src/common/types/ApiInformation' ;
1215
1316const powPegAddress = 'powPegAddress' ;
@@ -439,4 +442,168 @@ describe('Api Service', () => {
439442 expect ( result ) . toEqual ( expectedResponse . data ) ;
440443 } ) ;
441444 } ) ;
445+
446+ describe ( 'Function: registerTx' , ( ) => {
447+ afterEach ( ( ) => {
448+ sinon . restore ( ) ;
449+ } ) ;
450+ it ( 'should resolve when register tx on api db' , async ( ) => {
451+ const expectedResponse = { data : { } } ;
452+ const axiosPostStub = sinon . stub ( axios , 'post' ) . resolves ( expectedResponse ) ;
453+ const txHash = '0x807f14318a2f4bc62ae3a14370c243087464740fb2f5b16763f2fb1635708bb4' ;
454+ const type = 'pegout' ;
455+ const value = '8000000000000000' ;
456+ const wallet = 'Metamask' ;
457+ const result = await ApiService . registerTx (
458+ {
459+ txHash,
460+ type,
461+ value,
462+ wallet,
463+ } ,
464+ ) ;
465+ await expect ( axiosPostStub . calledOnceWithExactly (
466+ `${ ApiService . baseURL } /register` ,
467+ {
468+ txHash,
469+ type,
470+ value,
471+ wallet,
472+ } ,
473+ { headers : { 'Content-Type' : 'application/json' } } ,
474+ ) ) . toBe ( true ) ;
475+ expect ( result ) . toEqual ( expectedResponse . data ) ;
476+ } ) ;
477+ } ) ;
478+
479+ describe ( 'Function: getFeatures' , ( ) => {
480+ afterEach ( ( ) => {
481+ sinon . restore ( ) ;
482+ } ) ;
483+ it ( 'should resolve feature flags configuration' , async ( ) => {
484+ const expectedResponse = {
485+ data : [
486+ {
487+ name : 'flyover_pegout' ,
488+ value : 'enabled' ,
489+ version : 2.3 ,
490+ } ,
491+ {
492+ name : 'flyover_pegin' ,
493+ value : 'enabled' ,
494+ version : 2.3 ,
495+ } ,
496+ {
497+ name : 'terms_and_conditions' ,
498+ value : '# TERMS OF SERVICES' ,
499+ version : 2.3 ,
500+ } ,
501+ {
502+ name : 'wallet_ledger' ,
503+ value : 'enabled' ,
504+ version : 2.3 ,
505+ supportedBrowsers : {
506+ chrome : true ,
507+ firefox : false ,
508+ edge : false ,
509+ opera : false ,
510+ brave : false ,
511+ chromium : false ,
512+ safari : false ,
513+ _id : '67b8e1ee2fc2209df52211ce' ,
514+ } ,
515+ } ,
516+ {
517+ name : 'wallet_trezor' ,
518+ value : 'enabled' ,
519+ version : 2.3 ,
520+ supportedBrowsers : {
521+ chrome : true ,
522+ firefox : true ,
523+ edge : false ,
524+ opera : false ,
525+ brave : false ,
526+ chromium : false ,
527+ safari : false ,
528+ _id : '67b8e1ee2fc2209df52211cf' ,
529+ } ,
530+ } ,
531+ {
532+ name : 'wallet_leather' ,
533+ value : 'enabled' ,
534+ version : 2.3 ,
535+ supportedBrowsers : {
536+ chrome : true ,
537+ firefox : false ,
538+ edge : false ,
539+ opera : false ,
540+ brave : false ,
541+ chromium : false ,
542+ safari : false ,
543+ _id : '67b8e1ee2fc2209df52211d0' ,
544+ } ,
545+ } ,
546+ {
547+ name : 'wallet_xverse' ,
548+ value : 'enabled' ,
549+ version : 2.3 ,
550+ supportedBrowsers : {
551+ chrome : true ,
552+ firefox : false ,
553+ edge : false ,
554+ opera : false ,
555+ brave : false ,
556+ chromium : false ,
557+ safari : false ,
558+ _id : '67b8e1ee2fc2209df52211d1' ,
559+ } ,
560+ } ,
561+ {
562+ name : 'wallet_enkrypt' ,
563+ value : 'enabled' ,
564+ version : 2.3 ,
565+ supportedBrowsers : {
566+ chrome : true ,
567+ firefox : false ,
568+ edge : false ,
569+ opera : false ,
570+ brave : false ,
571+ chromium : false ,
572+ safari : false ,
573+ _id : '67b8e1ee2fc2209df52211d2' ,
574+ } ,
575+ } ,
576+ ] ,
577+ } ;
578+ const axiosGetStub = sinon . stub ( axios , 'get' ) . resolves ( expectedResponse ) ;
579+ const result = await ApiService . getFeatures ( ) ;
580+ expect ( axiosGetStub . calledOnceWithExactly ( `${ ApiService . baseURL } /features` ) )
581+ . toBe ( true ) ;
582+ expect ( result ) . toEqual ( expectedResponse . data ) ;
583+ } ) ;
584+ } ) ;
585+
586+ describe ( 'Function: registerFlyoverCall' , ( ) => {
587+ afterEach ( ( ) => {
588+ sinon . restore ( ) ;
589+ } ) ;
590+ it ( 'should resolve when register LPS call on api logs' , async ( ) => {
591+ const expectedResponse = { data : { } } ;
592+ const axiosPostStub = sinon . stub ( axios , 'post' ) . resolves ( expectedResponse ) ;
593+ const operationType = TxStatusType . FLYOVER_PEGIN ;
594+ const functionType = FlyoverCallFunction . LPS ;
595+ const res = FlyoverCallResult . SUCCESS ;
596+ const result = await ApiService . registerFlyoverCall ( {
597+ operationType,
598+ functionType,
599+ result : res ,
600+ } ) ;
601+ expect ( axiosPostStub . calledOnceWithExactly ( `${ ApiService . baseURL } /register-flyover-call` , {
602+ operationType,
603+ functionType,
604+ result : res ,
605+ } ) ) . toBe ( true ) ;
606+ expect ( result ) . toEqual ( expectedResponse . data ) ;
607+ } ) ;
608+ } ) ;
442609} ) ;
0 commit comments