@@ -72,53 +72,33 @@ describe('sagas/nanoContract/fetchHistory', () => {
72
72
} ) ;
73
73
74
74
describe ( 'sagas/nanoContract/requestHistoryNanoContract' , ( ) => {
75
- test ( 'history loading' , ( ) => {
76
- // arrange Nano Contract registration inputs
77
- const { ncId } = fixtures ;
78
-
79
- // call effect to request history
80
- const gen = requestHistoryNanoContract ( nanoContractHistoryRequest ( { ncId } ) ) ;
81
- // select wallet
82
- gen . next ( ) ;
83
- // feed back historyMeta
84
- gen . next ( { [ ncId ] : { isLoading : true , after : null } } ) ;
85
-
86
- // assert termination
87
- expect ( gen . next ( ) . value ) . toBeUndefined ( ) ;
88
- } ) ;
89
-
90
75
test ( 'history without registered contract' , ( ) => {
91
76
// arrange Nano Contract registration inputs
92
- const { ncId } = fixtures ;
77
+ const { address , ncId } = fixtures ;
93
78
94
79
// call effect to request history
95
- const gen = requestHistoryNanoContract ( nanoContractHistoryRequest ( { ncId } ) ) ;
80
+ const gen = requestHistoryNanoContract ( nanoContractHistoryRequest ( { address , ncId } ) ) ;
96
81
// select wallet
97
82
gen . next ( ) ;
98
- // feed back historyMeta
99
- gen . next ( { } ) ;
100
83
// feed back wallet
101
84
gen . next ( fixtures . wallet . readyAndMine ) ;
102
85
103
86
// expect failure
104
87
// feed back isNanoContractRegistered
105
- expect ( gen . next ( false ) . value ) . toStrictEqual (
106
- put ( nanoContractHistoryFailure ( { ncId, error : failureMessage . notRegistered } ) )
107
- ) ;
88
+ expect ( gen . next ( false ) . value )
89
+ . toStrictEqual ( put ( nanoContractHistoryFailure ( failureMessage . notRegistered ) ) ) ;
108
90
} ) ;
109
91
110
92
test ( 'fetch history fails' , ( ) => {
111
93
// arrange Nano Contract registration inputs
112
- const { ncId } = fixtures ;
94
+ const { address , ncId } = fixtures ;
113
95
const storage = STORE . getStorage ( ) ;
114
96
storage . registerNanoContract ( ncId , { ncId } ) ;
115
97
116
98
// call effect to request history
117
- const gen = requestHistoryNanoContract ( nanoContractHistoryRequest ( { ncId } ) ) ;
99
+ const gen = requestHistoryNanoContract ( nanoContractHistoryRequest ( { address , ncId } ) ) ;
118
100
// select wallet
119
101
gen . next ( ) ;
120
- // feed back historyMeta
121
- gen . next ( { } ) ;
122
102
// feed back wallet
123
103
gen . next ( fixtures . wallet . readyAndMine ) ;
124
104
// feed back isNanoContractRegistered
@@ -130,39 +110,40 @@ describe('sagas/nanoContract/requestHistoryNanoContract', () => {
130
110
131
111
// assert failure
132
112
expect ( fetchHistoryCall . payload . fn ) . toBe ( fetchHistory ) ;
133
- expect ( failureCall ) . toStrictEqual (
134
- put ( nanoContractHistoryFailure ( { ncId, error : failureMessage . nanoContractHistoryFailure } ) )
135
- ) ;
113
+ expect ( failureCall ) . toStrictEqual ( put ( nanoContractHistoryFailure ( failureMessage . nanoContractHistoryFailure , new Error ( 'history' ) ) ) ) ;
136
114
expect ( onErrorCall ) . toStrictEqual ( put ( onExceptionCaptured ( new Error ( 'history' ) , false ) ) ) ;
137
115
} ) ;
138
116
139
117
test ( 'history with success' , ( ) => {
140
118
// arrange Nano Contract registration inputs
141
- const { ncId } = fixtures ;
119
+ const { address , ncId } = fixtures ;
142
120
143
121
// call effect to request history
144
- const gen = requestHistoryNanoContract ( nanoContractHistoryRequest ( { ncId } ) ) ;
122
+ const gen = requestHistoryNanoContract ( nanoContractHistoryRequest ( { address , ncId } ) ) ;
145
123
// select wallet
146
124
gen . next ( ) ;
147
- // feed back historyMeta
148
- gen . next ( { } ) ;
149
125
// feed back wallet
150
126
gen . next ( fixtures . wallet . readyAndMine ) ;
151
127
// feed back isNanoContractRegistered
152
128
const fetchHistoryCall = gen . next ( true ) . value ;
153
129
// feed back fetchHistory
154
- const sucessCall = gen . next ( fixtures . ncSaga . fetchHistory . successResponse ) . value ;
130
+ gen . next ( fixtures . ncSaga . fetchHistory . successResponse ) ;
131
+ // feed back getNanoContract
132
+ gen . next ( { ncId } ) ;
133
+ // call registerNanoContract and yield put nanoContractHistoryLoad
134
+ const historyLoadCall = gen . next ( ) . value ;
135
+
136
+ const sucessCall = gen . next ( ) . value ;
155
137
156
138
// assert success
157
- const expectedHistory = fixtures . ncSaga . fetchHistory . successResponse . history ;
158
139
expect ( fetchHistoryCall . payload . fn ) . toBe ( fetchHistory ) ;
159
- expect ( sucessCall . payload ) . toHaveProperty ( 'action.payload.ncId' ) ;
160
- expect ( sucessCall . payload ) . toHaveProperty ( 'action.payload.history' ) ;
161
- expect ( sucessCall . payload . action . payload . ncId ) . toStrictEqual ( ncId ) ;
162
- expect ( sucessCall . payload . action . payload . history ) . toStrictEqual ( expectedHistory ) ;
163
- expect ( sucessCall ) . toStrictEqual (
164
- put ( nanoContractHistorySuccess ( { ncId, history : expectedHistory , after : null } ) )
140
+ expect ( historyLoadCall . payload ) . toHaveProperty ( 'action.payload.ncId' ) ;
141
+ expect ( historyLoadCall . payload ) . toHaveProperty ( 'action.payload.history' ) ;
142
+ expect ( historyLoadCall . payload . action . payload . ncId ) . toStrictEqual ( ncId ) ;
143
+ expect ( historyLoadCall . payload . action . payload . history ) . toStrictEqual (
144
+ fixtures . ncSaga . fetchHistory . successResponse . history
165
145
) ;
146
+ expect ( sucessCall ) . toStrictEqual ( put ( nanoContractHistorySuccess ( ) ) ) ;
166
147
// assert termination
167
148
expect ( gen . next ( ) . value ) . toBeUndefined ( ) ;
168
149
} ) ;
0 commit comments