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 = {
userid: null,
};
function init() {
function init(settings) {
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.
*/
......@@ -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.
*
......@@ -103,6 +119,7 @@ export default storeModule({
},
selectors: {
authDomain,
hasFetchedProfile,
isFeatureEnabled,
isLoggedIn,
......
......@@ -71,7 +71,9 @@ describe('sidebar/store/modules/groups', () => {
let store;
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', () => {
......
import createStore from '../../create-store';
import session from '../session';
describe('sidebar/store/modules/session', function () {
describe('sidebar/store/modules/session', () => {
let fakeSettings;
let store;
beforeEach(() => {
store = createStore([session]);
fakeSettings = {};
store = createStore([session], [fakeSettings]);
});
describe('#updateProfile', function () {
it('updates the profile data', function () {
describe('#updateProfile', () => {
it('updates the profile data', () => {
const newProfile = Object.assign({ userid: 'john' });
store.updateProfile({ userid: 'john' });
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', () => {
[
{ 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