Fix logged in selector with test

This commit is contained in:
Paul Kaplan 2021-04-21 14:51:29 -04:00
parent 64fecf28bb
commit c789a27018
2 changed files with 4 additions and 2 deletions

View file

@ -121,7 +121,7 @@ module.exports.refreshSessionWithRetry = () => (dispatch => {
});
// Selectors
module.exports.selectIsLoggedIn = state => get(state, ['session', 'session', 'user'], false);
module.exports.selectIsLoggedIn = state => !!get(state, ['session', 'session', 'user'], false);
module.exports.selectUsername = state => get(state, ['session', 'session', 'user', 'username'], null);
module.exports.selectToken = state => get(state, ['session', 'session', 'user', 'token'], null);
module.exports.selectIsAdmin = state => get(state, ['session', 'session', 'permissions', 'admin'], false);

View file

@ -1,6 +1,6 @@
import {
getInitialState, selectIsAdmin, selectIsSocial, selectUserId,
selectUsername, selectToken, sessionReducer, setSession
selectIsLoggedIn, selectUsername, selectToken, sessionReducer, setSession
} from '../../../src/redux/session';
import {sessions} from '../../helpers/state-fixtures.json';
@ -10,6 +10,7 @@ describe('session selectors', () => {
const state = {session: getInitialState()};
expect(selectIsAdmin(state)).toBe(false);
expect(selectIsSocial(state)).toBe(false);
expect(selectIsLoggedIn(state)).toBe(false);
expect(selectUserId(state)).toBeNaN();
expect(selectToken(state)).toBeNull();
expect(selectUsername(state)).toBeNull();
@ -22,6 +23,7 @@ describe('session selectors', () => {
expect(selectUserId(state)).toBe(1);
expect(selectUsername(state)).toBe('user1-username');
expect(selectToken(state)).toBe('user1-token');
expect(selectIsLoggedIn(state)).toBe(true);
});
describe('permissions', () => {