1+ import { EventEmitter } from 'events' ;
12import { Store } from '../../../src/store' ;
23import GrpcAction from '../../../src/action/grpc' ;
34import PaymentAction from '../../../src/action/payment' ;
45import TransactionAction from '../../../src/action/transaction' ;
56import NotificationAction from '../../../src/action/notification' ;
67import NavAction from '../../../src/action/nav' ;
78import * as logger from '../../../src/action/log' ;
9+ import { nap } from '../../../src/helper' ;
810
911describe ( 'Action Payments Unit Tests' , ( ) => {
1012 let store ;
@@ -28,9 +30,48 @@ describe('Action Payments Unit Tests', () => {
2830 } ) ;
2931
3032 afterEach ( ( ) => {
33+ clearTimeout ( payment . tOpenUri ) ;
3134 sandbox . restore ( ) ;
3235 } ) ;
3336
37+ describe ( 'listenForUrl()' , ( ) => {
38+ let ipcRendererStub ;
39+
40+ beforeEach ( ( ) => {
41+ ipcRendererStub = new EventEmitter ( ) ;
42+ payment . listenForUrl ( ipcRendererStub ) ;
43+ sandbox . stub ( payment , 'init' ) ;
44+ sandbox . stub ( payment , 'checkType' ) ;
45+ } ) ;
46+
47+ it ( 'should not navigate to payment view for invalid uri' , ( ) => {
48+ const uri = 'invalid-uri' ;
49+ ipcRendererStub . emit ( 'open-url' , 'some-event' , uri ) ;
50+ expect ( payment . init , 'was not called' ) ;
51+ } ) ;
52+
53+ it ( 'should navigate to payment view for valid uri and lndReady' , ( ) => {
54+ store . lndReady = true ;
55+ const uri = 'lightning:lntb100n1pdn2e0app' ;
56+ ipcRendererStub . emit ( 'open-url' , 'some-event' , uri ) ;
57+ expect ( payment . init , 'was called once' ) ;
58+ expect ( store . payment . address , 'to equal' , 'lntb100n1pdn2e0app' ) ;
59+ expect ( payment . checkType , 'was called once' ) ;
60+ } ) ;
61+
62+ it ( 'should wait for lndReady' , async ( ) => {
63+ store . lndReady = false ;
64+ const uri = 'lightning:lntb100n1pdn2e0app' ;
65+ ipcRendererStub . emit ( 'open-url' , 'some-event' , uri ) ;
66+ expect ( payment . init , 'was not called' ) ;
67+ store . lndReady = true ;
68+ await nap ( 300 ) ;
69+ expect ( payment . init , 'was called once' ) ;
70+ expect ( store . payment . address , 'to equal' , 'lntb100n1pdn2e0app' ) ;
71+ expect ( payment . checkType , 'was called once' ) ;
72+ } ) ;
73+ } ) ;
74+
3475 describe ( 'init()' , ( ) => {
3576 it ( 'should clear attributes and navigate to payment view' , ( ) => {
3677 store . payment . address = 'foo' ;
@@ -58,6 +99,41 @@ describe('Action Payments Unit Tests', () => {
5899 } ) ;
59100 } ) ;
60101
102+ describe ( 'checkType()' , ( ) => {
103+ beforeEach ( ( ) => {
104+ sandbox . stub ( payment , 'decodeInvoice' ) ;
105+ } ) ;
106+
107+ it ( 'should notify if address is empty' , async ( ) => {
108+ payment . decodeInvoice . resolves ( true ) ;
109+ await payment . checkType ( ) ;
110+ expect ( notification . display , 'was called once' ) ;
111+ expect ( payment . decodeInvoice , 'was not called' ) ;
112+ } ) ;
113+
114+ it ( 'should decode successfully' , async ( ) => {
115+ store . payment . address = 'some-address' ;
116+ payment . decodeInvoice . resolves ( true ) ;
117+ await payment . checkType ( ) ;
118+ expect ( nav . goPayLightningConfirm , 'was called once' ) ;
119+ } ) ;
120+
121+ it ( 'should notify if not bitcoin address' , async ( ) => {
122+ store . payment . address = 'some-address' ;
123+ payment . decodeInvoice . resolves ( false ) ;
124+ await payment . checkType ( ) ;
125+ expect ( nav . goPayBitcoin , 'was not called' ) ;
126+ expect ( notification . display , 'was called once' ) ;
127+ } ) ;
128+
129+ it ( 'should navigate to bitcoin for valid address' , async ( ) => {
130+ store . payment . address = 'rfu4i1Mo2NF7TQsN9bMVLFSojSzcyQCEH5' ;
131+ payment . decodeInvoice . resolves ( false ) ;
132+ await payment . checkType ( ) ;
133+ expect ( nav . goPayBitcoin , 'was called once' ) ;
134+ } ) ;
135+ } ) ;
136+
61137 describe ( 'decodeInvoice()' , ( ) => {
62138 it ( 'should decode successfully' , async ( ) => {
63139 grpc . sendCommand . withArgs ( 'decodePayReq' ) . resolves ( {
0 commit comments