Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Welcome AI #4283

Merged
merged 3 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,11 @@ export default {
featureFlags(state) {
return state.currentUser.feature_flags || {};
},
hasFeatureEnabled(state, getters) {
/**
* @param {string} flag - shared.constants.FeatureFlagKeys.*
* @return {Boolean}
*/
return function(flag) {
return getters.isAdmin || Boolean(getters.featureFlags[flag]);
};
isAIFeatureEnabled(state, getters) {
if (getters.loggedIn) {
return Boolean(getters.featureFlags['ai_feature']);
}
return false;
vkWeb marked this conversation as resolved.
Show resolved Hide resolved
},
},
actions: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import vuexSessionModule from './index.js';

describe('session module feature flag related getters', () => {
describe('featureFlags', () => {
let state, getters;

beforeEach(() => {
state = {
currentUser: {
feature_flags: {
flag1: true,
flag2: false,
},
},
};
getters = {
featureFlags: vuexSessionModule.getters.featureFlags,
};
});
it('should return feature flags from current user', () => {
const result = getters.featureFlags(state);
expect(result).toEqual(state.currentUser.feature_flags);
});

it('should return empty object if no feature flags set', () => {
state.currentUser = {};
const result = getters.featureFlags(state);
expect(result).toEqual({});
});
});

describe('isAIFeatureEnabled', () => {
let state, getters;

beforeEach(() => {
state = {
currentUser: {
feature_flags: {
ai_feature: true,
},
},
};
getters = {
loggedIn: false,
featureFlags: state.currentUser.feature_flags,
isAIFeatureEnabled: vuexSessionModule.getters.isAIFeatureEnabled,
};
});

it('should return false if not logged in', () => {
expect(getters.isAIFeatureEnabled(state, getters)).toBe(false);
});

it('should return true if logged in and ai feature flag is true', () => {
getters.loggedIn = true;
expect(getters.isAIFeatureEnabled(state, getters)).toBe(true);
});

it('should return false if logged in and ai feature flag is false', () => {
getters.loggedIn = true;
state.currentUser.feature_flags.ai_feature = false;
expect(getters.isAIFeatureEnabled(state, getters)).toBe(false);
});
});
});