UNPKG

twreporter-redux

Version:

redux actions and reducers for twreporter website

112 lines (96 loc) 2.73 kB
'use strict'; var _posts = require('../posts'); var _actionTypes = require('../../constants/action-types'); var _actionTypes2 = _interopRequireDefault(_actionTypes); var _chai = require('chai'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var post1 = { id: 'post-id-1', slug: 'post-slug-1' }; /* global describe, it*/ var post2 = { id: 'post-id-2', slug: 'post-slug-2' }; var post3 = { id: 'post-id-3', slug: 'post-slug-3' }; var post4 = { id: 'post-id-4', slug: 'post-slug-4' }; describe('post reducer', function () { it('should return the initial state', function () { (0, _chai.expect)((0, _posts.post)({}, {})).to.deep.equal({}); }); it('should handle START_TO_GET_A_FULL_POST', function () { (0, _chai.expect)((0, _posts.post)({}, { type: _actionTypes2.default.START_TO_GET_A_FULL_POST, url: 'http://localhost:8080/v1/posts/mock-post' })).to.deep.equal({ isFetching: true, url: 'http://localhost:8080/v1/posts/mock-post' }); }); it('should handle GET_A_FULL_POST', function () { (0, _chai.expect)((0, _posts.post)({}, { type: _actionTypes2.default.GET_A_FULL_POST, payload: post1 })).to.deep.equal({ slug: post1.slug, error: null, isFetching: false }); }); it('should handle ERROR_TO_GET_A_FULL_POST', function () { var err = new Error('error occurs'); (0, _chai.expect)((0, _posts.post)({}, { type: _actionTypes2.default.ERROR_TO_GET_A_FULL_POST, error: err })).to.deep.equal({ error: err }); }); }); describe('posts reducer', function () { it('should return the initial state', function () { (0, _chai.expect)((0, _posts.posts)({}, {})).to.deep.equal({}); }); it('should handle GET_LISTED_POSTS', function () { (0, _chai.expect)((0, _posts.posts)({}, { type: _actionTypes2.default.GET_LISTED_POSTS, payload: { items: [post1, post2, post3, post4], total: 10, listID: 'mock-list-id' } })).to.deep.equal({ 'mock-list-id': { items: [post1.slug, post2.slug, post3.slug, post4.slug], total: 10, error: null } }); }); it('should handle ERROR_TO_GET_LISTED_POSTS', function () { var err = new Error('error occurs'); (0, _chai.expect)((0, _posts.posts)({ 'mock-list-id': { items: [post1], total: 5, error: null } }, { type: _actionTypes2.default.ERROR_TO_GET_LISTED_POSTS, error: err, listID: 'mock-list-id' })).to.deep.equal({ 'mock-list-id': { items: [post1], total: 5, error: err } }); }); });