Skip to content

Commit 8def9d6

Browse files
committed
add coveralls and few tests
1 parent d72cd8a commit 8def9d6

File tree

7 files changed

+59
-15
lines changed

7 files changed

+59
-15
lines changed

.eslintignore

-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ webpack.config.prod.js
33
webpack.config.server.js
44
webpack.config.babel.js
55
index.js
6-
server/tests/

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ services:
88
- mongodb
99
before_script:
1010
- sleep 15
11+
after_success:
12+
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'

client/modules/Intl/IntlReducer.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ const initialState = {
1111

1212
const IntlReducer = (state = initialState, action) => {
1313
switch (action.type) {
14-
case SWITCH_LANGUAGE:
15-
return { ...state, ...action };
14+
case SWITCH_LANGUAGE: {
15+
const { type, ...actionWithoutType } = action; // eslint-disable-line
16+
return { ...state, ...actionWithoutType };
17+
}
1618

1719
default:
1820
return state;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import test from 'ava';
2+
import { actionTest } from 'redux-ava';
3+
4+
import {
5+
SWITCH_LANGUAGE,
6+
switchLanguage,
7+
} from '../IntlActions';
8+
import { localizationData } from '../../../../Intl/setup';
9+
10+
const lang = 'en';
11+
12+
test('should return the correct type for switchLanguage', actionTest(
13+
switchLanguage,
14+
lang,
15+
{ type: SWITCH_LANGUAGE, ...localizationData[lang] },
16+
));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import test from 'ava';
2+
import { reducerTest } from 'redux-ava';
3+
import intlReducer from '../IntlReducer';
4+
import { switchLanguage } from '../IntlActions';
5+
import { localizationData, enabledLanguages } from '../../../../Intl/setup';
6+
7+
test('action for SWITCH_LANGUAGE is working', reducerTest(
8+
intlReducer,
9+
{ locale: 'en', enabledLanguages, ...localizationData.en },
10+
switchLanguage('fr'),
11+
{ locale: 'fr', enabledLanguages, ...localizationData.fr },
12+
));

package.json

+18-3
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,12 @@
113113
},
114114
"ava": {
115115
"files": [
116-
"**/*.spec.js"
116+
"client/**/*.spec.js",
117+
"server/**/*.spec.js"
117118
],
118119
"source": [
119-
"client/**/*.{js}",
120-
"server/**/*.{js}"
120+
"client/**/*.js",
121+
"server/**/*.js"
121122
],
122123
"failFast": true,
123124
"babel": "inherit",
@@ -126,6 +127,20 @@
126127
]
127128
},
128129
"nyc": {
130+
"include": [
131+
"client/**/*.js",
132+
"server/**/*.js"
133+
],
134+
"exclude": [
135+
"**/*.spec.js",
136+
"client/reducers.js",
137+
"client/store.js",
138+
"client/routes.js",
139+
"server/util/setup-test-env.js",
140+
"server/util/test-helpers.js",
141+
"server/config.js",
142+
"server/dummyData.js"
143+
],
129144
"reporter": [
130145
"lcov",
131146
"text",

server/tests/post.spec.js server/models/__tests__/post.spec.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
import test from 'ava';
2-
import { expect } from 'chai';
32
import request from 'supertest';
4-
import app from '../server';
5-
import Post from '../models/post';
6-
import { connectDB, dropDB } from '../util/test-helpers';
3+
import app from '../../server';
4+
import Post from '../post';
5+
import { connectDB, dropDB } from '../../util/test-helpers';
76

87
// Initial posts added into test db
98
const posts = [
10-
new Post({name: 'Prashant', title: 'Hello Mern', cuid: 'f34gb2bh24b24b2', content: "All cats meow 'mern!'"}),
11-
new Post({name: 'Mayank', title: 'Hi Mern', cuid: 'f34gb2bh24b24b3', content: "All dogs bark 'mern!'"})
9+
new Post({ name: 'Prashant', title: 'Hello Mern', cuid: 'f34gb2bh24b24b2', content: "All cats meow 'mern!'" }),
10+
new Post({ name: 'Mayank', title: 'Hi Mern', cuid: 'f34gb2bh24b24b3', content: "All dogs bark 'mern!'" }),
1211
];
1312

1413
test.beforeEach('connect and add two post entries', t => {
15-
1614
connectDB(t, () => {
1715
Post.create(posts, err => {
18-
if(err) t.fail('Unable to create posts');
16+
if (err) t.fail('Unable to create posts');
1917
});
2018
});
2119
});
@@ -38,7 +36,7 @@ test.serial('Should correctly give number of Posts', async t => {
3836
test.serial('Should send correct data when queried against a cuid', async t => {
3937
t.plan(2);
4038

41-
var post = new Post({ name: 'Foo', title: 'bar', slug: 'bar', cuid: 'f34gb2bh24b24b2', content: 'Hello Mern says Foo' });
39+
const post = new Post({ name: 'Foo', title: 'bar', slug: 'bar', cuid: 'f34gb2bh24b24b2', content: 'Hello Mern says Foo' });
4240
post.save();
4341

4442
const res = await request(app)

0 commit comments

Comments
 (0)