Skip to content

Commit 371a64d

Browse files
committed
all test passed
1 parent 4dc86b1 commit 371a64d

11 files changed

Lines changed: 97 additions & 93 deletions

File tree

app/actionCreators/actionCreators.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const onFetchIssuesError = (dispatch, e, notBeFoundMessage = '') => {
9494
if (!message) {
9595
return Promise.reject(e);
9696
}
97-
dispatch(ReceiveIssuesError(message));
97+
return dispatch(ReceiveIssuesError(message));
9898
};
9999

100100
export const fetchIssue = ({ userName, repoName, issueNumber }) => async dispatch => {
@@ -104,7 +104,7 @@ export const fetchIssue = ({ userName, repoName, issueNumber }) => async dispatc
104104
const issue = mapGithubIssueToLocalIssue(data);
105105
return dispatch(ReceiveIssues([issue]));
106106
} catch (e) {
107-
onFetchIssuesError(dispatch, e, constants.ISSUE_NOT_BE_FOUND_MESSAGE);
107+
return onFetchIssuesError(dispatch, e, constants.ISSUE_NOT_BE_FOUND_MESSAGE);
108108
}
109109
};
110110

@@ -117,7 +117,7 @@ export const fetchIssues = ({ userName, repoName, issuesCount, pageNumber }) =>
117117
const issues = data.map(mapGithubIssueToLocalIssue);
118118
return dispatch(ReceiveIssues(issues));
119119
} catch (e) {
120-
onFetchIssuesError(dispatch, e, constants.USER_OR_REPOSITORY_NOT_BE_FOUND_MESSAGE);
120+
return onFetchIssuesError(dispatch, e, constants.USER_OR_REPOSITORY_NOT_BE_FOUND_MESSAGE);
121121
}
122122
};
123123

app/actionCreators/actionCreators.spec.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ describe('async actions', () => {
2424
const userName = 'userName';
2525
const repos = ['project1', 'project2', 'project3'];
2626
const body = { items: repos.map(name => ({ name })) };
27-
2827
nock(api.hostname)
29-
.get(api.getUserReposPath(userName, ''))
28+
.get(api.withAccessToken(api.getUserReposPath(userName, '')))
3029
.reply(200, body);
3130

3231
const expectedAction = [{ type: constants.RECEIVE_USER_REPOSITORIES, repos }];
@@ -42,7 +41,7 @@ describe('async actions', () => {
4241
it('should dispatch no actions, when request not be successful', () => {
4342
const userName = 'userName';
4443
nock(api.hostname)
45-
.get(api.getUserReposPath(userName, ''))
44+
.get(api.withAccessToken(api.getUserReposPath(userName, '')))
4645
.reply(404);
4746

4847
const initState = {};
@@ -66,7 +65,7 @@ describe('async actions', () => {
6665
const body = { open_issues_count: 100 };
6766

6867
nock(api.hostname)
69-
.get(api.getReposInformationPath(userName, repoName))
68+
.get(api.withAccessToken(api.getReposInformationPath(userName, repoName)))
7069
.reply(200, body);
7170

7271
const store = mockStore({});
@@ -84,7 +83,7 @@ describe('async actions', () => {
8483
const issuesCount = '10';
8584

8685
nock(api.hostname)
87-
.get(api.getReposInformationPath(userName, repoName))
86+
.get(api.withAccessToken(api.getReposInformationPath(userName, repoName)))
8887
.reply(404);
8988

9089
const initState = {};
@@ -122,7 +121,7 @@ describe('async actions', () => {
122121
];
123122

124123
nock(api.hostname)
125-
.get(api.getIssuesPath(userName, repoName, issuesCount, pageNumber))
124+
.get(api.withAccessToken(api.getIssuesPath(userName, repoName, issuesCount, pageNumber)))
126125
.reply(200, body);
127126

128127
const store = mockStore({});
@@ -155,7 +154,7 @@ describe('async actions', () => {
155154
const pageNumber = '1';
156155

157156
nock(api.hostname)
158-
.get(api.getIssuesPath(userName, repoName, issuesCount, pageNumber))
157+
.get(api.withAccessToken(api.getIssuesPath(userName, repoName, issuesCount, pageNumber)))
159158
.reply(404);
160159

161160
const store = mockStore({});
@@ -202,7 +201,7 @@ describe('async actions', () => {
202201
};
203202

204203
nock(api.hostname)
205-
.get(api.getIssuePath(userName, repoName, issueNumber))
204+
.get(api.withAccessToken(api.getIssuePath(userName, repoName, issueNumber)))
206205
.reply(200, body);
207206

208207
const store = mockStore({});
@@ -225,7 +224,7 @@ describe('async actions', () => {
225224
const issueNumber = '1';
226225

227226
nock(api.hostname)
228-
.get(api.getIssuePath(userName, repoName, issueNumber))
227+
.get(api.withAccessToken(api.getIssuePath(userName, repoName, issueNumber)))
229228
.reply(404);
230229

231230
const store = mockStore({});

app/components/IssuesList/Issue.spec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import sinon from 'sinon';
2-
import React from 'react';
3-
import Issue from './Issue';
42
import { componentSetup } from 'utils/ComponentTest';
3+
import Issue from './Issue';
54

65
describe('<Issue/>', () => {
76
const defaultProps = {
@@ -32,6 +31,6 @@ describe('<Issue/>', () => {
3231
it('should call onTitleClick callback with issue id arg when click event fire for title element', () => {
3332
const { title, props } = setup();
3433
title.props().onClick();
35-
expect(props.onTitleClick.calledOnce && props.onTitleClick.calledWithExactly(props.id)).toBeTruthy();
34+
expect(props.onTitleClick.calledOnce && props.onTitleClick.calledWithExactly(props.number)).toBeTruthy();
3635
});
3736
});

app/components/Markdown/Markdown.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { PureComponent } from 'react';
22
import PropTypes from 'prop-types';
33
import block from 'bem-cn';
44
import classnames from 'classnames';
5-
import 'github-markdown-css';
5+
// import 'github-markdown-css';
66

77
class Markdown extends PureComponent {
88
render() {

app/components/StatusIssuesBar/StatusIssuesBar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { PureComponent } from 'react';
22
import PropTypes from 'prop-types';
33
import block from 'bem-cn';
4-
import './StatusIssuesBar.scss';
54
import classnames from 'classnames';
5+
import './StatusIssuesBar.scss';
66

77
class StatusIssuesBar extends PureComponent {
88
render() {

app/components/StatusIssuesBar/StatusIssuesBar.spec.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import StatusIssuesBar from './StatusIssuesBar';
2-
import React from 'react';
31
import { componentSetup } from 'utils/ComponentTest';
2+
import StatusIssuesBar from './StatusIssuesBar';
43

54
describe('<StatusIssuesBar/>', () => {
65
const defaultProps = {
7-
issuesBeReceived: false,
86
issuesIsLoading: false,
97
isRequestFailed: false,
10-
noIssueHave: false,
8+
noIssuesReceived: false,
119
};
1210

1311
const setup = propsOverrides => componentSetup(StatusIssuesBar, defaultProps, propsOverrides);
@@ -33,8 +31,7 @@ describe('<StatusIssuesBar/>', () => {
3331
it('should render noIssuesBeReceivedMessage when no issues is received without request error', () => {
3432
const { props, wrapper } = setup({
3533
isRequestFailed: false,
36-
issuesBeReceived: true,
37-
noIssueHave: true,
34+
noIssuesReceived: true,
3835
noIssuesBeReceivedMessage: 'message',
3936
});
4037
expect(wrapper.children().contains(props.noIssuesBeReceivedMessage)).toBeTruthy();
@@ -44,7 +41,6 @@ describe('<StatusIssuesBar/>', () => {
4441
const { props, wrapper } = setup({
4542
isRequestFailed: false,
4643
issuesBeReceived: false,
47-
noIssueHave: false,
4844
issuesIsLoading: true,
4945
issuesIsLoadingMessage: 'message',
5046
});

app/mainReducers/issues.spec.js

Lines changed: 26 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import { fromJS } from 'immutable';
12
import issues from './issues';
23
import * as constants from '../actionCreators/constants';
34

45
describe('Issue', () => {
5-
const initState = {
6+
const initState = fromJS({
67
didInvalidate: true,
78
isFetching: false,
89
isRequestFailed: false,
@@ -11,8 +12,9 @@ describe('Issue', () => {
1112
paging: {
1213
issuesCountOptions: ['10', '20', '30', '50', '100'],
1314
defaultIssuesCountOption: '20',
15+
issuesPagesCount: null,
1416
},
15-
};
17+
});
1618

1719
it('should return the init state', () => {
1820
expect(issues(undefined, {})).toEqual(initState);
@@ -22,39 +24,25 @@ describe('Issue', () => {
2224
expect(issues(undefined, { type: 'NOT_EXISTING' })).toEqual(initState);
2325
});
2426

25-
it('should handle INVALIDATE_ISSUES', () => {
26-
const originalState = {
27-
...initState,
28-
didInvalidate: false,
29-
data: [{ id: 1 }, { id: 2 }, { id: 5 }],
30-
};
27+
it('should handle INVALIDATE_ISSUES action', () => {
28+
const originalState = initState.set('didInvalidate', false).set('data', fromJS([{ id: 1 }, { id: 2 }, { id: 5 }]));
3129
const expectedState = initState;
32-
expect(issues(originalState, { type: constants.INVALIDATE_ISSUES })).toEqual(expectedState);
30+
expect(issues(originalState, { type: constants.INVALIDATE_ISSUES })).toEqual(fromJS(expectedState));
3331
});
3432

35-
it('should handle REQUEST_ISSUES', () => {
33+
it('should handle REQUEST_ISSUES action', () => {
3634
const originalState = initState;
37-
const expectedState = {
38-
...initState,
39-
didInvalidate: false,
40-
isFetching: true,
41-
};
35+
const expectedState = initState.set('didInvalidate', false).set('isFetching', true);
4236
expect(issues(originalState, { type: constants.REQUEST_ISSUES })).toEqual(expectedState);
4337
});
4438

45-
it('should handle RECEIVE_ISSUES', () => {
46-
const originalState = {
47-
...initState,
48-
data: [{ id: 1 }, { id: 2 }, { id: 5 }],
49-
isFetching: true,
50-
didInvalidate: false,
51-
};
39+
it('should handle RECEIVE_ISSUES action', () => {
40+
const originalState = initState
41+
.set('data', fromJS([{ id: 1 }, { id: 2 }, { id: 5 }]))
42+
.set('isFetching', true)
43+
.set('didInvalidate', false);
5244
const newIssues = [{ id: 7 }, { id: 8 }, { id: 9 }];
53-
const expectedState = {
54-
...originalState,
55-
isFetching: false,
56-
data: [...originalState.data, ...newIssues],
57-
};
45+
const expectedState = originalState.set('isFetching', false).set('data', fromJS(newIssues));
5846
expect(
5947
issues(originalState, {
6048
type: constants.RECEIVE_ISSUES,
@@ -63,20 +51,16 @@ describe('Issue', () => {
6351
).toEqual(expectedState);
6452
});
6553

66-
it('should handle RECEIVE_ISSUES_ERROR', () => {
67-
const originalState = {
68-
...initState,
69-
data: [{ id: 1 }, { id: 2 }, { id: 5 }],
70-
isFetching: true,
71-
didInvalidate: false,
72-
};
54+
it('should handle RECEIVE_ISSUES_ERROR action', () => {
55+
const originalState = initState
56+
.set('data', [{ id: 1 }, { id: 2 }, { id: 5 }])
57+
.set('isFetching', true)
58+
.set('didInvalidate', false);
7359
const errorMessage = 'Message';
74-
const expectedState = {
75-
...originalState,
76-
isFetching: false,
77-
isRequestFailed: true,
78-
errorMessage,
79-
};
60+
const expectedState = originalState
61+
.set('isFetching', false)
62+
.set('isRequestFailed', true)
63+
.set('errorMessage', errorMessage);
8064
expect(
8165
issues(originalState, {
8266
type: constants.RECEIVE_ISSUES_ERROR,
@@ -85,13 +69,10 @@ describe('Issue', () => {
8569
).toEqual(expectedState);
8670
});
8771

88-
it('should handle RECEIVE_ISSUES_PAGES_COUNT', () => {
72+
it('should handle RECEIVE_ISSUES_PAGES_COUNT action', () => {
8973
const originalState = initState;
9074
const issuesPagesCount = 5;
91-
const expectedState = {
92-
...initState,
93-
paging: { ...originalState.paging, issuesPagesCount },
94-
};
75+
const expectedState = originalState.setIn(['paging', 'issuesPagesCount'], issuesPagesCount);
9576
expect(
9677
issues(originalState, {
9778
type: constants.RECEIVE_ISSUES_PAGES_COUNT,

app/mainReducers/userRepositories.spec.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1+
import { fromJS } from 'immutable';
12
import userRepositories from './userRepositories';
23
import { RECEIVE_USER_REPOSITORIES } from '../actionCreators/constants';
34

45
describe('Issue', () => {
56
it('should return the init state', () => {
6-
const expectedState = [];
7+
const expectedState = fromJS([]);
78
expect(userRepositories(undefined, {})).toEqual(expectedState);
89
});
910

1011
it('should not affect state', () => {
11-
const expectedState = [];
12+
const expectedState = fromJS([]);
1213
expect(userRepositories(undefined, { type: 'NOT_EXISTING' })).toEqual(expectedState);
1314
});
1415

1516
it('should delete old and add new repositories', () => {
16-
const originalState = ['repo1', 'repo2', 'repo3', 'repo4'];
17+
const originalState = fromJS(['repo1', 'repo2', 'repo3', 'repo4']);
1718
const newRepos = ['repo5', 'repo6', 'repo7'];
18-
const expectedState = newRepos;
19+
const expectedState = fromJS(newRepos);
1920
expect(
2021
userRepositories(originalState, {
2122
type: RECEIVE_USER_REPOSITORIES,

app/utils/GitHubApi.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ export const getIssuePath = (userName, repoName, issueNumber) => ({
2525
path: `/repos/${userName}/${repoName}/issues/${issueNumber}`,
2626
});
2727

28-
const constructUrl = ({ path, queryParams: pathQueryParams = {} }) => {
28+
export const withAccessToken = ({ path, queryParams: pathQueryParams = {} }) => {
2929
const queryParams = { access_token: githubAccessToken, ...pathQueryParams };
3030
const queryString = Object.keys(queryParams).reduce(
3131
(acc, curr) => `${acc}${acc.length ? '&' : '?'}${curr}=${queryParams[curr]}`,
3232
'',
3333
);
34-
return hostname + path + queryString;
34+
return path + queryString;
3535
};
3636

37+
const constructUrl = path => hostname + withAccessToken(path);
38+
3739
export const getIssueUrl = (userName, repoName, issueNumber) =>
3840
`${constructUrl(getIssuePath(userName, repoName, issueNumber))}`;
3941

0 commit comments

Comments
 (0)