Skip to content

Commit

Permalink
add authReducer test
Browse files Browse the repository at this point in the history
  • Loading branch information
bvellek committed Apr 26, 2017
1 parent 6412588 commit eb9c8c3
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 20 deletions.
4 changes: 2 additions & 2 deletions client/build/asset-manifest.json
@@ -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"
}
2 changes: 1 addition & 1 deletion client/build/index.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions client/build/static/js/main.260f5659.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion client/build/static/js/main.675b536a.js.map

This file was deleted.

95 changes: 95 additions & 0 deletions client/src/__test__/authReducer.test.js
@@ -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);
});
});
4 changes: 2 additions & 2 deletions client/src/js/reducers/authReducer.js
@@ -1,6 +1,6 @@
import * as actions from '../actions/index';

const initialState = {
export const initialState = {
authLoadingStatus: false,
registrationSuccessMessage: {},
registrationErrorMessage: {},
Expand Down Expand Up @@ -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,
});
Expand Down
2 changes: 1 addition & 1 deletion client/src/js/reducers/breweryListReducer.js
@@ -1,6 +1,6 @@
import * as actions from '../actions/index';

const initialState = {
export const initialState = {
breweryListLoadingStatus: false,
currentCityData: {
brewArr: [],
Expand Down
2 changes: 1 addition & 1 deletion client/src/js/reducers/citiesReducer.js
@@ -1,6 +1,6 @@
import * as actions from '../actions/index';

const initialState = {
export const initialState = {
citiesLoadingStatus: false,
myCities: [],
citiesErrorStatus: false,
Expand Down
5 changes: 2 additions & 3 deletions routes/api.js
Expand Up @@ -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 };
2 changes: 1 addition & 1 deletion server.js
Expand Up @@ -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'));
Expand Down

0 comments on commit eb9c8c3

Please sign in to comment.