Permalink
Browse files

add authReducer test

  • Loading branch information...
bvellek committed Apr 26, 2017
1 parent 6412588 commit eb9c8c33d9f301d6cf7e78a77aae5fecd36d7aa3
@@ -1,6 +1,6 @@
{
"main.css": "static/css/main.3124611b.css",
"main.css.map": "static/css/main.3124611b.css.map",
"main.js": "static/js/main.675b536a.js",
"main.js.map": "static/js/main.675b536a.js.map"
"main.js": "static/js/main.260f5659.js",
"main.js.map": "static/js/main.260f5659.js.map"
}
View

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,95 @@
import { authReducer, initialState } from '../js/reducers/authReducer';
describe('Auth Reducer', () => {
it('should return the intial state when no matching action is dispatched', () => {
expect(authReducer(undefined, {})).toEqual(initialState);
});
it('should handle AUTH_LOADING_STATUS_TRUE by changing authLoadingStatus to true', () => {
const stateAfter = Object.assign({}, initialState, {
authLoadingStatus: true,
});
expect(authReducer(initialState, {
type: 'AUTH_LOADING_STATUS_TRUE',
})).toEqual(stateAfter);
});
it('should handle REGISTER_USER_SUCCESS by passing registrationSuccessMessage, clearing loading status, clear registrationErrorMessage', () => {
const successMsg = {
status: 200,
msg: 'success',
};
const stateAfter = Object.assign({}, initialState, {
authLoadingStatus: false,
registrationErrorMessage: {},
registrationSuccessMessage: successMsg,
});
expect(authReducer(initialState, {
type: 'REGISTER_USER_SUCCESS',
registrationSuccessMessage: successMsg,
})).toEqual(stateAfter);
});
it('should handle REGISTER_USER_ERROR by passing registrationErrorMessage, clearing loading status', () => {
const errorMsg = {
status: 500,
msg: 'fail',
};
const stateAfter = Object.assign({}, initialState, {
authLoadingStatus: false,
registrationErrorMessage: errorMsg,
});
expect(authReducer(initialState, {
type: 'REGISTER_USER_ERROR',
registrationErrorMessage: errorMsg,
})).toEqual(stateAfter);
});
it('should handle LOGIN_USER_SUCCESS by passing clearing loading status, clearing registrationSuccessMessage, clearing loginErrorMessage, setting loginRedirect to true, and passing a userID', () => {
const successMessage = {
user: {
userID: '123ABCDefg',
},
};
const stateAfter = Object.assign({}, initialState, {
authLoadingStatus: false,
registrationSuccessMessage: {},
loginErrorMessage: {},
loginRedirect: true,
currentUser: '123ABCDefg',
});
expect(authReducer(initialState, {
type: 'LOGIN_USER_SUCCESS',
loginSuccessMessage: successMessage,
})).toEqual(stateAfter);
});
it('should handle LOGIN_USER_ERROR by passing clearing loading status, clearing registrationSuccessMessage, passing loginErrorMessage', () => {
const errorMsg = {
error: true,
};
const stateAfter = Object.assign({}, initialState, {
authLoadingStatus: false,
registrationSuccessMessage: {},
loginErrorMessage: errorMsg,
});
expect(authReducer(initialState, {
type: 'LOGIN_USER_ERROR',
loginErrorMessage: errorMsg,
})).toEqual(stateAfter);
});
it('should handle CLEAN_AUTH by clearing authLoadingStatus, registrationSuccessMessage, registrationErrorMessage, loginSuccessMessage, loginErrorMessage, and loginRedirect', () => {
const stateAfter = Object.assign({}, initialState, {
authLoadingStatus: false,
registrationSuccessMessage: {},
registrationErrorMessage: {},
loginSuccessMessage: {},
loginErrorMessage: {},
loginRedirect: false,
});
expect(authReducer(initialState, {
type: 'CLEAN_AUTH',
})).toEqual(stateAfter);
});
});
@@ -1,6 +1,6 @@
import * as actions from '../actions/index';
const initialState = {
export const initialState = {
authLoadingStatus: false,
registrationSuccessMessage: {},
registrationErrorMessage: {},
@@ -45,7 +45,7 @@ export const authReducer = (state = initialState, action) => {
} else if (action.type === actions.LOGIN_USER_ERROR) {
const errorMessage = action.loginErrorMessage;
const modState = Object.assign({}, state, {
authLadingStatus: false,
authLoadingStatus: false,
registrationSuccessMessage: {},
loginErrorMessage: errorMessage,
});
@@ -1,6 +1,6 @@
import * as actions from '../actions/index';
const initialState = {
export const initialState = {
breweryListLoadingStatus: false,
currentCityData: {
brewArr: [],
@@ -1,6 +1,6 @@
import * as actions from '../actions/index';
const initialState = {
export const initialState = {
citiesLoadingStatus: false,
myCities: [],
citiesErrorStatus: false,
View
@@ -332,6 +332,5 @@ const checkoffBrewery = (req, res) => {
router.post('/city', checkoffBrewery);
module.exports = router;
// getBreweries, getCities, getCompletedByCityID, deleteCity, addCity, getCityBrewList, getCityData, mapBreweryToCheckoff, getCheckoffByBreweryAndCity, updateBreweryTotal, checkoffBrewery;
// module.exports = router;
module.exports = { router, getCities, getBreweries, getCompletedByCityID, deleteCity, addCity, getCityBrewList, getCityData, mapBreweryToCheckoff, getCheckoffByBreweryAndCity, updateBreweryTotal, checkoffBrewery };
View
@@ -39,7 +39,7 @@ const apiRoutes = require('./routes/api');
app.use('/api', authCheckMiddleware);
app.use('/auth', authRoutes);
app.use('/api', apiRoutes);
app.use('/api', apiRoutes.router);
// all routes that are not the auth or api will be served the react app
app.use('/*', express.static('./client/build'));

0 comments on commit eb9c8c3

Please sign in to comment.