11import { expect } from 'chai' ;
22import nock from 'nock' ;
3- import { apiMiddleware , ApiError } from 'redux-api-middleware' ;
43import configureMockStore from 'redux-mock-store' ;
4+ import thunk from 'redux-thunk' ;
55
66import Constants from '../../utils/constants' ;
77import * as actions from '../../actions' ;
88
9- const middlewares = [ apiMiddleware ] ;
9+ const middlewares = [ thunk ] ;
1010const createMockStore = configureMockStore ( middlewares ) ;
1111
1212describe ( 'actions/index.js' , ( ) => {
@@ -26,8 +26,8 @@ describe('actions/index.js', () => {
2626 } ) ;
2727
2828 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' } } }
3131 ] ;
3232
3333 const store = createMockStore ( { response : [ ] } , expectedActions ) ;
@@ -52,8 +52,8 @@ describe('actions/index.js', () => {
5252 } ) ;
5353
5454 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 } } }
5757 ] ;
5858
5959 const store = createMockStore ( { response : [ ] } , expectedActions ) ;
@@ -88,17 +88,21 @@ describe('actions/index.js', () => {
8888 ] ;
8989
9090 nock ( 'https://api.github.com/' )
91- . get ( '/notifications' )
91+ . get ( '/notifications?participating=false ' )
9292 . reply ( 200 , {
9393 body : notifications
9494 } ) ;
9595
9696 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 } }
9999 ] ;
100100
101- const store = createMockStore ( { response : [ ] } , expectedActions ) ;
101+ const store = createMockStore ( {
102+ auth : { token : 'THISISATOKEN' } ,
103+ settings : { participating : false } ,
104+ response : [ ]
105+ } , expectedActions ) ;
102106
103107 return store . dispatch ( actions . fetchNotifications ( ) )
104108 . then ( ( ) => { // return of async actions
@@ -111,17 +115,21 @@ describe('actions/index.js', () => {
111115 const message = 'Oops! Something went wrong.' ;
112116
113117 nock ( 'https://api.github.com/' )
114- . get ( '/notifications' )
118+ . get ( '/notifications?participating=false ' )
115119 . reply ( 400 , {
116120 body : { message }
117121 } ) ;
118122
119123 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 } } }
122126 ] ;
123127
124- const store = createMockStore ( { response : [ ] } , expectedActions ) ;
128+ const store = createMockStore ( {
129+ auth : { token : null } ,
130+ settings : { participating : false } ,
131+ response : [ ]
132+ } , expectedActions ) ;
125133
126134 return store . dispatch ( actions . fetchNotifications ( ) )
127135 . then ( ( ) => { // return of async actions
@@ -141,11 +149,14 @@ describe('actions/index.js', () => {
141149 } ) ;
142150
143151 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 } }
146154 ] ;
147155
148- const store = createMockStore ( { response : [ ] } , expectedActions ) ;
156+ const store = createMockStore ( {
157+ auth : { token : 'IAMATOKEN' } ,
158+ response : [ ]
159+ } , expectedActions ) ;
149160
150161 return store . dispatch ( actions . markNotification ( id ) )
151162 . then ( ( ) => { // return of async actions
@@ -164,22 +175,15 @@ describe('actions/index.js', () => {
164175 body : { message }
165176 } ) ;
166177
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-
177178 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 } } }
180181 ] ;
181182
182- const store = createMockStore ( { response : [ ] } , expectedActions ) ;
183+ const store = createMockStore ( {
184+ auth : { token : null } ,
185+ response : [ ]
186+ } , expectedActions ) ;
183187
184188 return store . dispatch ( actions . markNotification ( id ) )
185189 . then ( ( ) => { // return of async actions
@@ -201,11 +205,14 @@ describe('actions/index.js', () => {
201205 } ) ;
202206
203207 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 } }
206210 ] ;
207211
208- const store = createMockStore ( { response : [ ] } , expectedActions ) ;
212+ const store = createMockStore ( {
213+ auth : { token : 'IAMATOKEN' } ,
214+ response : [ ]
215+ } , expectedActions ) ;
209216
210217 return store . dispatch ( actions . markRepoNotifications ( loginId , repoId , repoFullName ) )
211218 . then ( ( ) => { // return of async actions
@@ -226,22 +233,15 @@ describe('actions/index.js', () => {
226233 body : { message }
227234 } ) ;
228235
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-
239236 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 } } }
242239 ] ;
243240
244- const store = createMockStore ( { response : [ ] } , expectedActions ) ;
241+ const store = createMockStore ( {
242+ auth : { token : null } ,
243+ response : [ ]
244+ } , expectedActions ) ;
245245
246246 return store . dispatch ( actions . markRepoNotifications ( loginId , repoId , repoFullName ) )
247247 . then ( ( ) => { // return of async actions
@@ -250,17 +250,20 @@ describe('actions/index.js', () => {
250250
251251 } ) ;
252252
253- it ( 'should check if the user has starred the repository' , ( ) => {
253+ it ( 'should check if the user has starred the repository (has) ' , ( ) => {
254254 nock ( 'https://api.github.com/' )
255255 . get ( `/user/starred/${ Constants . REPO_SLUG } ` )
256256 . reply ( 200 ) ;
257257
258258 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 : '' }
261261 ] ;
262262
263- const store = createMockStore ( { response : [ ] } , expectedActions ) ;
263+ const store = createMockStore ( {
264+ auth : { token : 'IAMATOKEN' } ,
265+ response : [ ]
266+ } , expectedActions ) ;
264267
265268 return store . dispatch ( actions . checkHasStarred ( ) )
266269 . then ( ( ) => { // return of async actions
@@ -269,18 +272,20 @@ describe('actions/index.js', () => {
269272
270273 } ) ;
271274
272- it ( 'should check if the user has starred the repository' , ( ) => {
275+ it ( 'should check if the user has starred the repository (has not) ' , ( ) => {
273276 nock ( 'https://api.github.com/' )
274277 . get ( `/user/starred/${ Constants . REPO_SLUG } ` )
275278 . reply ( 404 ) ;
276279
277- const apiError = new ApiError ( 404 , 'Not Found' , undefined ) ;
278280 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 : '' }
281283 ] ;
282284
283- const store = createMockStore ( { response : [ ] } , expectedActions ) ;
285+ const store = createMockStore ( {
286+ auth : { token : 'IAMATOKEN' } ,
287+ response : [ ]
288+ } , expectedActions ) ;
284289
285290 return store . dispatch ( actions . checkHasStarred ( ) )
286291 . then ( ( ) => { // return of async actions
0 commit comments