Skip to content

Commit 0fdda76

Browse files
committed
use redux-api-middleware instead
1 parent 0844659 commit 0fdda76

File tree

15 files changed

+139
-112
lines changed

15 files changed

+139
-112
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@
6161
"react-dom": "^15.5.4",
6262
"react-redux": "^5.0.4",
6363
"redux": "^3.6.0",
64-
"redux-fetch-middleware": "^3.0.2",
65-
"redux-thunk": "^2.2.0",
64+
"redux-api-middleware": "^1.0.3",
6665
"rimraf": "~2.6.1",
6766
"semver": "~5.3.0",
6867
"serve-static": "~1.12.2",

src-react/__tests__/reducers/app.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('app.js reducers', () => {
1818
describe('when action doesn\'t match any case' , () => {
1919

2020
it('should return original state except the showNPSSurvey state', () => {
21-
const state = app(initialState, { type: 'no-op' });
21+
const state = app(initialState, { type: types.NO_OP });
2222
expect(state.gitVersionErrorVisible).toEqual(initialState.gitVersionErrorVisible);
2323
expect(state.showNewVersionAvailable).toEqual(initialState.showNewVersionAvailable);
2424
expect(state.showBugtrackingNagscreen).toEqual(initialState.showBugtrackingNagscreen);
@@ -31,7 +31,7 @@ describe('app.js reducers', () => {
3131
});
3232

3333
it('showNPSSurvey state will be true', () => {
34-
const state = app(initialState, { type: 'no-op' });
34+
const state = app(initialState, { type: types.NO_OP });
3535
expect(state.showNPSSurvey).toEqual(true);
3636
});
3737

@@ -47,7 +47,7 @@ describe('app.js reducers', () => {
4747
});
4848

4949
it('showNPSSurvey state will be false', () => {
50-
const state = app(initialState, { type: 'no-op' });
50+
const state = app(initialState, { type: types.NO_OP });
5151
expect(state.showNPSSurvey).toEqual(false);
5252
});
5353

@@ -63,7 +63,7 @@ describe('app.js reducers', () => {
6363
});
6464

6565
it('showNPSSurvey state will be false', () => {
66-
const state = app(initialState, { type: 'no-op' });
66+
const state = app(initialState, { type: types.NO_OP });
6767
expect(state.showNPSSurvey).toEqual(false);
6868
});
6969

@@ -73,19 +73,19 @@ describe('app.js reducers', () => {
7373
});
7474
});
7575

76-
describe('when RECEIVE_UNGIT_CONFIG action dispatch', () => {
76+
describe('when FETCH_UNGIT_CONFIG_SUCCESS action dispatch', () => {
7777
describe('if ungitConfig.config.bugtracking is false and bugtrackingNagscreenDismissed is false', () => {
7878
it('showBugtrackingNagscreen state will be true', () => {
7979
const ungitConfig = { config: { bugtracking: false } };
80-
const state = app(initialState, { type: types.RECEIVE_UNGIT_CONFIG, payload: ungitConfig }, { ungitConfig });
80+
const state = app(initialState, { type: types.FETCH_UNGIT_CONFIG_SUCCESS, payload: ungitConfig }, { ungitConfig });
8181
expect(state.showBugtrackingNagscreen).toEqual(true);
8282
});
8383
});
8484

8585
describe('if ungitConfig.config.bugtracking is true', () => {
8686
it('showBugtrackingNagscreen state will be false', () => {
8787
const ungitConfig = { config: { bugtracking: true } };
88-
const state = app(initialState, { type: types.RECEIVE_UNGIT_CONFIG, payload: ungitConfig }, { ungitConfig });
88+
const state = app(initialState, { type: types.FETCH_UNGIT_CONFIG_SUCCESS, payload: ungitConfig }, { ungitConfig });
8989
expect(state.showBugtrackingNagscreen).toEqual(false);
9090
});
9191
});
@@ -94,13 +94,13 @@ describe('app.js reducers', () => {
9494
it('showBugtrackingNagscreen state will be false', () => {
9595
localStorage.setItem('bugtrackingNagscreenDismissed', true);
9696
const ungitConfig = { config: { bugtracking: false } };
97-
const state = app(initialState, { type: types.RECEIVE_UNGIT_CONFIG, payload: ungitConfig }, { ungitConfig });
97+
const state = app(initialState, { type: types.FETCH_UNGIT_CONFIG_SUCCESS, payload: ungitConfig }, { ungitConfig });
9898
expect(state.showBugtrackingNagscreen).toEqual(false);
9999
});
100100
});
101101
});
102102

103-
describe('when RECEIVE_GIT_VERSION action dispatch', () => {
103+
describe('when FETCH_GIT_VERSION_SUCCESS action dispatch', () => {
104104
describe('if ungitConfig.config.gitVersionCheckOverride is false and gitVersionError is defined && gitVersionErrorDismissed is false', () => {
105105
it('gitVersionErrorVisible state will be true', () => {
106106
localStorage.setItem('gitVersionErrorDismissed', false);
@@ -111,7 +111,7 @@ describe('app.js reducers', () => {
111111
};
112112
const config = { ungitConfig, versions: { gitVersion } };
113113

114-
const state = app(initialState, { type: types.RECEIVE_GIT_VERSION, payload: gitVersion }, config);
114+
const state = app(initialState, { type: types.FETCH_GIT_VERSION_SUCCESS, payload: gitVersion }, config);
115115
expect(state.gitVersionErrorVisible).toEqual(true);
116116
});
117117
});
@@ -126,7 +126,7 @@ describe('app.js reducers', () => {
126126
};
127127
const config = { ungitConfig, versions: { gitVersion } };
128128

129-
const state = app(initialState, { type: types.RECEIVE_GIT_VERSION, payload: gitVersion }, config);
129+
const state = app(initialState, { type: types.FETCH_GIT_VERSION_SUCCESS, payload: gitVersion }, config);
130130
expect(state.gitVersionErrorVisible).toEqual(false);
131131
});
132132
});
@@ -138,7 +138,7 @@ describe('app.js reducers', () => {
138138
const gitVersion = { satisfied: true };
139139
const config = { ungitConfig, versions: { gitVersion } };
140140

141-
const state = app(initialState, { type: types.RECEIVE_GIT_VERSION, payload: gitVersion }, config);
141+
const state = app(initialState, { type: types.FETCH_GIT_VERSION_SUCCESS, payload: gitVersion }, config);
142142
expect(state.gitVersionErrorVisible).toEqual(false);
143143
});
144144
});
@@ -153,20 +153,20 @@ describe('app.js reducers', () => {
153153
};
154154
const config = { ungitConfig, versions: { gitVersion } };
155155

156-
const state = app(initialState, { type: types.RECEIVE_GIT_VERSION, payload: gitVersion }, config);
156+
const state = app(initialState, { type: types.FETCH_GIT_VERSION_SUCCESS, payload: gitVersion }, config);
157157
expect(state.gitVersionErrorVisible).toEqual(false);
158158
});
159159
});
160160
});
161161

162-
describe('when RECEIVE_LATEST_VERSION action dispatch', () => {
162+
describe('when FETCH_LATEST_VERSION_SUCCESS action dispatch', () => {
163163
describe('gitVersionCheckOverride is false and latestVersion.outdated is true', () => {
164164
it('showNewVersionAvailable state will be true', () => {
165165
const ungitConfig = { config: { gitVersionCheckOverride: false } };
166166
const latestVersion = { outdated: true };
167167
const config = { ungitConfig, versions: { latestVersion } };
168168

169-
const state = app(initialState, { type: types.RECEIVE_LATEST_VERSION, payload: latestVersion }, config);
169+
const state = app(initialState, { type: types.FETCH_LATEST_VERSION_SUCCESS, payload: latestVersion }, config);
170170
expect(state.showNewVersionAvailable).toEqual(true);
171171
});
172172
});
@@ -177,7 +177,7 @@ describe('app.js reducers', () => {
177177
const latestVersion = { outdated: true };
178178
const config = { ungitConfig, versions: { latestVersion } };
179179

180-
const state = app(initialState, { type: types.RECEIVE_LATEST_VERSION, payload: latestVersion }, config);
180+
const state = app(initialState, { type: types.FETCH_LATEST_VERSION_SUCCESS, payload: latestVersion }, config);
181181
expect(state.showNewVersionAvailable).toEqual(false);
182182
});
183183
});
@@ -188,20 +188,20 @@ describe('app.js reducers', () => {
188188
const latestVersion = { outdated: false };
189189
const config = { ungitConfig, versions: { latestVersion } };
190190

191-
const state = app(initialState, { type: types.RECEIVE_LATEST_VERSION, payload: latestVersion }, config);
191+
const state = app(initialState, { type: types.FETCH_LATEST_VERSION_SUCCESS, payload: latestVersion }, config);
192192
expect(state.showNewVersionAvailable).toEqual(false);
193193
});
194194
});
195195
});
196196

197-
describe('when RECEIVE_USER_CONFIG action dispatch', () => {
197+
describe('when FETCH_USER_CONFIG_SUCCESS action dispatch', () => {
198198
describe('userConfig.bugtracking = false and bugtrackingNagscreenDismissed = false', () => {
199199
it('showBugtrackingNagscreen state will be true', () => {
200200
const userConfig = { bugtracking: false };
201201
const ungitConfig = { config: { bugtracking: true } };
202202
localStorage.setItem('bugtrackingNagscreenDismissed', false);
203203

204-
const state = app(initialState, { type: types.RECEIVE_USER_CONFIG, payload: userConfig }, { userConfig, ungitConfig });
204+
const state = app(initialState, { type: types.FETCH_USER_CONFIG_SUCCESS, payload: userConfig }, { userConfig, ungitConfig });
205205
expect(state.showBugtrackingNagscreen).toEqual(true);
206206
});
207207
});
@@ -212,7 +212,7 @@ describe('app.js reducers', () => {
212212
const ungitConfig = { config: { bugtracking: true } };
213213
localStorage.setItem('bugtrackingNagscreenDismissed', false);
214214

215-
const state = app(initialState, { type: types.RECEIVE_USER_CONFIG, payload: userConfig }, { userConfig, ungitConfig });
215+
const state = app(initialState, { type: types.FETCH_USER_CONFIG_SUCCESS, payload: userConfig }, { userConfig, ungitConfig });
216216
expect(state.showBugtrackingNagscreen).toEqual(false);
217217
});
218218
});
@@ -223,7 +223,7 @@ describe('app.js reducers', () => {
223223
const ungitConfig = { config: { bugtracking: true } };
224224
localStorage.setItem('bugtrackingNagscreenDismissed', true);
225225

226-
const state = app(initialState, { type: types.RECEIVE_USER_CONFIG, payload: userConfig }, { userConfig, ungitConfig });
226+
const state = app(initialState, { type: types.FETCH_USER_CONFIG_SUCCESS, payload: userConfig }, { userConfig, ungitConfig });
227227
expect(state.showBugtrackingNagscreen).toEqual(false);
228228
});
229229
});

src-react/__tests__/reducers/path.test.js

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,26 @@ import path from 'reducers/path';
44

55
describe('path.js reducers', () => {
66
let initialState;
7-
const DECREASE_PENDING_ACTIONS = [
8-
types.RECEIVE_UNGIT_CONFIG,
9-
types.RECEIVE_USER_CONFIG,
10-
types.RECEIVE_GIT_VERSION,
11-
types.RECEIVE_LATEST_VERSION
7+
8+
const REQUEST_ACTIONS = [
9+
types.FETCH_USER_CONFIG_REQUEST,
10+
types.FETCH_LATEST_VERSION_REQUEST,
11+
types.FETCH_GIT_VERSION_REQUEST,
12+
types.FETCH_UNGIT_CONFIG_REQUEST
13+
];
14+
15+
const SUCCESS_ACTIONS = [
16+
types.FETCH_USER_CONFIG_SUCCESS,
17+
types.FETCH_LATEST_VERSION_SUCCESS,
18+
types.FETCH_GIT_VERSION_SUCCESS,
19+
types.FETCH_UNGIT_CONFIG_SUCCESS
20+
];
21+
22+
const FAILURE_ACTIONS = [
23+
types.FETCH_USER_CONFIG_FAILURE,
24+
types.FETCH_LATEST_VERSION_FAILURE,
25+
types.FETCH_GIT_VERSION_FAILURE,
26+
types.FETCH_UNGIT_CONFIG_FAILURE
1227
];
1328

1429
beforeEach(() => {
@@ -19,25 +34,29 @@ describe('path.js reducers', () => {
1934
});
2035

2136
it('should return original state if action doesn\'t match any case' , function() {
22-
const state = path(initialState, { type: 'no-op' });
37+
const state = path(initialState, { type: types.NO_OP });
2338
expect(state.pending).toEqual(initialState.pending);
2439
expect(state.errMessage.length).toEqual(initialState.errMessage.length);
2540
});
2641

27-
describe('when PATH_PAGE_PENDING action dispatch', () => {
28-
it('pending state should be calculated correctly', function() {
29-
const action1 = { type: types.PATH_PAGE_PENDING, payload: 1 };
30-
const action2 = { type: types.PATH_PAGE_PENDING, payload: 3 };
31-
32-
const state1 = path(initialState, action1);
33-
expect(state1.pending).toEqual(initialState.pending + action1.payload);
42+
REQUEST_ACTIONS.forEach(actionName => {
43+
describe(`when ${actionName} action dispatch`, () => {
44+
beforeEach(() => {
45+
initialState = {
46+
pending: 1,
47+
errMessage: []
48+
};
49+
});
50+
it('pending state should be plus one', () => {
51+
const action = { type: actionName };
3452

35-
const state2 = path(state1, action2);
36-
expect(state2.pending).toEqual(state1.pending + action2.payload);
53+
const state = path(initialState, action);
54+
expect(state.pending).toEqual(initialState.pending + 1);
55+
});
3756
});
3857
});
3958

40-
DECREASE_PENDING_ACTIONS.forEach(actionName => {
59+
SUCCESS_ACTIONS.forEach(actionName => {
4160
describe(`when ${actionName} action dispatch`, () => {
4261
beforeEach(() => {
4362
initialState = {
@@ -53,21 +72,22 @@ describe('path.js reducers', () => {
5372
});
5473
});
5574
});
56-
57-
describe('when PATH_PAGE_API_ERR action dispatch', () => {
58-
it('pending state should be minused one', function() {
59-
const action = { type: types.PATH_PAGE_API_ERR, payload: 'error message' };
60-
61-
const state = path(initialState, action);
62-
expect(state.pending).toEqual(initialState.pending - 1);
63-
});
6475

65-
it('errMessage state should correct content', function() {
66-
const action = { type: types.PATH_PAGE_API_ERR, payload: 'error message' };
76+
FAILURE_ACTIONS.forEach(actionName => {
77+
describe(`when ${actionName} action dispatch`, () => {
78+
beforeEach(() => {
79+
initialState = {
80+
pending: 1,
81+
errMessage: []
82+
};
83+
});
84+
it('pending state should be minused one', () => {
85+
const action = { type: actionName, payload: { message: 'error' } };
6786

68-
const state = path(initialState, action);
69-
expect(state.errMessage.length).toEqual(initialState.errMessage.length + 1);
70-
expect(state.errMessage[0]).toEqual(action.payload);
87+
const state = path(initialState, action);
88+
expect(state.pending).toEqual(initialState.pending - 1);
89+
expect(state.errMessage[0]).toEqual(action.payload.message);
90+
});
7191
});
7292
});
7393
});

src-react/__tests__/reducers/ungit-config.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ describe('ungit-config.js reducers', () => {
66
let initialState;
77

88
it('should return original state if action doesn\'t match any case' , function() {
9-
const state = ungitConfig(initialState, { type: 'no-op' });
9+
const state = ungitConfig(initialState, { type: types.NO_OP });
1010
expect(state).toEqual({});
1111
});
1212

13-
describe('when RECEIVE_UNGIT_CONFIG action dispatch', () => {
13+
describe('when FETCH_UNGIT_CONFIG_SUCCESS action dispatch', () => {
1414
it('state should have ungit configuration correctly', function() {
1515
// TODO: consider to use sinon to mock data and make mock data reuseable and meaningful
16-
const action = { type: types.RECEIVE_UNGIT_CONFIG, payload: {
16+
const action = { type: types.FETCH_UNGIT_CONFIG_SUCCESS, payload: {
1717
config: {
1818
allowCheckoutNodes: false,
1919
autoStashAndPop: true

src-react/__tests__/reducers/user-config.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ describe('user-config.js reducers', () => {
66
let initialState;
77

88
it('should return original state if action doesn\'t match any case' , () => {
9-
const state = userConfig(initialState, { type: 'no-op' });
9+
const state = userConfig(initialState, { type: types.NO_OP });
1010
expect(state).toEqual({});
1111
});
1212

13-
describe('when RECEIVE_USER_CONFIG action dispatch', () => {
13+
describe('when FETCH_USER_CONFIG_SUCCESS action dispatch', () => {
1414
it('state should have user configuration correctly', () => {
1515
// TODO: consider to use sinon to mock data and make mock data reuseable and meaningful
16-
const action = { type: types.RECEIVE_USER_CONFIG, payload: {
16+
const action = { type: types.FETCH_USER_CONFIG_SUCCESS, payload: {
1717
port: 8080,
1818
bugtracking: true
1919
} };

src-react/__tests__/reducers/versions.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ describe('versions.js reducers', () => {
99
};
1010

1111
it('should return original state if action doesn\'t match any case' , () => {
12-
const state = versions(initialState, { type: 'no-op' });
12+
const state = versions(initialState, { type: types.NO_OP });
1313
expect(state).toEqual(initialState);
1414
});
1515

16-
describe('when RECEIVE_GIT_VERSION action dispatch', () => {
16+
describe('when FETCH_GIT_VERSION_SUCCESS action dispatch', () => {
1717
it('state should have git version configuration correctly', () => {
1818
// TODO: consider to use sinon to mock data and make mock data reuseable and meaningful
19-
const action = { type: types.RECEIVE_GIT_VERSION, payload: {
19+
const action = { type: types.FETCH_GIT_VERSION_SUCCESS, payload: {
2020
requiredVersion: '>=1.8.x',
2121
satisfied: true,
2222
version: '2.3.2'
@@ -27,10 +27,10 @@ describe('versions.js reducers', () => {
2727
});
2828
});
2929

30-
describe('when RECEIVE_LATEST_VERSION action dispatch', () => {
30+
describe('when FETCH_LATEST_VERSION_SUCCESS action dispatch', () => {
3131
it('state should have lastest configuration correctly', () => {
3232
// TODO: consider to use sinon to mock data and make mock data reuseable and meaningful
33-
const action = { type: types.RECEIVE_LATEST_VERSION, payload: {
33+
const action = { type: types.FETCH_LATEST_VERSION_SUCCESS, payload: {
3434
currentVersion: 'dev-1.1.16-071f30a',
3535
latestVersion: '1.1.19',
3636
outdated: false

0 commit comments

Comments
 (0)