Commit 51e1a593 authored by Richard Smith-Unna's avatar Richard Smith-Unna
Browse files

Merge branch 'reducer-import-export' into 'master'

Fix reducer export/import

See merge request !22
parents b7da0f04 92ae3971
Pipeline #1110 passed with stage
in 6 minutes and 14 seconds
......@@ -4,13 +4,13 @@
"main": "src/index.js",
"scripts": {
"compile": "babel --presets es2015,react -d lib/ src/",
"test": "./test/helpers/runtestcmd jest",
"test": "./test/helpers/runtestcmd jest --runInBand",
"testdocker": "./test/helpers/runtestcmd \"jest --runInBand --no-watchman --no-cache --verbose --forceExit\"",
"testci": "gitlab-ci-multi-runner exec docker --docker-image=pubsweet/pubsweet-test-base test",
"eslint": "eslint"
},
"engines": {
"node": ">=5.0.0",
"node": ">=7.7.0",
"npm": ">=3.0.0"
},
"author": "Collaborative Knowledge Foundation",
......
......@@ -17,7 +17,7 @@ import clone from 'lodash/clone'
import findIndex from 'lodash/findIndex'
import without from 'lodash/without'
export function collections (state = [], action) {
export default function (state = [], action) {
const collections = clone(state)
// TODO: store entities as an object or immutable Map, with the id as the key
......@@ -90,4 +90,4 @@ export function collections (state = [], action) {
}
return state
}
\ No newline at end of file
}
......@@ -4,7 +4,7 @@ import {
GET_USER_REQUEST, GET_USER_SUCCESS, GET_USER_FAILURE
} from '../actions/types'
export function currentUser (state = {
export default function (state = {
isFetching: false,
isAuthenticated: false,
token: token()
......
// Updates error message to notify about the failed fetches.
export default function (state = null, action) {
const {error} = action
if (error) {
console.log(error)
return error.message
} else {
return null
}
}
......@@ -3,7 +3,7 @@ import {
FILE_UPLOAD_SUCCESS,
} from '../actions/types'
export function fileUpload (state = {
export default function (state = {
isFetching: false
}, action) {
switch (action.type) {
......
......@@ -15,7 +15,7 @@ import clone from 'lodash/clone'
import assign from 'lodash/assign'
import unset from 'lodash/unset'
export function fragments (state = {}, action) {
export default function (state = {}, action) {
const fragments = clone(state)
function replaceAll () {
......
// Updates error message to notify about the failed fetches.
export function error (state = null, action) {
const { error } = action
if (error) {
console.log(error)
return error.message
} else {
return null
}
}
import { collections } from './collections'
import { fragments } from './fragments'
import error from './error'
import collections from './collections'
import fragments from './fragments'
import currentUser from './current_user'
import users from './users'
import teams from './teams'
import fileUpload from './fileUpload'
export { collections, fragments, currentUser, users, teams, fileUpload }
export default { error, collections, fragments, currentUser, users, teams, fileUpload }
......@@ -10,7 +10,7 @@ import findIndex from 'lodash/findIndex'
import assign from 'lodash/assign'
import difference from 'lodash/difference'
export function teams (state = [], action) {
export default function (state = [], action) {
const teams = clone(state)
function updateOne () {
......
......@@ -6,7 +6,7 @@ import {
} from '../actions/types'
// The users reducer.
export function users (state = {
export default function (state = {
isFetching: false
}, action) {
switch (action.type) {
......
......@@ -3,7 +3,7 @@ import { routerReducer, routerMiddleware } from 'react-router-redux'
import { browserHistory } from 'react-router'
import thunk from 'redux-thunk'
import * as reducers from '../reducers'
import reducers from '../reducers'
require('../components/reducers').forEach(
componentReducers => Object.assign(reducers, componentReducers)
......
......@@ -26,8 +26,9 @@ module.exports = app => {
describeAction('createFragment', {
firstarg: mockcol,
secondarg: {
name: 'some name',
body: 'some text'
title: 'mock fragment',
type: 'some_fragment',
owners: []
},
types: {
request: T.CREATE_FRAGMENT_REQUEST,
......@@ -49,7 +50,9 @@ module.exports = app => {
secondarg: () => {
return {
id: storedData.fragment.id,
name: 'new name'
title: 'modded fragment',
type: 'some_fragment',
owners: []
}
},
types: {
......
......@@ -85,8 +85,12 @@ const describeAction = actions => (key, opts, cb) => {
)
expect(dispatched).to.be.ok
expect(dispatched.type).to.equal(opts.types.request)
expect(
dispatched.type
).to.equal(
opts.types.request,
`Received dispatched object with wrong type: \n${JSON.stringify(dispatched, null, 2)}`
)
if (properties) {
expect(Object.keys(dispatched)).to.include.members(properties)
}
......@@ -112,7 +116,12 @@ const describeAction = actions => (key, opts, cb) => {
).then(
dispatched => {
expect(dispatched).to.be.ok
expect(dispatched.type).to.equal(opts.types.success)
expect(
dispatched.type
).to.equal(
opts.types.success,
`Received dispatched object with wrong type: \n${JSON.stringify(dispatched, null, 2)}`
)
if (properties) {
expect(Object.keys(dispatched)).to.include.members(properties)
}
......@@ -139,7 +148,12 @@ const describeAction = actions => (key, opts, cb) => {
).then(
dispatched => {
expect(dispatched).to.be.ok
expect(dispatched.type).to.equal(opts.types.failure)
expect(
dispatched.type
).to.equal(
opts.types.failure,
`Received dispatched object with wrong type: \n${JSON.stringify(dispatched, null, 2)}`
)
if (properties) {
expect(Object.keys(dispatched)).to.include.members(properties)
}
......
const allreducers = require.requireActual('../../src/reducers')
const allreducers = require.requireActual('../../src/reducers').default
const expect = require.requireActual('chai').expect
const describeReducerSet = (key, reducers, cb) => describe(key, () => {
it('is exported from the file', () => {
expect(reducers).to.have.property(key)
expect(reducers).to.have.property('default')
})
it('is exported in the all reducers object', () => {
......@@ -11,7 +11,7 @@ const describeReducerSet = (key, reducers, cb) => describe(key, () => {
})
it('is a function', () => {
expect(reducers[key]).to.be.a('function')
expect(reducers.default).to.be.a('function')
})
if (cb) cb()
......
jasmine.DEFAULT_TIMEOUT_INTERVAL = 600000
process.env.NODE_ENV = 'production'
process.env.SILENT_NPM = 'true'
global.PUBSWEET_COMPONENTS = []
......
......@@ -13,7 +13,7 @@ module.exports = app => describeReducerSet('collections', reducers, () => {
const describeReducer = require.requireActual(
'../helpers/describeReducer'
)(reducers['collections'])
)(reducers.default)
describeReducer('getCollections success', {
state: [mockcol],
......
......@@ -6,7 +6,7 @@ const T = require('../../src/actions/types')
module.exports = app => describeReducerSet('currentUser', reducers, () => {
const describeReducer = require.requireActual(
'../helpers/describeReducer'
)(reducers['currentUser'])
)(reducers.default)
const mockuser = {
name: 'jo johnson'
......
......@@ -8,7 +8,7 @@ const clone = require('lodash/clone')
module.exports = app => describeReducerSet('fileUpload', reducers, () => {
const describeReducer = require.requireActual(
'../helpers/describeReducer'
)(reducers['fileUpload'])
)(reducers.default)
describeReducer('fileUpload success', {
action: {
......
......@@ -8,16 +8,24 @@ const clone = require('lodash/clone')
module.exports = app => describeReducerSet('fragments', reducers, () => {
const describeReducer = require.requireActual(
'../helpers/describeReducer'
)(reducers['fragments'])
)(reducers.default)
const mockcol = app.collection
mockcol.fragments = []
const mockfrag = { name: 'mock fragment', id: 'abcd' }
const mockfrag = {
title: 'mock fragment',
type: 'some_fragment',
owners: []
}
const mockstate = {}
mockstate[mockfrag.id] = mockfrag
const mockfragmod = { name: 'modded fragmemnt', id: 'abcd' }
const mockfragmod = {
title: 'modded fragment',
type: 'some_fragment',
owners: []
}
mockstatemod = {}
mockstatemod[mockfrag.id] = mockfragmod
......
......@@ -8,7 +8,7 @@ const clone = require('lodash/clone')
module.exports = app => describeReducerSet('teams', reducers, () => {
const describeReducer = require.requireActual(
'../helpers/describeReducer'
)(reducers['teams'])
)(reducers.default)
const mockteam = { name: 'someteam', id: '1234' }
const mockstate = [mockteam]
......
......@@ -8,7 +8,7 @@ const clone = require('lodash/clone')
module.exports = app => describeReducerSet('users', reducers, () => {
const describeReducer = require.requireActual(
'../helpers/describeReducer'
)(reducers['users'])
)(reducers.default)
const user = app.user
const usermod = clone(user)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment