Commit 12c7b753 authored by Rik Smith-Unna's avatar Rik Smith-Unna

Tests for actions

parent e31be8df
{
"presets": ["es2015", "react"],
"plugins": ["transform-object-rest-spread"]
}
......@@ -2,7 +2,8 @@
"name": "pubsweet-frontend",
"version": "0.6.2",
"scripts": {
"test": "NODE_ENV=test ./node_modules/.bin/mocha --harmony src/test/*.js",
"compile": "babel --presets es2015,react -d lib/ src/",
"test": "NODE_ENV=test ./node_modules/.bin/mocha --compilers js:babel-core/register test/*.js",
"eslint": "eslint"
},
"engines": {
......@@ -47,7 +48,11 @@
"redux-thunk": "^0.1.0"
},
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-eslint": "^6.1.2",
"babel-plugin-transform-object-rest-spread": "^6.19.0",
"babel-polyfill": "^6.16.0",
"babel-preset-react": "^6.16.0",
"babel-preset-react-hmre": "^1.1.1",
"babel-preset-stage-2": "^6.5.0",
"chai": "^3.5.0",
......@@ -62,6 +67,8 @@
"expect.js": "^0.3.1",
"expose-loader": "^0.7.0",
"mocha": "^3.0.1",
"pubsweet": "0.0.5",
"require-dir": "^0.3.1",
"standard": "^8.0.0-beta.5",
"supertest": "^2.0.0",
"supertest-as-promised": "^3.2.0",
......
......@@ -197,58 +197,3 @@ export function deleteTeam (team) {
)
}
}
// function updateUserRequest (user) {
// return {
// type: T.UPDATE_USER_REQUEST,
// user: user,
// isFetching: true
// }
// }
// function updateUserSuccess (users) {
// return {
// type: T.UPDATE_USER_SUCCESS,
// isFetching: false,
// users: users
// }
// }
// function updateUserFailure (message) {
// return {
// type: T.UPDATE_USER_FAILURE,
// isFetching: false,
// error: message
// }
// }
// export function updateUser (user) {
// let config = {
// method: 'PUT',
// headers: {
// 'Authorization': 'Bearer ' + localStorage.token,
// 'Content-Type': 'application/json'
// },
// body: JSON.stringify(user)
// }
// return dispatch => {
// dispatch(updateUserRequest(user))
// return fetch(API_ENDPOINT + '/users/' + user.id, config)
// .then(response => {
// if (response.ok) {
// return response.json().then(user => {
// dispatch(updateUserSuccess(user))
// })
// } else {
// return response.json().then(response => {
// dispatch(updateUserFailure(response.message))
// throw new Error(response.message)
// })
// }
// }).catch(err => {
// dispatch(updateUserFailure(err.message))
// console.log('Error: ', err)
// })
// }
// }
import 'babel-polyfill'
require('./helpers/env')
describe('ACTIONS', () => {
require('require-dir')('./actions')
})
const expect = require('chai').expect
const actions = require('../../src/actions/collectionsFragments')
const describeAction = require('../helpers/action')(actions)
const mockcol = {
id: 'fake'
}
const mockfrag = {
id: 'fake'
}
describe('collections and fragments', () => {
describeAction('getCollections', action => {
// TODO: functionality tests here
})
describeAction('getFragments', { firstarg: mockcol }, action => {
// TODO: functionality tests here
})
describeAction('createFragment', {
firstarg: mockcol, secondarg: mockfrag
}, action => {
// TODO: functionality tests here
})
describeAction('updateFragment', {
firstarg: mockcol, secondarg: mockfrag
}, action => {
// TODO: functionality tests here
})
describeAction('deleteFragment', {
firstarg: mockcol, secondarg: mockfrag
}, action => {
// TODO: functionality tests here
})
})
const expect = require('chai').expect
global.window = { localStorage: { token: 'mock' } }
const actions = require('../../src/actions/current_user')
const describeAction = require('../helpers/action')(actions)
describe('current user', () => {
describeAction('getUser', action => {
// TODO: test functionality here
})
})
const expect = require('chai').expect
const actions = require('../../src/actions/teams')
const describeAction = require('../helpers/action')(actions)
describe('teams', () => {
describeAction('getTeams', action => {
// TODO: test functionality here
})
describeAction('createTeam', action => {
// TODO: test functionality here
})
describeAction('updateTeam', action => {
// TODO: test functionality here
})
describeAction('deleteTeam', action => {
// TODO: test functionality here
})
})
const expect = require('chai').expect
const actions = require('../../src/actions/users')
const describeAction = require('../helpers/action')(actions)
describe('users', () => {
describeAction('getUsers', action => {
// TODO: test functionality here
})
describeAction('updateUser', action => {
// TODO: test functionality here
})
})
const expect = require('chai').expect
const defaults = require('lodash/defaults')
const empty = {}
const mockDispatch = () => {}
const mockGetState = () => { return { currentUser: { token: '' } } }
module.exports = actions => (key, opts, testFunctionality) => {
if (typeof opts === 'function') {
testFunctionality = opts
opts = {}
}
defaults(opts, {
firstarg: empty,
secondarg: empty
})
describe(key, () => {
it('is exported', () => {
expect(actions).to.have.property(key)
})
const action = actions[key]
it('returns a fetcher function', () => {
const returned = action(noobj, noobj)
expect(returned).to.be.a('function')
})
it('fetcher function returns a promise', () => {
const fetcher = action(opts.firstarg, opts.secondarg)
const returned = fetcher(mockDispatch, mockGetState)
expect(returned).to.be.a('promise')
})
it('dispatches a typed fragment', () => {
const fetcher = action(opts.firstarg, opts.secondarg)
let frag
fetcher(fragment => { frag = fragment }, mockGetState)
expect(frag).to.exist
expect(frag).to.include.keys('type')
})
testFunctionality(action)
})
}
global.CONFIG = {
'pubsweet-backend': {
API_ENDPOINT: '/api'
}
}
global.window = {}
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