Skip to content

Commit 71e9349

Browse files
authored
Fix type error cannot read property async (#9)
upgrade redux-api-middleware to v2.0.0-beta.2 and fix "type error cannot read property async" for testing
1 parent 18ad19c commit 71e9349

File tree

11 files changed

+61
-55
lines changed

11 files changed

+61
-55
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,4 @@ install:
2727
- npm install
2828

2929
script:
30-
- node -v
3130
- npm run test-react

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"react-dom": "^15.5.4",
6262
"react-redux": "^5.0.4",
6363
"redux": "^3.6.0",
64-
"redux-api-middleware": "^1.0.3",
64+
"redux-api-middleware": "^2.0.0-beta.2",
6565
"rimraf": "~2.6.1",
6666
"semver": "~5.3.0",
6767
"serve-static": "~1.12.2",
@@ -152,7 +152,7 @@
152152
"<rootDir>/config/localStorageMock.js"
153153
],
154154
"testPathIgnorePatterns": [
155-
"<rootDir>[/\\\\](build|docs|node_modules|scripts|clicktests)[/\\\\]"
155+
"<rootDir>[/\\\\](build|docs|node_modules|scripts|clicktests|src-react/__tests__/utils)[/\\\\]"
156156
],
157157
"testEnvironment": "node",
158158
"testURL": "http://localhost",
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import { CALL_API } from 'redux-api-middleware';
1+
import { RSAA } from 'redux-api-middleware';
22
import expect from 'expect.js';
33

44
import * as types from 'constants/action-types';
55
import { fetchUngitConfig } from 'actions/ungit-config';
66

77
describe('ungit-config.js action', () => {
88
describe('fetchUngitConfig', () => {
9-
it('returns CALL_API action object', function(){
9+
it('returns RSAA action object', function(){
1010
const action = fetchUngitConfig();
1111

12-
expect(action[CALL_API]).to.be.an('object');
13-
expect(action[CALL_API].endpoint).to.eql('http://localhost:8448/ungit/config');
14-
expect(action[CALL_API].method).to.eql('GET');
15-
expect(action[CALL_API].types).to.be.an('array');
16-
expect(action[CALL_API].types[0]).to.eql(types.FETCH_UNGIT_CONFIG_REQUEST);
17-
expect(action[CALL_API].types[1]).to.be.an('object');
18-
expect(action[CALL_API].types[1].type).to.eql(types.FETCH_UNGIT_CONFIG_SUCCESS);
19-
expect(action[CALL_API].types[2]).to.eql(types.FETCH_UNGIT_CONFIG_FAILURE);
12+
expect(action[RSAA]).to.be.an('object');
13+
expect(action[RSAA].endpoint).to.eql('http://localhost:8448/ungit/config');
14+
expect(action[RSAA].method).to.eql('GET');
15+
expect(action[RSAA].types).to.be.an('array');
16+
expect(action[RSAA].types[0]).to.eql(types.FETCH_UNGIT_CONFIG_REQUEST);
17+
expect(action[RSAA].types[1]).to.be.an('object');
18+
expect(action[RSAA].types[1].type).to.eql(types.FETCH_UNGIT_CONFIG_SUCCESS);
19+
expect(action[RSAA].types[2]).to.eql(types.FETCH_UNGIT_CONFIG_FAILURE);
2020
});
2121
});
2222
});
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import { CALL_API } from 'redux-api-middleware';
1+
import { RSAA } from 'redux-api-middleware';
22
import expect from 'expect.js';
33

44
import * as types from 'constants/action-types';
55
import { fetchUserConfig } from 'actions/user-config';
66

77
describe('user-config.js action', () => {
88
describe('fetchUserConfig', () => {
9-
it('returns CALL_API action object', function(){
9+
it('returns RSAA action object', function(){
1010
const action = fetchUserConfig();
1111

12-
expect(action[CALL_API]).to.be.an('object');
13-
expect(action[CALL_API].endpoint).to.eql('http://localhost:8448/api/userconfig');
14-
expect(action[CALL_API].method).to.eql('GET');
15-
expect(action[CALL_API].types).to.be.an('array');
16-
expect(action[CALL_API].types[0]).to.eql(types.FETCH_USER_CONFIG_REQUEST);
17-
expect(action[CALL_API].types[1]).to.eql(types.FETCH_USER_CONFIG_SUCCESS);
18-
expect(action[CALL_API].types[2]).to.eql(types.FETCH_USER_CONFIG_FAILURE);
12+
expect(action[RSAA]).to.be.an('object');
13+
expect(action[RSAA].endpoint).to.eql('http://localhost:8448/api/userconfig');
14+
expect(action[RSAA].method).to.eql('GET');
15+
expect(action[RSAA].types).to.be.an('array');
16+
expect(action[RSAA].types[0]).to.eql(types.FETCH_USER_CONFIG_REQUEST);
17+
expect(action[RSAA].types[1]).to.eql(types.FETCH_USER_CONFIG_SUCCESS);
18+
expect(action[RSAA].types[2]).to.eql(types.FETCH_USER_CONFIG_FAILURE);
1919
});
2020
});
2121
});
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
import { CALL_API } from 'redux-api-middleware';
1+
import { RSAA } from 'redux-api-middleware';
22
import expect from 'expect.js';
33

44
import * as types from 'constants/action-types';
55
import { fetchLatestVersion, fetchGitVersion } from 'actions/version';
66

77
describe('version.js action', () => {
88
describe('fetchLatestVersion', () => {
9-
it('returns CALL_API action object', function(){
9+
it('returns RSAA action object', function(){
1010
const action = fetchLatestVersion();
1111

12-
expect(action[CALL_API]).to.be.an('object');
13-
expect(action[CALL_API].endpoint).to.eql('http://localhost:8448/api/latestversion');
14-
expect(action[CALL_API].method).to.eql('GET');
15-
expect(action[CALL_API].types).to.be.an('array');
16-
expect(action[CALL_API].types[0]).to.eql(types.FETCH_LATEST_VERSION_REQUEST);
17-
expect(action[CALL_API].types[1]).to.eql(types.FETCH_LATEST_VERSION_SUCCESS);
18-
expect(action[CALL_API].types[2]).to.eql(types.FETCH_LATEST_VERSION_FAILURE);
12+
expect(action[RSAA]).to.be.an('object');
13+
expect(action[RSAA].endpoint).to.eql('http://localhost:8448/api/latestversion');
14+
expect(action[RSAA].method).to.eql('GET');
15+
expect(action[RSAA].types).to.be.an('array');
16+
expect(action[RSAA].types[0]).to.eql(types.FETCH_LATEST_VERSION_REQUEST);
17+
expect(action[RSAA].types[1]).to.eql(types.FETCH_LATEST_VERSION_SUCCESS);
18+
expect(action[RSAA].types[2]).to.eql(types.FETCH_LATEST_VERSION_FAILURE);
1919
});
2020
});
2121

2222
describe('fetchGitVersion', () => {
23-
it('returns CALL_API action object', function(){
23+
it('returns RSAA action object', function(){
2424
const action = fetchGitVersion();
2525

26-
expect(action[CALL_API]).to.be.an('object');
27-
expect(action[CALL_API].endpoint).to.eql('http://localhost:8448/api/gitversion');
28-
expect(action[CALL_API].method).to.eql('GET');
29-
expect(action[CALL_API].types).to.be.an('array');
30-
expect(action[CALL_API].types[0]).to.eql(types.FETCH_GIT_VERSION_REQUEST);
31-
expect(action[CALL_API].types[1]).to.eql(types.FETCH_GIT_VERSION_SUCCESS);
32-
expect(action[CALL_API].types[2]).to.eql(types.FETCH_GIT_VERSION_FAILURE);
26+
expect(action[RSAA]).to.be.an('object');
27+
expect(action[RSAA].endpoint).to.eql('http://localhost:8448/api/gitversion');
28+
expect(action[RSAA].method).to.eql('GET');
29+
expect(action[RSAA].types).to.be.an('array');
30+
expect(action[RSAA].types[0]).to.eql(types.FETCH_GIT_VERSION_REQUEST);
31+
expect(action[RSAA].types[1]).to.eql(types.FETCH_GIT_VERSION_SUCCESS);
32+
expect(action[RSAA].types[2]).to.eql(types.FETCH_GIT_VERSION_FAILURE);
3333
});
3434
});
3535
});

src-react/__tests__/middlewares/redux-api/ungit-config.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import sinon from 'sinon';
33
import expect from 'expect.js';
44
import configureStore from 'redux-mock-store';
55
import { createStore, applyMiddleware } from 'redux';
6-
import { apiMiddleware, CALL_API } from 'redux-api-middleware';
6+
import { apiMiddleware } from 'redux-api-middleware';
77

8+
import { FETCH_HEADER } from '../../utils/constants';
89
import * as types from 'constants/action-types';
910
import { fetchUngitConfig } from 'actions/ungit-config';
1011

@@ -17,11 +18,11 @@ describe('redux-api-middleware::ungit-config', () => {
1718
beforeEach(() => {
1819
nock('http://localhost:8448')
1920
.get('/ungit/config')
20-
.reply(200, mockPayload);
21+
.reply(200, mockPayload, FETCH_HEADER);
2122

2223
nock('http://localhost:8448')
2324
.get('/api/userconfig')
24-
.reply(200, mockPayload);
25+
.reply(200, mockPayload, FETCH_HEADER);
2526
});
2627

2728
it('should dispatch \'FETCH_UNGIT_CONFIG_REQUEST\'', done => {
@@ -58,7 +59,7 @@ describe('redux-api-middleware::ungit-config', () => {
5859
beforeEach(() => {
5960
nock('http://localhost:8448')
6061
.get('/ungit/config')
61-
.reply(500, null);
62+
.reply(500, null, FETCH_HEADER);
6263
});
6364

6465
it('should dispatch \'FETCH_UNGIT_CONFIG_FAILURE\'', done => {

src-react/__tests__/middlewares/redux-api/user-config.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import sinon from 'sinon';
33
import expect from 'expect.js';
44
import configureStore from 'redux-mock-store';
55
import { createStore, applyMiddleware } from 'redux';
6-
import { apiMiddleware, CALL_API } from 'redux-api-middleware';
6+
import { apiMiddleware } from 'redux-api-middleware';
77

8+
import { FETCH_HEADER } from '../../utils/constants';
89
import * as types from 'constants/action-types';
910
import { fetchUserConfig } from 'actions/user-config';
1011

@@ -17,7 +18,7 @@ describe('redux-api-middleware::user-config', () => {
1718
beforeEach(() => {
1819
nock('http://localhost:8448')
1920
.get('/api/userconfig')
20-
.reply(200, mockPayload);
21+
.reply(200, mockPayload, FETCH_HEADER);
2122
});
2223

2324
it('should dispatch \'FETCH_USER_CONFIG_REQUEST\'', done => {
@@ -54,7 +55,7 @@ describe('redux-api-middleware::user-config', () => {
5455
beforeEach(() => {
5556
nock('http://localhost:8448')
5657
.get('/api/userconfig')
57-
.reply(500, null);
58+
.reply(500, null, FETCH_HEADER);
5859
});
5960

6061
it('should dispatch \'FETCH_USER_CONFIG_FAILURE\'', done => {

src-react/__tests__/middlewares/redux-api/version.test.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import sinon from 'sinon';
33
import expect from 'expect.js';
44
import configureStore from 'redux-mock-store';
55
import { createStore, applyMiddleware } from 'redux';
6-
import { apiMiddleware, CALL_API } from 'redux-api-middleware';
6+
import { apiMiddleware } from 'redux-api-middleware';
77

8+
import { FETCH_HEADER } from '../../utils/constants';
89
import * as types from 'constants/action-types';
910
import { fetchLatestVersion, fetchGitVersion } from 'actions/version';
1011

@@ -17,7 +18,7 @@ describe('redux-api-middleware::version', () => {
1718
beforeEach(() => {
1819
nock('http://localhost:8448')
1920
.get('/api/latestversion')
20-
.reply(200, mockPayload);
21+
.reply(200, mockPayload, FETCH_HEADER);
2122
});
2223

2324
it('should dispatch \'FETCH_LATEST_VERSION_REQUEST\'', done => {
@@ -54,7 +55,7 @@ describe('redux-api-middleware::version', () => {
5455
beforeEach(() => {
5556
nock('http://localhost:8448')
5657
.get('/api/latestversion')
57-
.reply(500, null);
58+
.reply(500, null, FETCH_HEADER);
5859
});
5960

6061
it('should dispatch \'FETCH_LATEST_VERSION_FAILURE\'', done => {
@@ -79,7 +80,7 @@ describe('redux-api-middleware::version', () => {
7980
beforeEach(() => {
8081
nock('http://localhost:8448')
8182
.get('/api/gitversion')
82-
.reply(200, mockPayload);
83+
.reply(200, mockPayload, FETCH_HEADER);
8384
});
8485

8586
it('should dispatch \'FETCH_GIT_VERSION_REQUEST\'', done => {
@@ -116,7 +117,7 @@ describe('redux-api-middleware::version', () => {
116117
beforeEach(() => {
117118
nock('http://localhost:8448')
118119
.get('/api/gitversion')
119-
.reply(500, null);
120+
.reply(500, null, FETCH_HEADER);
120121
});
121122

122123
it('should dispatch \'FETCH_GIT_VERSION_FAILURE\'', done => {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const FETCH_HEADER = {
2+
'Access-Control-Allow-Origin': '*',
3+
'Content-type': 'application/json'
4+
};

src-react/actions/ungit-config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as types from 'constants/action-types';
2-
import { CALL_API } from 'redux-api-middleware';
2+
import { RSAA } from 'redux-api-middleware';
33
import { fetchUserConfig } from './user-config';
44
import store from 'store';
55

66
export function fetchUngitConfig() {
77
return {
8-
[CALL_API]: {
8+
[RSAA]: {
99
endpoint: 'http://localhost:8448/ungit/config',
1010
method: 'GET',
1111
types: [

0 commit comments

Comments
 (0)