Skip to content

Commit 9283484

Browse files
committed
complete middlewares test
1 parent 930a078 commit 9283484

File tree

3 files changed

+291
-0
lines changed

3 files changed

+291
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import nock from 'nock';
2+
import sinon from 'sinon';
3+
import expect from 'expect.js';
4+
import configureStore from 'redux-mock-store';
5+
import { createStore, applyMiddleware } from 'redux';
6+
import { apiMiddleware, CALL_API } from 'redux-api-middleware';
7+
8+
import * as types from 'constants/action-types';
9+
import { fetchUngitConfig } from 'actions/ungit-config';
10+
11+
const createMockStore = configureStore([ apiMiddleware ]);
12+
13+
describe('redux-api-middleware::ungit-config', () => {
14+
describe('fetchUngitConfig successfully', () => {
15+
const mockPayload = { message: 'success' };
16+
17+
beforeEach(() => {
18+
nock('http://localhost:8448')
19+
.get('/ungit/config')
20+
.reply(200, mockPayload);
21+
22+
nock('http://localhost:8448')
23+
.get('/api/userconfig')
24+
.reply(200, mockPayload);
25+
});
26+
27+
it('should dispatch \'FETCH_UNGIT_CONFIG_REQUEST\'', done => {
28+
const store = createMockStore({});
29+
30+
store.subscribe(() => {
31+
const dispatchedActions = store.getActions();
32+
if (dispatchedActions.length === 1) {
33+
expect(dispatchedActions[0].type).to.eql(types.FETCH_UNGIT_CONFIG_REQUEST);
34+
done();
35+
}
36+
});
37+
store.dispatch(fetchUngitConfig());
38+
});
39+
40+
it('should dispatch \'FETCH_UNGIT_CONFIG_SUCCESS\'', done => {
41+
const store = createMockStore({});
42+
43+
store.subscribe(() => {
44+
const dispatchedActions = store.getActions();
45+
if (dispatchedActions.length === 2) {
46+
expect(dispatchedActions[0].type).to.eql(types.FETCH_UNGIT_CONFIG_REQUEST);
47+
expect(dispatchedActions[1].type).to.eql(types.FETCH_UNGIT_CONFIG_SUCCESS);
48+
expect(dispatchedActions[1].payload).to.eql(mockPayload);
49+
done();
50+
}
51+
});
52+
store.dispatch(fetchUngitConfig());
53+
});
54+
});
55+
56+
describe('fetchUngitConfig fails', () => {
57+
58+
beforeEach(() => {
59+
nock('http://localhost:8448')
60+
.get('/ungit/config')
61+
.reply(500, null);
62+
});
63+
64+
it('should dispatch \'FETCH_UNGIT_CONFIG_FAILURE\'', done => {
65+
const store = createMockStore({});
66+
67+
store.subscribe(() => {
68+
const dispatchedActions = store.getActions();
69+
if (dispatchedActions.length === 2) {
70+
expect(dispatchedActions[0].type).to.eql(types.FETCH_UNGIT_CONFIG_REQUEST);
71+
expect(dispatchedActions[1].type).to.eql(types.FETCH_UNGIT_CONFIG_FAILURE);
72+
expect(dispatchedActions[1].payload).to.be.an('object');
73+
done();
74+
}
75+
});
76+
store.dispatch(fetchUngitConfig());
77+
});
78+
});
79+
});
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import nock from 'nock';
2+
import sinon from 'sinon';
3+
import expect from 'expect.js';
4+
import configureStore from 'redux-mock-store';
5+
import { createStore, applyMiddleware } from 'redux';
6+
import { apiMiddleware, CALL_API } from 'redux-api-middleware';
7+
8+
import * as types from 'constants/action-types';
9+
import { fetchUserConfig } from 'actions/user-config';
10+
11+
const createMockStore = configureStore([ apiMiddleware ]);
12+
13+
describe('redux-api-middleware::user-config', () => {
14+
describe('fetchUserConfig successfully', () => {
15+
const mockPayload = { message: 'success' };
16+
17+
beforeEach(() => {
18+
nock('http://localhost:8448')
19+
.get('/api/userconfig')
20+
.reply(200, mockPayload);
21+
});
22+
23+
it('should dispatch \'FETCH_USER_CONFIG_REQUEST\'', done => {
24+
const store = createMockStore({});
25+
26+
store.subscribe(() => {
27+
const dispatchedActions = store.getActions();
28+
if (dispatchedActions.length === 1) {
29+
expect(dispatchedActions[0].type).to.eql(types.FETCH_USER_CONFIG_REQUEST);
30+
done();
31+
}
32+
});
33+
store.dispatch(fetchUserConfig());
34+
});
35+
36+
it('should dispatch \'FETCH_USER_CONFIG_SUCCESS\'', done => {
37+
const store = createMockStore({});
38+
39+
store.subscribe(() => {
40+
const dispatchedActions = store.getActions();
41+
if (dispatchedActions.length === 2) {
42+
expect(dispatchedActions[0].type).to.eql(types.FETCH_USER_CONFIG_REQUEST);
43+
expect(dispatchedActions[1].type).to.eql(types.FETCH_USER_CONFIG_SUCCESS);
44+
expect(dispatchedActions[1].payload).to.eql(mockPayload);
45+
done();
46+
}
47+
});
48+
store.dispatch(fetchUserConfig());
49+
});
50+
});
51+
52+
describe('fetchUserConfig fails', () => {
53+
54+
beforeEach(() => {
55+
nock('http://localhost:8448')
56+
.get('/api/userconfig')
57+
.reply(500, null);
58+
});
59+
60+
it('should dispatch \'FETCH_USER_CONFIG_FAILURE\'', done => {
61+
const store = createMockStore({});
62+
63+
store.subscribe(() => {
64+
const dispatchedActions = store.getActions();
65+
if (dispatchedActions.length === 2) {
66+
expect(dispatchedActions[0].type).to.eql(types.FETCH_USER_CONFIG_REQUEST);
67+
expect(dispatchedActions[1].type).to.eql(types.FETCH_USER_CONFIG_FAILURE);
68+
expect(dispatchedActions[1].payload).to.be.an('object');
69+
done();
70+
}
71+
});
72+
store.dispatch(fetchUserConfig());
73+
});
74+
});
75+
});
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
import nock from 'nock';
2+
import sinon from 'sinon';
3+
import expect from 'expect.js';
4+
import configureStore from 'redux-mock-store';
5+
import { createStore, applyMiddleware } from 'redux';
6+
import { apiMiddleware, CALL_API } from 'redux-api-middleware';
7+
8+
import * as types from 'constants/action-types';
9+
import { fetchLatestVersion, fetchGitVersion } from 'actions/version';
10+
11+
const createMockStore = configureStore([ apiMiddleware ]);
12+
13+
describe('redux-api-middleware::version', () => {
14+
describe('fetchLatestVersion successfully', () => {
15+
const mockPayload = { message: 'success' };
16+
17+
beforeEach(() => {
18+
nock('http://localhost:8448')
19+
.get('/api/latestversion')
20+
.reply(200, mockPayload);
21+
});
22+
23+
it('should dispatch \'FETCH_LATEST_VERSION_REQUEST\'', done => {
24+
const store = createMockStore({});
25+
26+
store.subscribe(() => {
27+
const dispatchedActions = store.getActions();
28+
if (dispatchedActions.length === 1) {
29+
expect(dispatchedActions[0].type).to.eql(types.FETCH_LATEST_VERSION_REQUEST);
30+
done();
31+
}
32+
});
33+
store.dispatch(fetchLatestVersion());
34+
});
35+
36+
it('should dispatch \'FETCH_USER_CONFIG_SUCCESS\'', done => {
37+
const store = createMockStore({});
38+
39+
store.subscribe(() => {
40+
const dispatchedActions = store.getActions();
41+
if (dispatchedActions.length === 2) {
42+
expect(dispatchedActions[0].type).to.eql(types.FETCH_LATEST_VERSION_REQUEST);
43+
expect(dispatchedActions[1].type).to.eql(types.FETCH_LATEST_VERSION_SUCCESS);
44+
expect(dispatchedActions[1].payload).to.eql(mockPayload);
45+
done();
46+
}
47+
});
48+
store.dispatch(fetchLatestVersion());
49+
});
50+
});
51+
52+
describe('fetchLatestVersion fails', () => {
53+
54+
beforeEach(() => {
55+
nock('http://localhost:8448')
56+
.get('/api/latestversion')
57+
.reply(500, null);
58+
});
59+
60+
it('should dispatch \'FETCH_LATEST_VERSION_FAILURE\'', done => {
61+
const store = createMockStore({});
62+
63+
store.subscribe(() => {
64+
const dispatchedActions = store.getActions();
65+
if (dispatchedActions.length === 2) {
66+
expect(dispatchedActions[0].type).to.eql(types.FETCH_LATEST_VERSION_REQUEST);
67+
expect(dispatchedActions[1].type).to.eql(types.FETCH_LATEST_VERSION_FAILURE);
68+
expect(dispatchedActions[1].payload).to.be.an('object');
69+
done();
70+
}
71+
});
72+
store.dispatch(fetchLatestVersion());
73+
});
74+
});
75+
76+
describe('fetchGitVersion successfully', () => {
77+
const mockPayload = { message: 'success' };
78+
79+
beforeEach(() => {
80+
nock('http://localhost:8448')
81+
.get('/api/gitversion')
82+
.reply(200, mockPayload);
83+
});
84+
85+
it('should dispatch \'FETCH_GIT_VERSION_REQUEST\'', done => {
86+
const store = createMockStore({});
87+
88+
store.subscribe(() => {
89+
const dispatchedActions = store.getActions();
90+
if (dispatchedActions.length === 1) {
91+
expect(dispatchedActions[0].type).to.eql(types.FETCH_GIT_VERSION_REQUEST);
92+
done();
93+
}
94+
});
95+
store.dispatch(fetchGitVersion());
96+
});
97+
98+
it('should dispatch \'FETCH_GIT_VERSION_SUCCESS\'', done => {
99+
const store = createMockStore({});
100+
101+
store.subscribe(() => {
102+
const dispatchedActions = store.getActions();
103+
if (dispatchedActions.length === 2) {
104+
expect(dispatchedActions[0].type).to.eql(types.FETCH_GIT_VERSION_REQUEST);
105+
expect(dispatchedActions[1].type).to.eql(types.FETCH_GIT_VERSION_SUCCESS);
106+
expect(dispatchedActions[1].payload).to.eql(mockPayload);
107+
done();
108+
}
109+
});
110+
store.dispatch(fetchGitVersion());
111+
});
112+
});
113+
114+
describe('fetchGitVersion fails', () => {
115+
116+
beforeEach(() => {
117+
nock('http://localhost:8448')
118+
.get('/api/gitversion')
119+
.reply(500, null);
120+
});
121+
122+
it('should dispatch \'FETCH_GIT_VERSION_FAILURE\'', done => {
123+
const store = createMockStore({});
124+
125+
store.subscribe(() => {
126+
const dispatchedActions = store.getActions();
127+
if (dispatchedActions.length === 2) {
128+
expect(dispatchedActions[0].type).to.eql(types.FETCH_GIT_VERSION_REQUEST);
129+
expect(dispatchedActions[1].type).to.eql(types.FETCH_GIT_VERSION_FAILURE);
130+
expect(dispatchedActions[1].payload).to.be.an('object');
131+
done();
132+
}
133+
});
134+
store.dispatch(fetchGitVersion());
135+
});
136+
});
137+
});

0 commit comments

Comments
 (0)