Add SET_HAS_VERIFICATION_BEEN_ATTEMPTED action, reducer and tests

This commit is contained in:
Kyle Corbelli 2017-09-28 11:27:39 -07:00
parent 895bda81aa
commit c204f5e6b8
10 changed files with 61 additions and 5 deletions

13
dist/actions.js vendored
View File

@ -88,6 +88,12 @@ exports.signOutRequestSucceeded = function () { return ({
exports.signOutRequestFailed = function () { return ({ exports.signOutRequestFailed = function () { return ({
type: types_1.SIGNOUT_REQUEST_FAILED, type: types_1.SIGNOUT_REQUEST_FAILED,
}); }; }); };
exports.setHasVerificationBeenAttempted = function (hasVerificationBeenAttempted) { return ({
type: types_1.SET_HAS_VERIFICATION_BEEN_ATTEMPTED,
payload: {
hasVerificationBeenAttempted: hasVerificationBeenAttempted,
},
}); };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Async Redux Thunk actions: // Async Redux Thunk actions:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -263,8 +269,11 @@ var generateAuthActions = function (config) {
verificationParams = (_a.uid = (_c.sent()), verificationParams = (_a.uid = (_c.sent()),
_a); _a);
store.dispatch(verifyToken(verificationParams)); store.dispatch(verifyToken(verificationParams));
_c.label = 5; return [3 /*break*/, 6];
case 5: return [2 /*return*/]; case 5:
store.dispatch(exports.setHasVerificationBeenAttempted(true));
_c.label = 6;
case 6: return [2 /*return*/];
} }
}); });
}); }; }); };

2
dist/actions.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -38,6 +38,8 @@ var currentUser = function (state, action) {
return __assign({}, state, { attributes: allNullUserAttributes, isLoading: false, isSignedIn: false }); return __assign({}, state, { attributes: allNullUserAttributes, isLoading: false, isSignedIn: false });
case types_1.SIGNOUT_REQUEST_FAILED: case types_1.SIGNOUT_REQUEST_FAILED:
return __assign({}, state, { isLoading: false }); return __assign({}, state, { isLoading: false });
case types_1.SET_HAS_VERIFICATION_BEEN_ATTEMPTED:
return __assign({}, state, { hasVerificationBeenAttempted: action.payload.hasVerificationBeenAttempted });
default: default:
return state; return state;
} }

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/reducers/current-user/index.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,qCAgBoB;AACpB,qDAA8C;AAG5C,IAAA,iDAAwB,CACV;AAEhB,IAAM,WAAW,GAAG,UAAC,KAAyB,EAAE,MAAmB;IAA9C,sBAAA,EAAA,mBAAyB;IAC5C,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QACpB,KAAK,iCAAyB,CAAC;QAC/B,KAAK,iCAAyB,CAAC;QAC/B,KAAK,2BAAmB,CAAC;QACzB,KAAK,4BAAoB;YACvB,MAAM,cACD,KAAK,IACR,SAAS,EAAE,IAAI,IAChB;QACH,KAAK,sCAA8B;YACjC,MAAM,cACD,KAAK,IACR,UAAU,eAAO,MAAM,CAAC,OAAO,CAAC,cAAc,GAC9C,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,IAAI,EAChB,4BAA4B,EAAE,IAAI,IACnC;QACH,KAAK,sCAA8B,CAAC;QACpC,KAAK,gCAAwB;YAC3B,MAAM,cACD,KAAK,IACR,UAAU,eAAO,MAAM,CAAC,OAAO,CAAC,cAAc,GAC9C,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,IAAI,IACjB;QACH,KAAK,mCAA2B;YAC9B,MAAM,cACD,KAAK,IACR,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,KAAK,EACjB,4BAA4B,EAAE,IAAI,IACnC;QACH,KAAK,mCAA2B,CAAC;QACjC,KAAK,6BAAqB;YACxB,MAAM,cACD,KAAK,IACR,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,KAAK,IAClB;QACH,KAAK,iCAAyB;YAC5B,IAAM,iBAAiB,GAAa,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;YACjE,IAAM,qBAAqB,GAAmB,iBAAiB,CAAC,MAAM,CACpE,UAAC,6BAA6C,EAAE,uBAA+B;gBAC7E,MAAM,cACD,6BAA6B,eAC/B,uBAAuB,IAAG,IAAI,OAChC;;YACH,CAAC,EACD,EAAE,CACH,CAAA;YACD,MAAM,cACD,KAAK,IACR,UAAU,EAAE,qBAAqB,EACjC,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,KAAK,IAClB;QACH,KAAK,8BAAsB;YACzB,MAAM,cACD,KAAK,IACR,SAAS,EAAE,KAAK,IACjB;QACH;YACE,MAAM,CAAC,KAAK,CAAA;IAChB,CAAC;AACH,CAAC,CAAA;AAED,kBAAe,WAAW,CAAA"} {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/reducers/current-user/index.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,qCAiBoB;AACpB,qDAA8C;AAG5C,IAAA,iDAAwB,CACV;AAEhB,IAAM,WAAW,GAAG,UAAC,KAAyB,EAAE,MAAmB;IAA9C,sBAAA,EAAA,mBAAyB;IAC5C,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QACpB,KAAK,iCAAyB,CAAC;QAC/B,KAAK,iCAAyB,CAAC;QAC/B,KAAK,2BAAmB,CAAC;QACzB,KAAK,4BAAoB;YACvB,MAAM,cACD,KAAK,IACR,SAAS,EAAE,IAAI,IAChB;QACH,KAAK,sCAA8B;YACjC,MAAM,cACD,KAAK,IACR,UAAU,eAAO,MAAM,CAAC,OAAO,CAAC,cAAc,GAC9C,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,IAAI,EAChB,4BAA4B,EAAE,IAAI,IACnC;QACH,KAAK,sCAA8B,CAAC;QACpC,KAAK,gCAAwB;YAC3B,MAAM,cACD,KAAK,IACR,UAAU,eAAO,MAAM,CAAC,OAAO,CAAC,cAAc,GAC9C,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,IAAI,IACjB;QACH,KAAK,mCAA2B;YAC9B,MAAM,cACD,KAAK,IACR,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,KAAK,EACjB,4BAA4B,EAAE,IAAI,IACnC;QACH,KAAK,mCAA2B,CAAC;QACjC,KAAK,6BAAqB;YACxB,MAAM,cACD,KAAK,IACR,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,KAAK,IAClB;QACH,KAAK,iCAAyB;YAC5B,IAAM,iBAAiB,GAAa,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;YACjE,IAAM,qBAAqB,GAAmB,iBAAiB,CAAC,MAAM,CACpE,UAAC,6BAA6C,EAAE,uBAA+B;gBAC7E,MAAM,cACD,6BAA6B,eAC/B,uBAAuB,IAAG,IAAI,OAChC;;YACH,CAAC,EACD,EAAE,CACH,CAAA;YACD,MAAM,cACD,KAAK,IACR,UAAU,EAAE,qBAAqB,EACjC,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,KAAK,IAClB;QACH,KAAK,8BAAsB;YACzB,MAAM,cACD,KAAK,IACR,SAAS,EAAE,KAAK,IACjB;QACH,KAAK,2CAAmC;YACtC,MAAM,cACD,KAAK,IACR,4BAA4B,EAAE,MAAM,CAAC,OAAO,CAAC,4BAA4B,IAC1E;QACH;YACE,MAAM,CAAC,KAAK,CAAA;IAChB,CAAC;AACH,CAAC,CAAA;AAED,kBAAe,WAAW,CAAA"}

1
dist/types.js vendored
View File

@ -12,4 +12,5 @@ exports.SIGNIN_REQUEST_FAILED = 'redux-token-auth/SIGNIN_REQUEST_FAILED';
exports.SIGNOUT_REQUEST_SENT = 'redux-token-auth/SIGNOUT_REQUEST_SENT'; exports.SIGNOUT_REQUEST_SENT = 'redux-token-auth/SIGNOUT_REQUEST_SENT';
exports.SIGNOUT_REQUEST_SUCCEEDED = 'redux-token-auth/SIGNOUT_REQUEST_SUCCEEDED'; exports.SIGNOUT_REQUEST_SUCCEEDED = 'redux-token-auth/SIGNOUT_REQUEST_SUCCEEDED';
exports.SIGNOUT_REQUEST_FAILED = 'redux-token-auth/SIGNOUT_REQUEST_FAILED'; exports.SIGNOUT_REQUEST_FAILED = 'redux-token-auth/SIGNOUT_REQUEST_FAILED';
exports.SET_HAS_VERIFICATION_BEEN_ATTEMPTED = 'redux-token-auth/SET_HAS_VERIFICATION_BEEN_ATTEMPTED';
//# sourceMappingURL=types.js.map //# sourceMappingURL=types.js.map

2
dist/types.js.map vendored
View File

@ -1 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;AA+Ca,QAAA,yBAAyB,GAA8B,4CAA4C,CAAA;AAGnG,QAAA,8BAA8B,GAAmC,iDAAiD,CAAA;AAGlH,QAAA,2BAA2B,GAAgC,8CAA8C,CAAA;AAGzG,QAAA,yBAAyB,GAA8B,4CAA4C,CAAA;AAGnG,QAAA,8BAA8B,GAAmC,iDAAiD,CAAA;AAGlH,QAAA,2BAA2B,GAAgC,8CAA8C,CAAA;AAGzG,QAAA,mBAAmB,GAAwB,sCAAsC,CAAA;AAGjF,QAAA,wBAAwB,GAA6B,2CAA2C,CAAA;AAGhG,QAAA,qBAAqB,GAA0B,wCAAwC,CAAA;AAGvF,QAAA,oBAAoB,GAAyB,uCAAuC,CAAA;AAGpF,QAAA,yBAAyB,GAA8B,4CAA4C,CAAA;AAGnG,QAAA,sBAAsB,GAA2B,yCAAyC,CAAA"} {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;AA+Ca,QAAA,yBAAyB,GAA8B,4CAA4C,CAAA;AAGnG,QAAA,8BAA8B,GAAmC,iDAAiD,CAAA;AAGlH,QAAA,2BAA2B,GAAgC,8CAA8C,CAAA;AAGzG,QAAA,yBAAyB,GAA8B,4CAA4C,CAAA;AAGnG,QAAA,8BAA8B,GAAmC,iDAAiD,CAAA;AAGlH,QAAA,2BAA2B,GAAgC,8CAA8C,CAAA;AAGzG,QAAA,mBAAmB,GAAwB,sCAAsC,CAAA;AAGjF,QAAA,wBAAwB,GAA6B,2CAA2C,CAAA;AAGhG,QAAA,qBAAqB,GAA0B,wCAAwC,CAAA;AAGvF,QAAA,oBAAoB,GAAyB,uCAAuC,CAAA;AAGpF,QAAA,yBAAyB,GAA8B,4CAA4C,CAAA;AAGnG,QAAA,sBAAsB,GAA2B,yCAAyC,CAAA;AAG1F,QAAA,mCAAmC,GAAwC,sDAAsD,CAAA"}

View File

@ -24,6 +24,7 @@ import {
SIGNOUT_REQUEST_SENT, SIGNOUT_REQUEST_SENT,
SIGNOUT_REQUEST_SUCCEEDED, SIGNOUT_REQUEST_SUCCEEDED,
SIGNOUT_REQUEST_FAILED, SIGNOUT_REQUEST_FAILED,
SET_HAS_VERIFICATION_BEEN_ATTEMPTED,
RegistrationRequestSentAction, RegistrationRequestSentAction,
RegistrationRequestSucceededAction, RegistrationRequestSucceededAction,
RegistrationRequestFailedAction, RegistrationRequestFailedAction,
@ -36,6 +37,7 @@ import {
SignOutRequestSentAction, SignOutRequestSentAction,
SignOutRequestSucceededAction, SignOutRequestSucceededAction,
SignOutRequestFailedAction, SignOutRequestFailedAction,
SetHasVerificationBeenAttemptedAction,
} from './types' } from './types'
import AsyncLocalStorage from './AsyncLocalStorage' import AsyncLocalStorage from './AsyncLocalStorage'
import { import {
@ -107,6 +109,15 @@ export const signOutRequestFailed = (): SignOutRequestFailedAction => ({
type: SIGNOUT_REQUEST_FAILED, type: SIGNOUT_REQUEST_FAILED,
}) })
export const setHasVerificationBeenAttempted = (
hasVerificationBeenAttempted: boolean
): SetHasVerificationBeenAttemptedAction => ({
type: SET_HAS_VERIFICATION_BEEN_ATTEMPTED,
payload: {
hasVerificationBeenAttempted,
},
})
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Async Redux Thunk actions: // Async Redux Thunk actions:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -231,6 +242,8 @@ const generateAuthActions = (config: { [key: string]: any }): ActionsExport => {
uid: await Storage.getItem('uid') as string, uid: await Storage.getItem('uid') as string,
} }
store.dispatch<any>(verifyToken(verificationParams)) store.dispatch<any>(verifyToken(verificationParams))
} else {
store.dispatch(setHasVerificationBeenAttempted(true))
} }
} }

View File

@ -14,6 +14,7 @@ import {
SignOutRequestFailedAction, SignOutRequestFailedAction,
User, User,
UserAttributes, UserAttributes,
SetHasVerificationBeenAttemptedAction,
} from '../../types' } from '../../types'
import { import {
registrationRequestSent, registrationRequestSent,
@ -28,6 +29,7 @@ import {
signOutRequestSent, signOutRequestSent,
signOutRequestSucceeded, signOutRequestSucceeded,
signOutRequestFailed, signOutRequestFailed,
setHasVerificationBeenAttempted,
} from '../../actions' } from '../../actions'
describe('currentUser', () => { describe('currentUser', () => {
@ -197,4 +199,16 @@ describe('currentUser', () => {
expect(newState).toEqual(expectedNewState) expect(newState).toEqual(expectedNewState)
}) })
}) })
describe('SET_HAS_VERIFICATION_BEEN_ATTEMPTED', () => {
it('sets hasVerificationBeenAttempted', () => {
const action: SetHasVerificationBeenAttemptedAction = setHasVerificationBeenAttempted(true)
const initialState: User = {
...alreadyLoadingState,
hasVerificationBeenAttempted: false,
}
const newState: User = currentUser(alreadyLoadingState, action)
expect(newState.hasVerificationBeenAttempted).toBe(true)
})
})
}) })

View File

@ -14,6 +14,7 @@ import {
SIGNOUT_REQUEST_SENT, SIGNOUT_REQUEST_SENT,
SIGNOUT_REQUEST_SUCCEEDED, SIGNOUT_REQUEST_SUCCEEDED,
SIGNOUT_REQUEST_FAILED, SIGNOUT_REQUEST_FAILED,
SET_HAS_VERIFICATION_BEEN_ATTEMPTED,
} from '../../types' } from '../../types'
import initialState from '../../initial-state' import initialState from '../../initial-state'
@ -83,6 +84,11 @@ const currentUser = (state: User = initialUser, action: ReduxAction): User => {
...state, ...state,
isLoading: false, isLoading: false,
} }
case SET_HAS_VERIFICATION_BEEN_ATTEMPTED:
return {
...state,
hasVerificationBeenAttempted: action.payload.hasVerificationBeenAttempted,
}
default: default:
return state return state
} }

View File

@ -80,6 +80,9 @@ export const SIGNOUT_REQUEST_SUCCEEDED: SIGNOUT_REQUEST_SUCCEEDED = 'redux-token
export type SIGNOUT_REQUEST_FAILED = 'redux-token-auth/SIGNOUT_REQUEST_FAILED' export type SIGNOUT_REQUEST_FAILED = 'redux-token-auth/SIGNOUT_REQUEST_FAILED'
export const SIGNOUT_REQUEST_FAILED: SIGNOUT_REQUEST_FAILED = 'redux-token-auth/SIGNOUT_REQUEST_FAILED' export const SIGNOUT_REQUEST_FAILED: SIGNOUT_REQUEST_FAILED = 'redux-token-auth/SIGNOUT_REQUEST_FAILED'
export type SET_HAS_VERIFICATION_BEEN_ATTEMPTED = 'redux-token-auth/SET_HAS_VERIFICATION_BEEN_ATTEMPTED'
export const SET_HAS_VERIFICATION_BEEN_ATTEMPTED: SET_HAS_VERIFICATION_BEEN_ATTEMPTED = 'redux-token-auth/SET_HAS_VERIFICATION_BEEN_ATTEMPTED'
export interface UserRegistrationDetails { export interface UserRegistrationDetails {
readonly email: string readonly email: string
readonly password: string readonly password: string
@ -155,6 +158,13 @@ export interface SignOutRequestFailedAction {
readonly type: SIGNOUT_REQUEST_FAILED readonly type: SIGNOUT_REQUEST_FAILED
} }
export interface SetHasVerificationBeenAttemptedAction {
readonly type: SET_HAS_VERIFICATION_BEEN_ATTEMPTED
readonly payload: {
readonly hasVerificationBeenAttempted: boolean
}
}
export type ReduxAction = RegistrationRequestSentAction export type ReduxAction = RegistrationRequestSentAction
| RegistrationRequestSucceededAction | RegistrationRequestSucceededAction
| RegistrationRequestFailedAction | RegistrationRequestFailedAction
@ -167,6 +177,7 @@ export type ReduxAction = RegistrationRequestSentAction
| SignOutRequestSentAction | SignOutRequestSentAction
| SignOutRequestSucceededAction | SignOutRequestSucceededAction
| SignOutRequestFailedAction | SignOutRequestFailedAction
| SetHasVerificationBeenAttemptedAction
export type ReduxAsyncAction = (input?: any) => (dispatch: Dispatch<{}>) => Promise<void> export type ReduxAsyncAction = (input?: any) => (dispatch: Dispatch<{}>) => Promise<void>