Commit c0219680 authored by Hannah Stepanek's avatar Hannah Stepanek

Add isLoggedIn to store

parent 0f8827fc
......@@ -40,6 +40,15 @@ function updateSession(session) {
};
}
/**
* Return true if a user is logged in and false otherwise.
*
* @param {object} state - The application state
*/
function isLoggedIn(state) {
return state.session.userid !== null;
}
/**
* Return true if a given feature flag is enabled.
*
......@@ -70,6 +79,7 @@ module.exports = {
selectors: {
isFeatureEnabled,
isLoggedIn,
profile,
},
};
......@@ -16,6 +16,19 @@ describe('sidebar.reducers.session', function() {
});
});
describe('#isLoggedIn', () => {
[
{ userid: 'john', expectedIsLoggedIn: true },
{ userid: null, expectedIsLoggedIn: false },
].forEach(({ userid, expectedIsLoggedIn }) => {
it('returns whether the user is logged in', () => {
const newSession = Object.assign(init(), { userid: userid });
const state = update(init(), actions.updateSession(newSession));
assert.equal(selectors.isLoggedIn(state), expectedIsLoggedIn);
});
});
});
describe('#profile', () => {
it("returns the user's profile", () => {
const newSession = Object.assign(init(), { userid: 'john' });
......
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