Skip to content

Commit c41deeb

Browse files
authored
Merge pull request #2 from dev-ashishk/circleci-project-setup
Circleci project setup
2 parents d902c76 + d6db4ff commit c41deeb

File tree

13 files changed

+8582
-4119
lines changed

13 files changed

+8582
-4119
lines changed

.babelrc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"modules": false,
66
"targets": [
77
"last 3 versions", "not dead", "not < 1%"
8-
],
9-
// "useBuiltIns": "usage"
8+
]
109
}
1110
],
1211
"@babel/preset-react"
@@ -31,6 +30,18 @@
3130
}
3231
]
3332
]
34-
}
33+
},
34+
"test": {
35+
"presets": [
36+
[
37+
"@babel/preset-env",
38+
{
39+
"targets": {
40+
"node": "current"
41+
}
42+
}
43+
]
44+
]
45+
}
3546
}
3647
}

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
steps:
1212
- run: npm install
1313
- run: npm run lint
14+
- run: npm test -- -u
1415
workflows:
1516
build-and-test:
1617
jobs:

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
.gitignore
55
.travis.yml
66
docker-compose.yml
7-
Dockerfile
7+
Dockerfile
8+
*.test.js

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/client-build
22
/server-build
3-
/node_modules
3+
/node_modules
4+
__snapshots__

client/__tests__/index.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* eslint-disable no-undef */
2+
import configureMockStore from "redux-mock-store";
3+
import thunk from "redux-thunk";
4+
import axios from "axios";
5+
import Cookies from "universal-cookie";
6+
import mockData from "../constants/mockData";
7+
import * as actions from "../actions/index";
8+
import * as types from "../constants/ActionTypes";
9+
import * as reducers from "../reducers/StoriesReducer";
10+
11+
const cookies = new Cookies();
12+
jest.mock("axios");
13+
const middlewares = [thunk.withExtraArgument({
14+
api: axios,
15+
cookies
16+
})];
17+
const mockStore = configureMockStore(middlewares);
18+
19+
const store = mockStore(reducers.INITIAL_STATE);
20+
21+
describe("TESTING ACTIONS", () => {
22+
const response = mockData;
23+
const payload = response.hits[0];
24+
const expectedAction = [
25+
{
26+
type: types.FETCH_STORIES_PENDING
27+
}, {
28+
type: types.FETCH_STORIES_SUCCESS,
29+
payload: response
30+
},
31+
{
32+
type: types.UPVOTE_STORY,
33+
payload: payload.objectID
34+
}
35+
];
36+
axios.get.mockResolvedValue({
37+
...response
38+
});
39+
it(`${types.UPVOTE_STORY} ->`, () => {
40+
store
41+
.dispatch(actions.fetchStories(1))
42+
.then(() => expect(actions.updateUpVote(payload)).toEqual(expectedAction));
43+
});
44+
45+
it(`${types.HIDE_STORY} ->`, () => {
46+
store
47+
.dispatch(actions.fetchStories(1))
48+
.then(() => expect(actions.hideStory(payload)).toEqual(expectedAction));
49+
});
50+
});

client/actions/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ export const fetchStories = (page = 0) => async (dispatch, getState, { api }) =>
4848
const res = await api.get(`/search?page=${page}&hitsPerPage=30`);
4949
const modifiedData = await dispatch(updateListWithPersistentData(res.data));
5050
dispatch(updateStoriesInStore(modifiedData));
51+
return modifiedData;
5152
} catch (err) {
5253
console.log(err);
5354
dispatch({
5455
type: FETCH_STORIES_FAILURE
5556
});
57+
return {};
5658
}
5759
};
5860

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from "react";
2+
import { MemoryRouter } from "react-router-dom";
3+
import { shallow, configure } from "enzyme";
4+
import Adapter from "enzyme-adapter-react-16";
5+
// eslint-disable-next-line import/no-self-import
6+
import { Provider } from "react-redux";
7+
import configureMockStore from "redux-mock-store";
8+
import StoryList from "../index";
9+
import mockData from "../../../constants/mockData";
10+
11+
React.useLayoutEffect = React.useEffect;
12+
13+
const mockStore = configureMockStore();
14+
const store = mockStore({
15+
stories: {
16+
loading: false,
17+
data: mockData
18+
}
19+
});
20+
21+
configure({ adapter: new Adapter() });
22+
23+
test("Testing StoryList >>", () => {
24+
const component = shallow(
25+
<Provider store={store}>
26+
<MemoryRouter>
27+
<StoryList />
28+
</MemoryRouter>
29+
</Provider>
30+
);
31+
32+
// const tree = component.toJSON();
33+
expect(component.render()).toMatchSnapshot();
34+
});

client/constants/mockData.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
export default {
2+
hits: [
3+
{
4+
created_at: "2013-04-12T05:07:53.000Z",
5+
title: "",
6+
url: "",
7+
author: "xijuan",
8+
points: 2751,
9+
story_text: "26 to 30",
10+
comment_text: null,
11+
num_comments: null,
12+
story_id: null,
13+
story_title: null,
14+
story_url: null,
15+
parent_id: 5536734,
16+
created_at_i: 1365743273,
17+
relevancy_score: 4557,
18+
_tags: [
19+
"pollopt", "author_xijuan", "story_5536739"
20+
],
21+
objectID: "5536739",
22+
_highlightResult: {
23+
title: {
24+
value: "",
25+
matchLevel: "none",
26+
matchedWords: []
27+
},
28+
url: {
29+
value: "",
30+
matchLevel: "none",
31+
matchedWords: []
32+
},
33+
author: {
34+
value: "xijuan",
35+
matchLevel: "none",
36+
matchedWords: []
37+
},
38+
story_text: {
39+
value: "26 to 30",
40+
matchLevel: "none",
41+
matchedWords: []
42+
}
43+
}
44+
}, {
45+
created_at: "2011-05-29T01:13:53.000Z",
46+
title: null,
47+
url: null,
48+
author: "pg",
49+
points: 2743,
50+
story_text: "I liked it better when comment scores were displayed.",
51+
comment_text: null,
52+
num_comments: null,
53+
story_id: null,
54+
story_title: null,
55+
story_url: null,
56+
parent_id: 2595605,
57+
created_at_i: 1306631633,
58+
relevancy_score: 3240,
59+
_tags: [
60+
"pollopt", "author_pg", "story_2595606"
61+
],
62+
objectID: "2595606",
63+
_highlightResult: {
64+
author: {
65+
value: "pg",
66+
matchLevel: "none",
67+
matchedWords: []
68+
},
69+
story_text: {
70+
value: "I liked it better when comment scores were displayed.",
71+
matchLevel: "none",
72+
matchedWords: []
73+
}
74+
}
75+
}
76+
],
77+
nbHits: 21526846,
78+
page: 1,
79+
nbPages: 34,
80+
hitsPerPage: 30,
81+
exhaustiveNbHits: true,
82+
query: "",
83+
params: "advancedSyntax=true\u0026analytics=true\u0026analyticsTags=backend\u0026hitsPerPage=30\u0026page=1",
84+
processingTimeMS: 2
85+
};

dev.env renamed to env/dev.env

File renamed without changes.

env/prod.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
PORT=3000
2+
API_URL=https://hn.algolia.com/
3+
HOST_URL=http://localhost:3000

0 commit comments

Comments
 (0)