1
1
import { expect } from 'chai' ;
2
2
import nock from 'nock' ;
3
- import { apiMiddleware , ApiError } from 'redux-api-middleware' ;
4
3
import configureMockStore from 'redux-mock-store' ;
4
+ import thunk from 'redux-thunk' ;
5
5
6
6
import Constants from '../../utils/constants' ;
7
7
import * as actions from '../../actions' ;
8
8
9
- const middlewares = [ apiMiddleware ] ;
9
+ const middlewares = [ thunk ] ;
10
10
const createMockStore = configureMockStore ( middlewares ) ;
11
11
12
12
describe ( 'actions/index.js' , ( ) => {
@@ -26,8 +26,8 @@ describe('actions/index.js', () => {
26
26
} ) ;
27
27
28
28
const expectedActions = [
29
- { type : actions . LOGIN_REQUEST , payload : undefined , meta : undefined } ,
30
- { type : actions . LOGIN_SUCCESS , payload : { body : { access_token : 'THISISATOKEN' } } , meta : undefined }
29
+ { type : actions . LOGIN . REQUEST } ,
30
+ { type : actions . LOGIN . SUCCESS , payload : { body : { access_token : 'THISISATOKEN' } } }
31
31
] ;
32
32
33
33
const store = createMockStore ( { response : [ ] } , expectedActions ) ;
@@ -52,8 +52,8 @@ describe('actions/index.js', () => {
52
52
} ) ;
53
53
54
54
const expectedActions = [
55
- { type : actions . LOGIN_REQUEST , payload : undefined , meta : undefined } ,
56
- { type : actions . LOGIN_FAILURE , payload : { body : { message } } , error : true , meta : undefined }
55
+ { type : actions . LOGIN . REQUEST } ,
56
+ { type : actions . LOGIN . FAILURE , payload : { body : { message } } }
57
57
] ;
58
58
59
59
const store = createMockStore ( { response : [ ] } , expectedActions ) ;
@@ -88,17 +88,21 @@ describe('actions/index.js', () => {
88
88
] ;
89
89
90
90
nock ( 'https://api.github.com/' )
91
- . get ( '/notifications' )
91
+ . get ( '/notifications?participating=false ' )
92
92
. reply ( 200 , {
93
93
body : notifications
94
94
} ) ;
95
95
96
96
const expectedActions = [
97
- { type : actions . NOTIFICATIONS_REQUEST , payload : undefined , meta : undefined } ,
98
- { type : actions . NOTIFICATIONS_SUCCESS , payload : { body : notifications } , meta : undefined }
97
+ { type : actions . NOTIFICATIONS . REQUEST } ,
98
+ { type : actions . NOTIFICATIONS . SUCCESS , payload : { body : notifications } }
99
99
] ;
100
100
101
- const store = createMockStore ( { response : [ ] } , expectedActions ) ;
101
+ const store = createMockStore ( {
102
+ auth : { token : 'THISISATOKEN' } ,
103
+ settings : { participating : false } ,
104
+ response : [ ]
105
+ } , expectedActions ) ;
102
106
103
107
return store . dispatch ( actions . fetchNotifications ( ) )
104
108
. then ( ( ) => { // return of async actions
@@ -111,17 +115,21 @@ describe('actions/index.js', () => {
111
115
const message = 'Oops! Something went wrong.' ;
112
116
113
117
nock ( 'https://api.github.com/' )
114
- . get ( '/notifications' )
118
+ . get ( '/notifications?participating=false ' )
115
119
. reply ( 400 , {
116
120
body : { message }
117
121
} ) ;
118
122
119
123
const expectedActions = [
120
- { type : actions . NOTIFICATIONS_REQUEST , payload : undefined , meta : undefined } ,
121
- { type : actions . NOTIFICATIONS_FAILURE , payload : { body : { message } } , error : true , meta : undefined }
124
+ { type : actions . NOTIFICATIONS . REQUEST } ,
125
+ { type : actions . NOTIFICATIONS . FAILURE , payload : { body : { message } } }
122
126
] ;
123
127
124
- const store = createMockStore ( { response : [ ] } , expectedActions ) ;
128
+ const store = createMockStore ( {
129
+ auth : { token : null } ,
130
+ settings : { participating : false } ,
131
+ response : [ ]
132
+ } , expectedActions ) ;
125
133
126
134
return store . dispatch ( actions . fetchNotifications ( ) )
127
135
. then ( ( ) => { // return of async actions
@@ -141,11 +149,14 @@ describe('actions/index.js', () => {
141
149
} ) ;
142
150
143
151
const expectedActions = [
144
- { type : actions . MARK_NOTIFICATION_REQUEST , payload : undefined , meta : undefined } ,
145
- { type : actions . MARK_NOTIFICATION_SUCCESS , payload : { body : message } , meta : { id } }
152
+ { type : actions . MARK_NOTIFICATION . REQUEST } ,
153
+ { type : actions . MARK_NOTIFICATION . SUCCESS , payload : { body : message } , meta : { id } }
146
154
] ;
147
155
148
- const store = createMockStore ( { response : [ ] } , expectedActions ) ;
156
+ const store = createMockStore ( {
157
+ auth : { token : 'IAMATOKEN' } ,
158
+ response : [ ]
159
+ } , expectedActions ) ;
149
160
150
161
return store . dispatch ( actions . markNotification ( id ) )
151
162
. then ( ( ) => { // return of async actions
@@ -164,22 +175,15 @@ describe('actions/index.js', () => {
164
175
body : { message }
165
176
} ) ;
166
177
167
- const expectedPayload = {
168
- message : '400 - Bad Request' ,
169
- name : 'ApiError' ,
170
- status : 400 ,
171
- response : {
172
- body : { message }
173
- } ,
174
- statusText : 'Bad Request'
175
- } ;
176
-
177
178
const expectedActions = [
178
- { type : actions . MARK_NOTIFICATION_REQUEST , payload : undefined , meta : undefined } ,
179
- { type : actions . MARK_NOTIFICATION_FAILURE , payload : expectedPayload , error : true , meta : undefined }
179
+ { type : actions . MARK_NOTIFICATION . REQUEST } ,
180
+ { type : actions . MARK_NOTIFICATION . FAILURE , payload : { body : { message } } }
180
181
] ;
181
182
182
- const store = createMockStore ( { response : [ ] } , expectedActions ) ;
183
+ const store = createMockStore ( {
184
+ auth : { token : null } ,
185
+ response : [ ]
186
+ } , expectedActions ) ;
183
187
184
188
return store . dispatch ( actions . markNotification ( id ) )
185
189
. then ( ( ) => { // return of async actions
@@ -201,11 +205,14 @@ describe('actions/index.js', () => {
201
205
} ) ;
202
206
203
207
const expectedActions = [
204
- { type : actions . MARK_REPO_NOTIFICATION_REQUEST , payload : undefined , meta : undefined } ,
205
- { type : actions . MARK_REPO_NOTIFICATION_SUCCESS , payload : { body : message } , meta : { repoFullName, repoId } }
208
+ { type : actions . MARK_REPO_NOTIFICATION . REQUEST } ,
209
+ { type : actions . MARK_REPO_NOTIFICATION . SUCCESS , payload : { body : message } , meta : { repoFullName, repoId } }
206
210
] ;
207
211
208
- const store = createMockStore ( { response : [ ] } , expectedActions ) ;
212
+ const store = createMockStore ( {
213
+ auth : { token : 'IAMATOKEN' } ,
214
+ response : [ ]
215
+ } , expectedActions ) ;
209
216
210
217
return store . dispatch ( actions . markRepoNotifications ( loginId , repoId , repoFullName ) )
211
218
. then ( ( ) => { // return of async actions
@@ -226,22 +233,15 @@ describe('actions/index.js', () => {
226
233
body : { message }
227
234
} ) ;
228
235
229
- const expectedPayload = {
230
- message : '400 - Bad Request' ,
231
- name : 'ApiError' ,
232
- status : 400 ,
233
- response : {
234
- body : { message }
235
- } ,
236
- statusText : 'Bad Request'
237
- } ;
238
-
239
236
const expectedActions = [
240
- { type : actions . MARK_REPO_NOTIFICATION_REQUEST , payload : undefined , meta : undefined } ,
241
- { type : actions . MARK_REPO_NOTIFICATION_FAILURE , payload : expectedPayload , error : true , meta : undefined }
237
+ { type : actions . MARK_REPO_NOTIFICATION . REQUEST } ,
238
+ { type : actions . MARK_REPO_NOTIFICATION . FAILURE , payload : { body : { message } } }
242
239
] ;
243
240
244
- const store = createMockStore ( { response : [ ] } , expectedActions ) ;
241
+ const store = createMockStore ( {
242
+ auth : { token : null } ,
243
+ response : [ ]
244
+ } , expectedActions ) ;
245
245
246
246
return store . dispatch ( actions . markRepoNotifications ( loginId , repoId , repoFullName ) )
247
247
. then ( ( ) => { // return of async actions
@@ -250,17 +250,20 @@ describe('actions/index.js', () => {
250
250
251
251
} ) ;
252
252
253
- it ( 'should check if the user has starred the repository' , ( ) => {
253
+ it ( 'should check if the user has starred the repository (has) ' , ( ) => {
254
254
nock ( 'https://api.github.com/' )
255
255
. get ( `/user/starred/${ Constants . REPO_SLUG } ` )
256
256
. reply ( 200 ) ;
257
257
258
258
const expectedActions = [
259
- { type : actions . HAS_STARRED_REQUEST , payload : undefined , meta : undefined } ,
260
- { type : actions . HAS_STARRED_SUCCESS , payload : undefined , meta : undefined }
259
+ { type : actions . HAS_STARRED . REQUEST } ,
260
+ { type : actions . HAS_STARRED . SUCCESS , payload : '' }
261
261
] ;
262
262
263
- const store = createMockStore ( { response : [ ] } , expectedActions ) ;
263
+ const store = createMockStore ( {
264
+ auth : { token : 'IAMATOKEN' } ,
265
+ response : [ ]
266
+ } , expectedActions ) ;
264
267
265
268
return store . dispatch ( actions . checkHasStarred ( ) )
266
269
. then ( ( ) => { // return of async actions
@@ -269,18 +272,20 @@ describe('actions/index.js', () => {
269
272
270
273
} ) ;
271
274
272
- it ( 'should check if the user has starred the repository' , ( ) => {
275
+ it ( 'should check if the user has starred the repository (has not) ' , ( ) => {
273
276
nock ( 'https://api.github.com/' )
274
277
. get ( `/user/starred/${ Constants . REPO_SLUG } ` )
275
278
. reply ( 404 ) ;
276
279
277
- const apiError = new ApiError ( 404 , 'Not Found' , undefined ) ;
278
280
const expectedActions = [
279
- { type : actions . HAS_STARRED_REQUEST , payload : undefined , meta : undefined } ,
280
- { type : actions . HAS_STARRED_FAILURE , payload : apiError , error : true , meta : undefined }
281
+ { type : actions . HAS_STARRED . REQUEST } ,
282
+ { type : actions . HAS_STARRED . FAILURE , payload : '' }
281
283
] ;
282
284
283
- const store = createMockStore ( { response : [ ] } , expectedActions ) ;
285
+ const store = createMockStore ( {
286
+ auth : { token : 'IAMATOKEN' } ,
287
+ response : [ ]
288
+ } , expectedActions ) ;
284
289
285
290
return store . dispatch ( actions . checkHasStarred ( ) )
286
291
. then ( ( ) => { // return of async actions
0 commit comments