Commit eadfcfda authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Add `authDomain` to `session` store

parent caec1d11
...@@ -23,8 +23,16 @@ const initialProfile = { ...@@ -23,8 +23,16 @@ const initialProfile = {
userid: null, userid: null,
}; };
function init() { function init(settings) {
return { return {
/**
* The app's authentication domain, from settings
* FIXME: This returns an empty string when `authDomain` is missing
* because other app logic has long assumed its string-y presence:
* behavior when it's missing is undefined. This setting should be
* enforced similarly to how `apiUrl` is enforced.
*/
authDomain: settings?.authDomain ?? '',
/** /**
* Profile object fetched from the `/api/profile` endpoint. * Profile object fetched from the `/api/profile` endpoint.
*/ */
...@@ -52,6 +60,14 @@ function updateProfile(profile) { ...@@ -52,6 +60,14 @@ function updateProfile(profile) {
}; };
} }
/**
*
* @returns {string}
*/
function authDomain(state) {
return state.authDomain;
}
/** /**
* Return true if a user is logged in and false otherwise. * Return true if a user is logged in and false otherwise.
* *
...@@ -103,6 +119,7 @@ export default storeModule({ ...@@ -103,6 +119,7 @@ export default storeModule({
}, },
selectors: { selectors: {
authDomain,
hasFetchedProfile, hasFetchedProfile,
isFeatureEnabled, isFeatureEnabled,
isLoggedIn, isLoggedIn,
......
...@@ -71,7 +71,9 @@ describe('sidebar/store/modules/groups', () => { ...@@ -71,7 +71,9 @@ describe('sidebar/store/modules/groups', () => {
let store; let store;
beforeEach(() => { beforeEach(() => {
store = createStore([groups, session]); // The empty second argument (settings) needed here because of the
// dependency on the `session` module
store = createStore([groups, session], [{}]);
}); });
describe('focusGroup', () => { describe('focusGroup', () => {
......
import createStore from '../../create-store'; import createStore from '../../create-store';
import session from '../session'; import session from '../session';
describe('sidebar/store/modules/session', function () { describe('sidebar/store/modules/session', () => {
let fakeSettings;
let store; let store;
beforeEach(() => { beforeEach(() => {
store = createStore([session]); fakeSettings = {};
store = createStore([session], [fakeSettings]);
}); });
describe('#updateProfile', function () { describe('#updateProfile', () => {
it('updates the profile data', function () { it('updates the profile data', () => {
const newProfile = Object.assign({ userid: 'john' }); const newProfile = Object.assign({ userid: 'john' });
store.updateProfile({ userid: 'john' }); store.updateProfile({ userid: 'john' });
assert.deepEqual(store.profile(), newProfile); assert.deepEqual(store.profile(), newProfile);
}); });
}); });
describe('#authDomain', () => {
it('returns the authDomain from the settings', () => {
fakeSettings.authDomain = 'foo.com';
store = createStore([session], [fakeSettings]);
assert.equal(store.authDomain(), 'foo.com');
});
});
describe('#isLoggedIn', () => { describe('#isLoggedIn', () => {
[ [
{ userid: 'john', expectedIsLoggedIn: true }, { userid: 'john', expectedIsLoggedIn: true },
......
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