Skip to content

Commit 41d2f6d

Browse files
authored
Merge pull request #232 from manosim/hello-thunk
From redux-api-middleware to think+axios
2 parents 23e2d42 + 8a63498 commit 41d2f6d

File tree

17 files changed

+226
-306
lines changed

17 files changed

+226
-306
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"homepage": "http://www.gitify.io/",
5050
"dependencies": {
5151
"auto-launch": "=4.0.0",
52+
"axios": "=0.14.0",
5253
"bootstrap": "=4.0.0-alpha.3",
5354
"electron-gh-releases": "=2.0.4",
5455
"electron-positioner": "=3.0.0",
@@ -67,10 +68,10 @@
6768
"react-router-redux": "=4.0.4",
6869
"react-toggle": "=2.1.0",
6970
"redux": "=3.5.2",
70-
"redux-api-middleware": "=1.0.2",
7171
"redux-storage": "=4.0.0",
7272
"redux-storage-decorator-filter": "=1.1.3",
7373
"redux-storage-engine-localstorage": "=1.1.0",
74+
"redux-thunk": "=2.1.0",
7475
"underscore": "=1.8.3"
7576
},
7677
"devDependencies": {

src/js/__tests__/__helpers__/mocha.opts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
--compilers scss:src/js/__tests__/__helpers__/scss-compiler.js,js:babel-core/register
1+
--compilers js:babel-core/register
22
--require src/js/__tests__/__helpers__/tests-dom.js
33
--bail
44
--recursive

src/js/__tests__/__helpers__/scss-compiler.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/js/__tests__/actions/index.js

Lines changed: 60 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { expect } from 'chai';
22
import nock from 'nock';
3-
import { apiMiddleware, ApiError } from 'redux-api-middleware';
43
import configureMockStore from 'redux-mock-store';
4+
import thunk from 'redux-thunk';
55

66
import Constants from '../../utils/constants';
77
import * as actions from '../../actions';
88

9-
const middlewares = [ apiMiddleware ];
9+
const middlewares = [ thunk ];
1010
const createMockStore = configureMockStore(middlewares);
1111

1212
describe('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

src/js/__tests__/middleware/notifications.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('middleware/notifications.js', () => {
6868
sinon.spy(NativeNotifications, 'setup');
6969

7070
const action = {
71-
type: actions.NOTIFICATIONS_SUCCESS,
71+
type: actions.NOTIFICATIONS.SUCCESS,
7272
payload: newNotification
7373
};
7474

@@ -87,7 +87,7 @@ describe('middleware/notifications.js', () => {
8787
sinon.spy(Helpers, 'updateTrayIcon');
8888

8989
const action = {
90-
type: actions.MARK_NOTIFICATION_SUCCESS,
90+
type: actions.MARK_NOTIFICATION.SUCCESS,
9191
};
9292

9393
expect(dispatchWithStoreOf({}, action)).to.eql(action);
@@ -103,7 +103,7 @@ describe('middleware/notifications.js', () => {
103103
sinon.spy(Helpers, 'updateTrayIcon');
104104

105105
const action = {
106-
type: actions.MARK_REPO_NOTIFICATION_SUCCESS,
106+
type: actions.MARK_REPO_NOTIFICATION.SUCCESS,
107107
meta: {
108108
repoId: 111111
109109
}

src/js/__tests__/middleware/requests.js

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)