Commit 2abba683 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch 'feature-flags-prop-pocalypse' into 'master'

Remove Feature Flags Vuex Modules, Favour Individual Stores

See merge request gitlab-org/gitlab!44638
parents 10a933c7 a0d20757
<script> <script>
import { GlAlert, GlLoadingIcon, GlToggle } from '@gitlab/ui'; import { GlAlert, GlLoadingIcon, GlToggle } from '@gitlab/ui';
import { createNamespacedHelpers } from 'vuex'; import { mapState, mapActions } from 'vuex';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { sprintf, s__ } from '~/locale'; import { sprintf, s__ } from '~/locale';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { LEGACY_FLAG, NEW_FLAG_ALERT } from '../constants'; import { LEGACY_FLAG, NEW_FLAG_ALERT } from '../constants';
import store from '../store/index';
import FeatureFlagForm from './form.vue'; import FeatureFlagForm from './form.vue';
const { mapState, mapActions } = createNamespacedHelpers('edit');
export default { export default {
store,
components: { components: {
GlAlert, GlAlert,
GlLoadingIcon, GlLoadingIcon,
...@@ -20,14 +16,6 @@ export default { ...@@ -20,14 +16,6 @@ export default {
}, },
mixins: [glFeatureFlagMixin()], mixins: [glFeatureFlagMixin()],
props: { props: {
endpoint: {
type: String,
required: true,
},
path: {
type: String,
required: true,
},
environmentsEndpoint: { environmentsEndpoint: {
type: String, type: String,
required: true, required: true,
...@@ -71,6 +59,7 @@ export default { ...@@ -71,6 +59,7 @@ export default {
}, },
computed: { computed: {
...mapState([ ...mapState([
'path',
'error', 'error',
'name', 'name',
'description', 'description',
...@@ -110,17 +99,10 @@ export default { ...@@ -110,17 +99,10 @@ export default {
}, },
}, },
created() { created() {
this.setPath(this.path); return this.fetchFeatureFlag();
return this.setEndpoint(this.endpoint).then(() => this.fetchFeatureFlag());
}, },
methods: { methods: {
...mapActions([ ...mapActions(['updateFeatureFlag', 'fetchFeatureFlag', 'toggleActive']),
'updateFeatureFlag',
'setEndpoint',
'setPath',
'fetchFeatureFlag',
'toggleActive',
]),
dismissNewVersionFlagAlert() { dismissNewVersionFlagAlert() {
this.userShouldSeeNewFlagAlert = false; this.userShouldSeeNewFlagAlert = false;
axios.post(this.userCalloutsPath, { axios.post(this.userCalloutsPath, {
......
<script> <script>
import { createNamespacedHelpers } from 'vuex'; import { mapState, mapActions } from 'vuex';
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
import { GlButton, GlModalDirective, GlTabs } from '@gitlab/ui'; import { GlButton, GlModalDirective, GlTabs } from '@gitlab/ui';
import { FEATURE_FLAG_SCOPE, USER_LIST_SCOPE } from '../constants'; import { FEATURE_FLAG_SCOPE, USER_LIST_SCOPE } from '../constants';
import FeatureFlagsTab from './feature_flags_tab.vue'; import FeatureFlagsTab from './feature_flags_tab.vue';
import FeatureFlagsTable from './feature_flags_table.vue'; import FeatureFlagsTable from './feature_flags_table.vue';
import UserListsTable from './user_lists_table.vue'; import UserListsTable from './user_lists_table.vue';
import store from '../store';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import TablePagination from '~/vue_shared/components/pagination/table_pagination.vue'; import TablePagination from '~/vue_shared/components/pagination/table_pagination.vue';
import { import {
...@@ -17,12 +16,9 @@ import { ...@@ -17,12 +16,9 @@ import {
import ConfigureFeatureFlagsModal from './configure_feature_flags_modal.vue'; import ConfigureFeatureFlagsModal from './configure_feature_flags_modal.vue';
const { mapState, mapActions } = createNamespacedHelpers('index');
const SCOPES = { FEATURE_FLAG_SCOPE, USER_LIST_SCOPE }; const SCOPES = { FEATURE_FLAG_SCOPE, USER_LIST_SCOPE };
export default { export default {
store,
components: { components: {
FeatureFlagsTable, FeatureFlagsTable,
UserListsTable, UserListsTable,
...@@ -36,14 +32,6 @@ export default { ...@@ -36,14 +32,6 @@ export default {
GlModal: GlModalDirective, GlModal: GlModalDirective,
}, },
props: { props: {
endpoint: {
type: String,
required: true,
},
projectId: {
type: String,
required: true,
},
csrfToken: { csrfToken: {
type: String, type: String,
required: true, required: true,
...@@ -56,19 +44,10 @@ export default { ...@@ -56,19 +44,10 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
rotateInstanceIdPath: {
type: String,
required: false,
default: '',
},
unleashApiUrl: { unleashApiUrl: {
type: String, type: String,
required: true, required: true,
}, },
unleashApiInstanceId: {
type: String,
required: true,
},
canUserConfigure: { canUserConfigure: {
type: Boolean, type: Boolean,
required: true, required: true,
...@@ -144,23 +123,15 @@ export default { ...@@ -144,23 +123,15 @@ export default {
}, },
}, },
created() { created() {
this.setFeatureFlagsEndpoint(this.endpoint);
this.setFeatureFlagsOptions({ scope: this.scope, page: this.page }); this.setFeatureFlagsOptions({ scope: this.scope, page: this.page });
this.setProjectId(this.projectId);
this.fetchFeatureFlags(); this.fetchFeatureFlags();
this.fetchUserLists(); this.fetchUserLists();
this.setInstanceId(this.unleashApiInstanceId);
this.setInstanceIdEndpoint(this.rotateInstanceIdPath);
}, },
methods: { methods: {
...mapActions([ ...mapActions([
'setFeatureFlagsEndpoint',
'setFeatureFlagsOptions', 'setFeatureFlagsOptions',
'fetchFeatureFlags', 'fetchFeatureFlags',
'fetchUserLists', 'fetchUserLists',
'setInstanceIdEndpoint',
'setInstanceId',
'setProjectId',
'rotateInstanceId', 'rotateInstanceId',
'toggleFeatureFlag', 'toggleFeatureFlag',
'deleteUserList', 'deleteUserList',
......
...@@ -28,7 +28,7 @@ import { ...@@ -28,7 +28,7 @@ import {
NEW_VERSION_FLAG, NEW_VERSION_FLAG,
LEGACY_FLAG, LEGACY_FLAG,
} from '../constants'; } from '../constants';
import { createNewEnvironmentScope } from '../store/modules/helpers'; import { createNewEnvironmentScope } from '../store/helpers';
export default { export default {
components: { components: {
......
<script> <script>
import { createNamespacedHelpers } from 'vuex'; import { mapState, mapActions } from 'vuex';
import { GlAlert } from '@gitlab/ui'; import { GlAlert } from '@gitlab/ui';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import store from '../store/index';
import FeatureFlagForm from './form.vue'; import FeatureFlagForm from './form.vue';
import { import {
LEGACY_FLAG, LEGACY_FLAG,
...@@ -10,28 +9,17 @@ import { ...@@ -10,28 +9,17 @@ import {
NEW_FLAG_ALERT, NEW_FLAG_ALERT,
ROLLOUT_STRATEGY_ALL_USERS, ROLLOUT_STRATEGY_ALL_USERS,
} from '../constants'; } from '../constants';
import { createNewEnvironmentScope } from '../store/modules/helpers'; import { createNewEnvironmentScope } from '../store/helpers';
import featureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import featureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
const { mapState, mapActions } = createNamespacedHelpers('new');
export default { export default {
store,
components: { components: {
GlAlert, GlAlert,
FeatureFlagForm, FeatureFlagForm,
}, },
mixins: [featureFlagsMixin()], mixins: [featureFlagsMixin()],
props: { props: {
endpoint: {
type: String,
required: true,
},
path: {
type: String,
required: true,
},
environmentsEndpoint: { environmentsEndpoint: {
type: String, type: String,
required: true, required: true,
...@@ -64,7 +52,7 @@ export default { ...@@ -64,7 +52,7 @@ export default {
newFlagAlert: NEW_FLAG_ALERT, newFlagAlert: NEW_FLAG_ALERT,
}, },
computed: { computed: {
...mapState(['error']), ...mapState(['error', 'path']),
scopes() { scopes() {
return [ return [
createNewEnvironmentScope( createNewEnvironmentScope(
...@@ -89,12 +77,8 @@ export default { ...@@ -89,12 +77,8 @@ export default {
return [{ name: ROLLOUT_STRATEGY_ALL_USERS, parameters: {}, scopes: [] }]; return [{ name: ROLLOUT_STRATEGY_ALL_USERS, parameters: {}, scopes: [] }];
}, },
}, },
created() {
this.setEndpoint(this.endpoint);
this.setPath(this.path);
},
methods: { methods: {
...mapActions(['createFeatureFlag', 'setEndpoint', 'setPath']), ...mapActions(['createFeatureFlag']),
dismissNewVersionFlagAlert() { dismissNewVersionFlagAlert() {
this.userShouldSeeNewFlagAlert = false; this.userShouldSeeNewFlagAlert = false;
axios.post(this.userCalloutsPath, { axios.post(this.userCalloutsPath, {
......
import Vue from 'vue'; import Vue from 'vue';
import EditFeatureFlag from '~/feature_flags/components/edit_feature_flag.vue'; import Vuex from 'vuex';
import { parseBoolean } from '~/lib/utils/common_utils'; import { parseBoolean } from '~/lib/utils/common_utils';
import createStore from './store/edit';
import EditFeatureFlag from './components/edit_feature_flag.vue';
Vue.use(Vuex);
export default () => { export default () => {
const el = document.querySelector('#js-edit-feature-flag'); const el = document.querySelector('#js-edit-feature-flag');
const { environmentsScopeDocsPath, strategyTypeDocsPagePath } = el.dataset; const {
environmentsScopeDocsPath,
strategyTypeDocsPagePath,
endpoint,
featureFlagsPath,
} = el.dataset;
return new Vue({ return new Vue({
store: createStore({ endpoint, path: featureFlagsPath }),
el, el,
components: {
EditFeatureFlag,
},
provide: { provide: {
environmentsScopeDocsPath, environmentsScopeDocsPath,
strategyTypeDocsPagePath, strategyTypeDocsPagePath,
}, },
render(createElement) { render(createElement) {
return createElement('edit-feature-flag', { return createElement(EditFeatureFlag, {
props: { props: {
endpoint: el.dataset.endpoint,
path: el.dataset.featureFlagsPath,
environmentsEndpoint: el.dataset.environmentsEndpoint, environmentsEndpoint: el.dataset.environmentsEndpoint,
projectId: el.dataset.projectId, projectId: el.dataset.projectId,
featureFlagIssuesEndpoint: el.dataset.featureFlagIssuesEndpoint, featureFlagIssuesEndpoint: el.dataset.featureFlagIssuesEndpoint,
......
import Vue from 'vue'; import Vue from 'vue';
import FeatureFlagsComponent from '~/feature_flags/components/feature_flags.vue'; import Vuex from 'vuex';
import csrf from '~/lib/utils/csrf'; import csrf from '~/lib/utils/csrf';
import FeatureFlagsComponent from './components/feature_flags.vue';
import createStore from './store/index';
export default () => Vue.use(Vuex);
new Vue({
el: '#feature-flags-vue', export default () => {
components: { const el = document.querySelector('#feature-flags-vue');
FeatureFlagsComponent,
}, const {
data() { projectName,
return { featureFlagsHelpPagePath,
dataset: document.querySelector(this.$options.el).dataset, errorStateSvgPath,
}; endpoint,
}, projectId,
unleashApiInstanceId,
rotateInstanceIdPath,
} = el.dataset;
return new Vue({
el,
store: createStore({ endpoint, projectId, unleashApiInstanceId, rotateInstanceIdPath }),
provide() { provide() {
return { return {
projectName: this.dataset.projectName, projectName,
featureFlagsHelpPagePath: this.dataset.featureFlagsHelpPagePath, featureFlagsHelpPagePath,
errorStateSvgPath: this.dataset.errorStateSvgPath, errorStateSvgPath,
}; };
}, },
render(createElement) { render(createElement) {
return createElement('feature-flags-component', { return createElement(FeatureFlagsComponent, {
props: { props: {
endpoint: this.dataset.endpoint, featureFlagsClientLibrariesHelpPagePath:
projectId: this.dataset.projectId, el.dataset.featureFlagsClientLibrariesHelpPagePath,
featureFlagsClientLibrariesHelpPagePath: this.dataset featureFlagsClientExampleHelpPagePath: el.dataset.featureFlagsClientExampleHelpPagePath,
.featureFlagsClientLibrariesHelpPagePath, unleashApiUrl: el.dataset.unleashApiUrl,
featureFlagsClientExampleHelpPagePath: this.dataset.featureFlagsClientExampleHelpPagePath,
unleashApiUrl: this.dataset.unleashApiUrl,
unleashApiInstanceId: this.dataset.unleashApiInstanceId || '',
csrfToken: csrf.token, csrfToken: csrf.token,
canUserConfigure: this.dataset.canUserAdminFeatureFlag, canUserConfigure: el.dataset.canUserAdminFeatureFlag,
newFeatureFlagPath: this.dataset.newFeatureFlagPath, newFeatureFlagPath: el.dataset.newFeatureFlagPath,
rotateInstanceIdPath: this.dataset.rotateInstanceIdPath, newUserListPath: el.dataset.newUserListPath,
newUserListPath: this.dataset.newUserListPath,
}, },
}); });
}, },
}); });
};
import Vue from 'vue'; import Vue from 'vue';
import NewFeatureFlag from '~/feature_flags/components/new_feature_flag.vue'; import Vuex from 'vuex';
import { parseBoolean } from '~/lib/utils/common_utils'; import { parseBoolean } from '~/lib/utils/common_utils';
import createStore from './store/new';
import NewFeatureFlag from './components/new_feature_flag.vue';
Vue.use(Vuex);
export default () => { export default () => {
const el = document.querySelector('#js-new-feature-flag'); const el = document.querySelector('#js-new-feature-flag');
const { environmentsScopeDocsPath, strategyTypeDocsPagePath } = el.dataset; const {
environmentsScopeDocsPath,
strategyTypeDocsPagePath,
endpoint,
featureFlagsPath,
} = el.dataset;
return new Vue({ return new Vue({
el, el,
components: { store: createStore({ endpoint, path: featureFlagsPath }),
NewFeatureFlag,
},
provide: { provide: {
environmentsScopeDocsPath, environmentsScopeDocsPath,
strategyTypeDocsPagePath, strategyTypeDocsPagePath,
}, },
render(createElement) { render(createElement) {
return createElement('new-feature-flag', { return createElement(NewFeatureFlag, {
props: { props: {
endpoint: el.dataset.endpoint,
path: el.dataset.featureFlagsPath,
environmentsEndpoint: el.dataset.environmentsEndpoint, environmentsEndpoint: el.dataset.environmentsEndpoint,
projectId: el.dataset.projectId, projectId: el.dataset.projectId,
userCalloutsPath: el.dataset.userCalloutsPath, userCalloutsPath: el.dataset.userCalloutsPath,
......
...@@ -3,23 +3,9 @@ import axios from '~/lib/utils/axios_utils'; ...@@ -3,23 +3,9 @@ import axios from '~/lib/utils/axios_utils';
import { visitUrl } from '~/lib/utils/url_utility'; import { visitUrl } from '~/lib/utils/url_utility';
import { deprecatedCreateFlash as createFlash } from '~/flash'; import { deprecatedCreateFlash as createFlash } from '~/flash';
import { __ } from '~/locale'; import { __ } from '~/locale';
import { NEW_VERSION_FLAG } from '../../../constants'; import { NEW_VERSION_FLAG } from '../../constants';
import { mapFromScopesViewModel, mapStrategiesToRails } from '../helpers'; import { mapFromScopesViewModel, mapStrategiesToRails } from '../helpers';
/**
* Commits mutation to set the main endpoint
* @param {String} endpoint
*/
export const setEndpoint = ({ commit }, endpoint) => commit(types.SET_ENDPOINT, endpoint);
/**
* Commits mutation to set the feature flag path.
* Used to redirect the user after form submission
*
* @param {String} path
*/
export const setPath = ({ commit }, path) => commit(types.SET_PATH, path);
/** /**
* Handles the edition of a feature flag. * Handles the edition of a feature flag.
* *
......
import Vuex from 'vuex';
import state from './state'; import state from './state';
import * as actions from './actions'; import * as actions from './actions';
import mutations from './mutations'; import mutations from './mutations';
export default { export default data =>
namespaced: true, new Vuex.Store({
actions, actions,
mutations, mutations,
state: state(), state: state(data),
}; });
export const SET_ENDPOINT = 'SET_ENDPOINT';
export const SET_PATH = 'SET_PATH';
export const REQUEST_UPDATE_FEATURE_FLAG = 'REQUEST_UPDATE_FEATURE_FLAG'; export const REQUEST_UPDATE_FEATURE_FLAG = 'REQUEST_UPDATE_FEATURE_FLAG';
export const RECEIVE_UPDATE_FEATURE_FLAG_SUCCESS = 'RECEIVE_UPDATE_FEATURE_FLAG_SUCCESS'; export const RECEIVE_UPDATE_FEATURE_FLAG_SUCCESS = 'RECEIVE_UPDATE_FEATURE_FLAG_SUCCESS';
export const RECEIVE_UPDATE_FEATURE_FLAG_ERROR = 'RECEIVE_UPDATE_FEATURE_FLAG_ERROR'; export const RECEIVE_UPDATE_FEATURE_FLAG_ERROR = 'RECEIVE_UPDATE_FEATURE_FLAG_ERROR';
......
import * as types from './mutation_types'; import * as types from './mutation_types';
import { mapToScopesViewModel, mapStrategiesToViewModel } from '../helpers'; import { mapToScopesViewModel, mapStrategiesToViewModel } from '../helpers';
import { LEGACY_FLAG } from '../../../constants'; import { LEGACY_FLAG } from '../../constants';
export default { export default {
[types.SET_ENDPOINT](state, endpoint) {
state.endpoint = endpoint;
},
[types.SET_PATH](state, path) {
state.path = path;
},
[types.REQUEST_FEATURE_FLAG](state) { [types.REQUEST_FEATURE_FLAG](state) {
state.isLoading = true; state.isLoading = true;
}, },
......
import { LEGACY_FLAG } from '../../../constants'; import { LEGACY_FLAG } from '../../constants';
export default () => ({ export default ({ path, endpoint }) => ({
endpoint: null, endpoint,
path: null, path,
isSendingRequest: false, isSendingRequest: false,
error: [], error: [],
......
...@@ -10,7 +10,7 @@ import { ...@@ -10,7 +10,7 @@ import {
fetchPercentageParams, fetchPercentageParams,
fetchUserIdParams, fetchUserIdParams,
LEGACY_FLAG, LEGACY_FLAG,
} from '../../constants'; } from '../constants';
/** /**
* Converts raw scope objects fetched from the API into an array of scope * Converts raw scope objects fetched from the API into an array of scope
......
import Vue from 'vue';
import Vuex from 'vuex';
import indexModule from './modules/index';
import newModule from './modules/new';
import editModule from './modules/edit';
Vue.use(Vuex);
export const createStore = () =>
new Vuex.Store({
modules: {
index: indexModule,
new: newModule,
edit: editModule,
},
});
export default createStore();
...@@ -2,19 +2,9 @@ import Api from '~/api'; ...@@ -2,19 +2,9 @@ import Api from '~/api';
import * as types from './mutation_types'; import * as types from './mutation_types';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
export const setFeatureFlagsEndpoint = ({ commit }, endpoint) =>
commit(types.SET_FEATURE_FLAGS_ENDPOINT, endpoint);
export const setFeatureFlagsOptions = ({ commit }, options) => export const setFeatureFlagsOptions = ({ commit }, options) =>
commit(types.SET_FEATURE_FLAGS_OPTIONS, options); commit(types.SET_FEATURE_FLAGS_OPTIONS, options);
export const setInstanceIdEndpoint = ({ commit }, endpoint) =>
commit(types.SET_INSTANCE_ID_ENDPOINT, endpoint);
export const setProjectId = ({ commit }, endpoint) => commit(types.SET_PROJECT_ID, endpoint);
export const setInstanceId = ({ commit }, instanceId) => commit(types.SET_INSTANCE_ID, instanceId);
export const fetchFeatureFlags = ({ state, dispatch }) => { export const fetchFeatureFlags = ({ state, dispatch }) => {
dispatch('requestFeatureFlags'); dispatch('requestFeatureFlags');
......
import Vuex from 'vuex';
import state from './state'; import state from './state';
import * as actions from './actions'; import * as actions from './actions';
import mutations from './mutations'; import mutations from './mutations';
export default { export default data =>
namespaced: true, new Vuex.Store({
actions, actions,
mutations, mutations,
state: state(), state: state(data),
}; });
export const SET_FEATURE_FLAGS_ENDPOINT = 'SET_FEATURE_FLAGS_ENDPOINT';
export const SET_FEATURE_FLAGS_OPTIONS = 'SET_FEATURE_FLAGS_OPTIONS'; export const SET_FEATURE_FLAGS_OPTIONS = 'SET_FEATURE_FLAGS_OPTIONS';
export const SET_INSTANCE_ID_ENDPOINT = 'SET_INSTANCE_ID_ENDPOINT';
export const SET_INSTANCE_ID = 'SET_INSTANCE_ID';
export const SET_PROJECT_ID = 'SET_PROJECT_ID';
export const REQUEST_FEATURE_FLAGS = 'REQUEST_FEATURE_FLAGS'; export const REQUEST_FEATURE_FLAGS = 'REQUEST_FEATURE_FLAGS';
export const RECEIVE_FEATURE_FLAGS_SUCCESS = 'RECEIVE_FEATURE_FLAGS_SUCCESS'; export const RECEIVE_FEATURE_FLAGS_SUCCESS = 'RECEIVE_FEATURE_FLAGS_SUCCESS';
......
import Vue from 'vue'; import Vue from 'vue';
import * as types from './mutation_types'; import * as types from './mutation_types';
import { parseIntPagination, normalizeHeaders } from '~/lib/utils/common_utils'; import { parseIntPagination, normalizeHeaders } from '~/lib/utils/common_utils';
import { FEATURE_FLAG_SCOPE, USER_LIST_SCOPE } from '../../../constants'; import { FEATURE_FLAG_SCOPE, USER_LIST_SCOPE } from '../../constants';
import { mapToScopesViewModel } from '../helpers'; import { mapToScopesViewModel } from '../helpers';
const mapFlag = flag => ({ ...flag, scopes: mapToScopesViewModel(flag.scopes || []) }); const mapFlag = flag => ({ ...flag, scopes: mapToScopesViewModel(flag.scopes || []) });
...@@ -23,21 +23,9 @@ const createPaginationInfo = (state, headers) => { ...@@ -23,21 +23,9 @@ const createPaginationInfo = (state, headers) => {
}; };
export default { export default {
[types.SET_FEATURE_FLAGS_ENDPOINT](state, endpoint) {
state.endpoint = endpoint;
},
[types.SET_FEATURE_FLAGS_OPTIONS](state, options = {}) { [types.SET_FEATURE_FLAGS_OPTIONS](state, options = {}) {
state.options = options; state.options = options;
}, },
[types.SET_INSTANCE_ID_ENDPOINT](state, endpoint) {
state.rotateEndpoint = endpoint;
},
[types.SET_INSTANCE_ID](state, instance) {
state.instanceId = instance;
},
[types.SET_PROJECT_ID](state, project) {
state.projectId = project;
},
[types.REQUEST_FEATURE_FLAGS](state) { [types.REQUEST_FEATURE_FLAGS](state) {
state.isLoading = true; state.isLoading = true;
}, },
......
import { FEATURE_FLAG_SCOPE, USER_LIST_SCOPE } from '../../../constants'; import { FEATURE_FLAG_SCOPE, USER_LIST_SCOPE } from '../../constants';
export default () => ({ export default ({ endpoint, projectId, unleashApiInstanceId, rotateInstanceIdPath }) => ({
[FEATURE_FLAG_SCOPE]: [], [FEATURE_FLAG_SCOPE]: [],
[USER_LIST_SCOPE]: [], [USER_LIST_SCOPE]: [],
alerts: [], alerts: [],
...@@ -8,11 +8,11 @@ export default () => ({ ...@@ -8,11 +8,11 @@ export default () => ({
pageInfo: { [FEATURE_FLAG_SCOPE]: {}, [USER_LIST_SCOPE]: {} }, pageInfo: { [FEATURE_FLAG_SCOPE]: {}, [USER_LIST_SCOPE]: {} },
isLoading: true, isLoading: true,
hasError: false, hasError: false,
endpoint: null, endpoint,
rotateEndpoint: null, rotateEndpoint: rotateInstanceIdPath,
instanceId: '', instanceId: unleashApiInstanceId,
isRotating: false, isRotating: false,
hasRotateError: false, hasRotateError: false,
options: {}, options: {},
projectId: '', projectId,
}); });
import * as types from './mutation_types'; import * as types from './mutation_types';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { visitUrl } from '~/lib/utils/url_utility'; import { visitUrl } from '~/lib/utils/url_utility';
import { NEW_VERSION_FLAG } from '../../../constants'; import { NEW_VERSION_FLAG } from '../../constants';
import { mapFromScopesViewModel, mapStrategiesToRails } from '../helpers'; import { mapFromScopesViewModel, mapStrategiesToRails } from '../helpers';
/**
* Commits mutation to set the main endpoint
* @param {String} endpoint
*/
export const setEndpoint = ({ commit }, endpoint) => commit(types.SET_ENDPOINT, endpoint);
/**
* Commits mutation to set the feature flag path.
* Used to redirect the user after form submission
*
* @param {String} path
*/
export const setPath = ({ commit }, path) => commit(types.SET_PATH, path);
/** /**
* Handles the creation of a new feature flag. * Handles the creation of a new feature flag.
* *
......
import Vuex from 'vuex';
import state from './state'; import state from './state';
import * as actions from './actions'; import * as actions from './actions';
import mutations from './mutations'; import mutations from './mutations';
export default { export default data =>
namespaced: true, new Vuex.Store({
actions, actions,
mutations, mutations,
state: state(), state: state(data),
}; });
export const SET_ENDPOINT = 'SET_ENDPOINT';
export const SET_PATH = 'SET_PATH';
export const REQUEST_CREATE_FEATURE_FLAG = 'REQUEST_CREATE_FEATURE_FLAG'; export const REQUEST_CREATE_FEATURE_FLAG = 'REQUEST_CREATE_FEATURE_FLAG';
export const RECEIVE_CREATE_FEATURE_FLAG_SUCCESS = 'RECEIVE_CREATE_FEATURE_FLAG_SUCCESS'; export const RECEIVE_CREATE_FEATURE_FLAG_SUCCESS = 'RECEIVE_CREATE_FEATURE_FLAG_SUCCESS';
export const RECEIVE_CREATE_FEATURE_FLAG_ERROR = 'RECEIVE_CREATE_FEATURE_FLAG_ERROR'; export const RECEIVE_CREATE_FEATURE_FLAG_ERROR = 'RECEIVE_CREATE_FEATURE_FLAG_ERROR';
import * as types from './mutation_types'; import * as types from './mutation_types';
export default { export default {
[types.SET_ENDPOINT](state, endpoint) {
state.endpoint = endpoint;
},
[types.SET_PATH](state, path) {
state.path = path;
},
[types.REQUEST_CREATE_FEATURE_FLAG](state) { [types.REQUEST_CREATE_FEATURE_FLAG](state) {
state.isSendingRequest = true; state.isSendingRequest = true;
state.error = []; state.error = [];
......
export default () => ({ export default ({ endpoint, path }) => ({
endpoint: null, endpoint,
path: null, path,
isSendingRequest: false, isSendingRequest: false,
error: [], error: [],
}); });
import initEditFeatureFlags from '~/feature_flags/edit'; import initEditFeatureFlags from '~/feature_flags/edit';
document.addEventListener('DOMContentLoaded', initEditFeatureFlags); initEditFeatureFlags();
import initFeatureFlags from '~/feature_flags'; import initFeatureFlags from '~/feature_flags';
document.addEventListener('DOMContentLoaded', initFeatureFlags); initFeatureFlags();
import initNewFeatureFlags from '~/feature_flags/new'; import initNewFeatureFlags from '~/feature_flags/new';
document.addEventListener('DOMContentLoaded', initNewFeatureFlags); initNewFeatureFlags();
...@@ -6,7 +6,7 @@ import { TEST_HOST } from 'spec/test_constants'; ...@@ -6,7 +6,7 @@ import { TEST_HOST } from 'spec/test_constants';
import { mockTracking } from 'helpers/tracking_helper'; import { mockTracking } from 'helpers/tracking_helper';
import { LEGACY_FLAG, NEW_VERSION_FLAG, NEW_FLAG_ALERT } from '~/feature_flags/constants'; import { LEGACY_FLAG, NEW_VERSION_FLAG, NEW_FLAG_ALERT } from '~/feature_flags/constants';
import Form from '~/feature_flags/components/form.vue'; import Form from '~/feature_flags/components/form.vue';
import editModule from '~/feature_flags/store/modules/edit'; import createStore from '~/feature_flags/store/edit';
import EditFeatureFlag from '~/feature_flags/components/edit_feature_flag.vue'; import EditFeatureFlag from '~/feature_flags/components/edit_feature_flag.vue';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
...@@ -20,10 +20,9 @@ describe('Edit feature flag form', () => { ...@@ -20,10 +20,9 @@ describe('Edit feature flag form', () => {
let wrapper; let wrapper;
let mock; let mock;
const store = new Vuex.Store({ const store = createStore({
modules: { path: '/feature_flags',
edit: editModule, endpoint: `${TEST_HOST}/feature_flags.json`,
},
}); });
const factory = (opts = {}) => { const factory = (opts = {}) => {
...@@ -34,8 +33,6 @@ describe('Edit feature flag form', () => { ...@@ -34,8 +33,6 @@ describe('Edit feature flag form', () => {
wrapper = shallowMount(EditFeatureFlag, { wrapper = shallowMount(EditFeatureFlag, {
localVue, localVue,
propsData: { propsData: {
endpoint: `${TEST_HOST}/feature_flags.json`,
path: '/feature_flags',
environmentsEndpoint: 'environments.json', environmentsEndpoint: 'environments.json',
projectId: '8', projectId: '8',
featureFlagIssuesEndpoint: `${TEST_HOST}/feature_flags/5/issues`, featureFlagIssuesEndpoint: `${TEST_HOST}/feature_flags/5/issues`,
...@@ -105,7 +102,7 @@ describe('Edit feature flag form', () => { ...@@ -105,7 +102,7 @@ describe('Edit feature flag form', () => {
describe('with error', () => { describe('with error', () => {
it('should render the error', () => { it('should render the error', () => {
store.dispatch('edit/receiveUpdateFeatureFlagError', { message: ['The name is required'] }); store.dispatch('receiveUpdateFeatureFlagError', { message: ['The name is required'] });
return wrapper.vm.$nextTick(() => { return wrapper.vm.$nextTick(() => {
expect(wrapper.find('.alert-danger').exists()).toEqual(true); expect(wrapper.find('.alert-danger').exists()).toEqual(true);
expect(wrapper.find('.alert-danger').text()).toContain('The name is required'); expect(wrapper.find('.alert-danger').text()).toContain('The name is required');
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import { GlEmptyState, GlLoadingIcon } from '@gitlab/ui'; import { GlEmptyState, GlLoadingIcon } from '@gitlab/ui';
import { TEST_HOST } from 'spec/test_constants'; import { TEST_HOST } from 'spec/test_constants';
import Api from '~/api'; import Api from '~/api';
import { createStore } from '~/feature_flags/store'; import createStore from '~/feature_flags/store/index';
import FeatureFlagsTab from '~/feature_flags/components/feature_flags_tab.vue'; import FeatureFlagsTab from '~/feature_flags/components/feature_flags_tab.vue';
import FeatureFlagsComponent from '~/feature_flags/components/feature_flags.vue'; import FeatureFlagsComponent from '~/feature_flags/components/feature_flags.vue';
import FeatureFlagsTable from '~/feature_flags/components/feature_flags_table.vue'; import FeatureFlagsTable from '~/feature_flags/components/feature_flags_table.vue';
...@@ -14,19 +15,25 @@ import TablePagination from '~/vue_shared/components/pagination/table_pagination ...@@ -14,19 +15,25 @@ import TablePagination from '~/vue_shared/components/pagination/table_pagination
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { getRequestData, userList } from '../mock_data'; import { getRequestData, userList } from '../mock_data';
const localVue = createLocalVue();
localVue.use(Vuex);
describe('Feature flags', () => { describe('Feature flags', () => {
const mockData = { const mockData = {
endpoint: `${TEST_HOST}/endpoint.json`,
csrfToken: 'testToken', csrfToken: 'testToken',
featureFlagsClientLibrariesHelpPagePath: '/help/feature-flags#unleash-clients', featureFlagsClientLibrariesHelpPagePath: '/help/feature-flags#unleash-clients',
featureFlagsClientExampleHelpPagePath: '/help/feature-flags#client-example', featureFlagsClientExampleHelpPagePath: '/help/feature-flags#client-example',
unleashApiUrl: `${TEST_HOST}/api/unleash`, unleashApiUrl: `${TEST_HOST}/api/unleash`,
unleashApiInstanceId: 'oP6sCNRqtRHmpy1gw2-F',
canUserConfigure: true, canUserConfigure: true,
canUserRotateToken: true, canUserRotateToken: true,
newFeatureFlagPath: 'feature-flags/new', newFeatureFlagPath: 'feature-flags/new',
newUserListPath: '/user-list/new', newUserListPath: '/user-list/new',
};
const mockState = {
endpoint: `${TEST_HOST}/endpoint.json`,
projectId: '8', projectId: '8',
unleashApiInstanceId: 'oP6sCNRqtRHmpy1gw2-F',
}; };
let wrapper; let wrapper;
...@@ -34,8 +41,9 @@ describe('Feature flags', () => { ...@@ -34,8 +41,9 @@ describe('Feature flags', () => {
let store; let store;
const factory = (propsData = mockData, fn = shallowMount) => { const factory = (propsData = mockData, fn = shallowMount) => {
store = createStore(); store = createStore(mockState);
wrapper = fn(FeatureFlagsComponent, { wrapper = fn(FeatureFlagsComponent, {
localVue,
store, store,
propsData, propsData,
provide: { provide: {
...@@ -76,7 +84,6 @@ describe('Feature flags', () => { ...@@ -76,7 +84,6 @@ describe('Feature flags', () => {
describe('without permissions', () => { describe('without permissions', () => {
const propsData = { const propsData = {
endpoint: `${TEST_HOST}/endpoint.json`,
csrfToken: 'testToken', csrfToken: 'testToken',
errorStateSvgPath: '/assets/illustrations/feature_flag.svg', errorStateSvgPath: '/assets/illustrations/feature_flag.svg',
featureFlagsHelpPagePath: '/help/feature-flags', featureFlagsHelpPagePath: '/help/feature-flags',
...@@ -85,8 +92,6 @@ describe('Feature flags', () => { ...@@ -85,8 +92,6 @@ describe('Feature flags', () => {
featureFlagsClientLibrariesHelpPagePath: '/help/feature-flags#unleash-clients', featureFlagsClientLibrariesHelpPagePath: '/help/feature-flags#unleash-clients',
featureFlagsClientExampleHelpPagePath: '/help/feature-flags#client-example', featureFlagsClientExampleHelpPagePath: '/help/feature-flags#client-example',
unleashApiUrl: `${TEST_HOST}/api/unleash`, unleashApiUrl: `${TEST_HOST}/api/unleash`,
unleashApiInstanceId: 'oP6sCNRqtRHmpy1gw2-F',
projectId: '8',
}; };
beforeEach(done => { beforeEach(done => {
...@@ -134,7 +139,7 @@ describe('Feature flags', () => { ...@@ -134,7 +139,7 @@ describe('Feature flags', () => {
let emptyState; let emptyState;
beforeEach(async () => { beforeEach(async () => {
mock.onGet(mockData.endpoint, { params: { scope: FEATURE_FLAG_SCOPE, page: '1' } }).reply( mock.onGet(mockState.endpoint, { params: { scope: FEATURE_FLAG_SCOPE, page: '1' } }).reply(
200, 200,
{ {
feature_flags: [], feature_flags: [],
...@@ -154,8 +159,6 @@ describe('Feature flags', () => { ...@@ -154,8 +159,6 @@ describe('Feature flags', () => {
}); });
it('should render the empty state', async () => { it('should render the empty state', async () => {
await axios.waitForAll();
emptyState = wrapper.find(GlEmptyState);
expect(emptyState.exists()).toBe(true); expect(emptyState.exists()).toBe(true);
}); });
...@@ -182,7 +185,7 @@ describe('Feature flags', () => { ...@@ -182,7 +185,7 @@ describe('Feature flags', () => {
describe('with paginated feature flags', () => { describe('with paginated feature flags', () => {
beforeEach(done => { beforeEach(done => {
mock mock
.onGet(mockData.endpoint, { params: { scope: FEATURE_FLAG_SCOPE, page: '1' } }) .onGet(mockState.endpoint, { params: { scope: FEATURE_FLAG_SCOPE, page: '1' } })
.replyOnce(200, getRequestData, { .replyOnce(200, getRequestData, {
'x-next-page': '2', 'x-next-page': '2',
'x-page': '1', 'x-page': '1',
...@@ -218,7 +221,7 @@ describe('Feature flags', () => { ...@@ -218,7 +221,7 @@ describe('Feature flags', () => {
const [flag] = table.props(FEATURE_FLAG_SCOPE); const [flag] = table.props(FEATURE_FLAG_SCOPE);
table.vm.$emit('toggle-flag', flag); table.vm.$emit('toggle-flag', flag);
expect(store.dispatch).toHaveBeenCalledWith('index/toggleFeatureFlag', flag); expect(store.dispatch).toHaveBeenCalledWith('toggleFeatureFlag', flag);
}); });
it('renders configure button', () => { it('renders configure button', () => {
...@@ -287,7 +290,7 @@ describe('Feature flags', () => { ...@@ -287,7 +290,7 @@ describe('Feature flags', () => {
describe('unsuccessful request', () => { describe('unsuccessful request', () => {
beforeEach(done => { beforeEach(done => {
mock mock
.onGet(mockData.endpoint, { params: { scope: FEATURE_FLAG_SCOPE, page: '1' } }) .onGet(mockState.endpoint, { params: { scope: FEATURE_FLAG_SCOPE, page: '1' } })
.replyOnce(500, {}); .replyOnce(500, {});
Api.fetchFeatureFlagUserLists.mockRejectedValueOnce(); Api.fetchFeatureFlagUserLists.mockRejectedValueOnce();
......
import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex'; import Vuex from 'vuex';
import { shallowMount } from '@vue/test-utils';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import { GlAlert } from '@gitlab/ui'; import { GlAlert } from '@gitlab/ui';
import { TEST_HOST } from 'spec/test_constants'; import { TEST_HOST } from 'spec/test_constants';
import Form from '~/feature_flags/components/form.vue'; import Form from '~/feature_flags/components/form.vue';
import newModule from '~/feature_flags/store/modules/new'; import createStore from '~/feature_flags/store/new';
import NewFeatureFlag from '~/feature_flags/components/new_feature_flag.vue'; import NewFeatureFlag from '~/feature_flags/components/new_feature_flag.vue';
import { import {
ROLLOUT_STRATEGY_ALL_USERS, ROLLOUT_STRATEGY_ALL_USERS,
...@@ -17,13 +17,15 @@ import { allUsersStrategy } from '../mock_data'; ...@@ -17,13 +17,15 @@ import { allUsersStrategy } from '../mock_data';
const userCalloutId = 'feature_flags_new_version'; const userCalloutId = 'feature_flags_new_version';
const userCalloutsPath = `${TEST_HOST}/user_callouts`; const userCalloutsPath = `${TEST_HOST}/user_callouts`;
const localVue = createLocalVue();
localVue.use(Vuex);
describe('New feature flag form', () => { describe('New feature flag form', () => {
let wrapper; let wrapper;
const store = new Vuex.Store({ const store = createStore({
modules: { endpoint: `${TEST_HOST}/feature_flags.json`,
new: newModule, path: '/feature_flags',
},
}); });
const factory = (opts = {}) => { const factory = (opts = {}) => {
...@@ -32,9 +34,8 @@ describe('New feature flag form', () => { ...@@ -32,9 +34,8 @@ describe('New feature flag form', () => {
wrapper = null; wrapper = null;
} }
wrapper = shallowMount(NewFeatureFlag, { wrapper = shallowMount(NewFeatureFlag, {
localVue,
propsData: { propsData: {
endpoint: `${TEST_HOST}/feature_flags.json`,
path: '/feature_flags',
environmentsEndpoint: 'environments.json', environmentsEndpoint: 'environments.json',
projectId: '8', projectId: '8',
showUserCallout: true, showUserCallout: true,
...@@ -63,7 +64,7 @@ describe('New feature flag form', () => { ...@@ -63,7 +64,7 @@ describe('New feature flag form', () => {
describe('with error', () => { describe('with error', () => {
it('should render the error', () => { it('should render the error', () => {
store.dispatch('new/receiveCreateFeatureFlagError', { message: ['The name is required'] }); store.dispatch('receiveCreateFeatureFlagError', { message: ['The name is required'] });
return wrapper.vm.$nextTick(() => { return wrapper.vm.$nextTick(() => {
expect(wrapper.find('.alert').exists()).toEqual(true); expect(wrapper.find('.alert').exists()).toEqual(true);
expect(wrapper.find('.alert').text()).toContain('The name is required'); expect(wrapper.find('.alert').text()).toContain('The name is required');
......
...@@ -2,8 +2,6 @@ import MockAdapter from 'axios-mock-adapter'; ...@@ -2,8 +2,6 @@ import MockAdapter from 'axios-mock-adapter';
import testAction from 'helpers/vuex_action_helper'; import testAction from 'helpers/vuex_action_helper';
import { TEST_HOST } from 'spec/test_constants'; import { TEST_HOST } from 'spec/test_constants';
import { import {
setEndpoint,
setPath,
updateFeatureFlag, updateFeatureFlag,
requestUpdateFeatureFlag, requestUpdateFeatureFlag,
receiveUpdateFeatureFlagSuccess, receiveUpdateFeatureFlagSuccess,
...@@ -13,18 +11,15 @@ import { ...@@ -13,18 +11,15 @@ import {
receiveFeatureFlagSuccess, receiveFeatureFlagSuccess,
receiveFeatureFlagError, receiveFeatureFlagError,
toggleActive, toggleActive,
} from '~/feature_flags/store/modules/edit/actions'; } from '~/feature_flags/store/edit/actions';
import state from '~/feature_flags/store/modules/edit/state'; import state from '~/feature_flags/store/edit/state';
import { import { mapStrategiesToRails, mapFromScopesViewModel } from '~/feature_flags/store/helpers';
mapStrategiesToRails,
mapFromScopesViewModel,
} from '~/feature_flags/store/modules/helpers';
import { import {
NEW_VERSION_FLAG, NEW_VERSION_FLAG,
LEGACY_FLAG, LEGACY_FLAG,
ROLLOUT_STRATEGY_ALL_USERS, ROLLOUT_STRATEGY_ALL_USERS,
} from '~/feature_flags/constants'; } from '~/feature_flags/constants';
import * as types from '~/feature_flags/store/modules/edit/mutation_types'; import * as types from '~/feature_flags/store/edit/mutation_types';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
jest.mock('~/lib/utils/url_utility'); jest.mock('~/lib/utils/url_utility');
...@@ -33,33 +28,7 @@ describe('Feature flags Edit Module actions', () => { ...@@ -33,33 +28,7 @@ describe('Feature flags Edit Module actions', () => {
let mockedState; let mockedState;
beforeEach(() => { beforeEach(() => {
mockedState = state(); mockedState = state({ endpoint: 'feature_flags.json', path: '/feature_flags' });
});
describe('setEndpoint', () => {
it('should commit SET_ENDPOINT mutation', done => {
testAction(
setEndpoint,
'feature_flags.json',
mockedState,
[{ type: types.SET_ENDPOINT, payload: 'feature_flags.json' }],
[],
done,
);
});
});
describe('setPath', () => {
it('should commit SET_PATH mutation', done => {
testAction(
setPath,
'/feature_flags',
mockedState,
[{ type: types.SET_PATH, payload: '/feature_flags' }],
[],
done,
);
});
}); });
describe('updateFeatureFlag', () => { describe('updateFeatureFlag', () => {
......
import state from '~/feature_flags/store/modules/edit/state'; import state from '~/feature_flags/store/edit/state';
import mutations from '~/feature_flags/store/modules/edit/mutations'; import mutations from '~/feature_flags/store/edit/mutations';
import * as types from '~/feature_flags/store/modules/edit/mutation_types'; import * as types from '~/feature_flags/store/edit/mutation_types';
describe('Feature flags Edit Module Mutations', () => { describe('Feature flags Edit Module Mutations', () => {
let stateCopy; let stateCopy;
beforeEach(() => { beforeEach(() => {
stateCopy = state(); stateCopy = state({ endpoint: 'feature_flags.json', path: '/feature_flags' });
});
describe('SET_ENDPOINT', () => {
it('should set endpoint', () => {
mutations[types.SET_ENDPOINT](stateCopy, 'feature_flags.json');
expect(stateCopy.endpoint).toEqual('feature_flags.json');
});
});
describe('SET_PATH', () => {
it('should set provided options', () => {
mutations[types.SET_PATH](stateCopy, 'feature_flags');
expect(stateCopy.path).toEqual('feature_flags');
});
}); });
describe('REQUEST_FEATURE_FLAG', () => { describe('REQUEST_FEATURE_FLAG', () => {
......
...@@ -5,7 +5,7 @@ import { ...@@ -5,7 +5,7 @@ import {
createNewEnvironmentScope, createNewEnvironmentScope,
mapStrategiesToViewModel, mapStrategiesToViewModel,
mapStrategiesToRails, mapStrategiesToRails,
} from '~/feature_flags/store/modules/helpers'; } from '~/feature_flags/store/helpers';
import { import {
ROLLOUT_STRATEGY_ALL_USERS, ROLLOUT_STRATEGY_ALL_USERS,
ROLLOUT_STRATEGY_PERCENT_ROLLOUT, ROLLOUT_STRATEGY_PERCENT_ROLLOUT,
......
...@@ -7,10 +7,7 @@ import { ...@@ -7,10 +7,7 @@ import {
receiveFeatureFlagsSuccess, receiveFeatureFlagsSuccess,
receiveFeatureFlagsError, receiveFeatureFlagsError,
fetchFeatureFlags, fetchFeatureFlags,
setFeatureFlagsEndpoint,
setFeatureFlagsOptions, setFeatureFlagsOptions,
setInstanceIdEndpoint,
setInstanceId,
rotateInstanceId, rotateInstanceId,
requestRotateInstanceId, requestRotateInstanceId,
receiveRotateInstanceIdSuccess, receiveRotateInstanceIdSuccess,
...@@ -26,10 +23,10 @@ import { ...@@ -26,10 +23,10 @@ import {
deleteUserList, deleteUserList,
receiveDeleteUserListError, receiveDeleteUserListError,
clearAlert, clearAlert,
} from '~/feature_flags/store/modules/index/actions'; } from '~/feature_flags/store/index/actions';
import { mapToScopesViewModel } from '~/feature_flags/store/modules/helpers'; import { mapToScopesViewModel } from '~/feature_flags/store/helpers';
import state from '~/feature_flags/store/modules/index/state'; import state from '~/feature_flags/store/index/state';
import * as types from '~/feature_flags/store/modules/index/mutation_types'; import * as types from '~/feature_flags/store/index/mutation_types';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { getRequestData, rotateData, featureFlag, userList } from '../../mock_data'; import { getRequestData, rotateData, featureFlag, userList } from '../../mock_data';
...@@ -39,20 +36,7 @@ describe('Feature flags actions', () => { ...@@ -39,20 +36,7 @@ describe('Feature flags actions', () => {
let mockedState; let mockedState;
beforeEach(() => { beforeEach(() => {
mockedState = state(); mockedState = state({});
});
describe('setFeatureFlagsEndpoint', () => {
it('should commit SET_FEATURE_FLAGS_ENDPOINT mutation', done => {
testAction(
setFeatureFlagsEndpoint,
'feature_flags.json',
mockedState,
[{ type: types.SET_FEATURE_FLAGS_ENDPOINT, payload: 'feature_flags.json' }],
[],
done,
);
});
}); });
describe('setFeatureFlagsOptions', () => { describe('setFeatureFlagsOptions', () => {
...@@ -68,32 +52,6 @@ describe('Feature flags actions', () => { ...@@ -68,32 +52,6 @@ describe('Feature flags actions', () => {
}); });
}); });
describe('setInstanceIdEndpoint', () => {
it('should commit SET_INSTANCE_ID_ENDPOINT mutation', done => {
testAction(
setInstanceIdEndpoint,
'instance_id.json',
mockedState,
[{ type: types.SET_INSTANCE_ID_ENDPOINT, payload: 'instance_id.json' }],
[],
done,
);
});
});
describe('setInstanceId', () => {
it('should commit SET_INSTANCE_ID mutation', done => {
testAction(
setInstanceId,
'test_instance_id',
mockedState,
[{ type: types.SET_INSTANCE_ID, payload: 'test_instance_id' }],
[],
done,
);
});
});
describe('fetchFeatureFlags', () => { describe('fetchFeatureFlags', () => {
let mock; let mock;
......
import state from '~/feature_flags/store/modules/index/state'; import state from '~/feature_flags/store/index/state';
import mutations from '~/feature_flags/store/modules/index/mutations'; import mutations from '~/feature_flags/store/index/mutations';
import * as types from '~/feature_flags/store/modules/index/mutation_types'; import * as types from '~/feature_flags/store/index/mutation_types';
import { mapToScopesViewModel } from '~/feature_flags/store/modules/helpers'; import { mapToScopesViewModel } from '~/feature_flags/store/helpers';
import { parseIntPagination, normalizeHeaders } from '~/lib/utils/common_utils'; import { parseIntPagination, normalizeHeaders } from '~/lib/utils/common_utils';
import { getRequestData, rotateData, featureFlag, userList } from '../../mock_data'; import { getRequestData, rotateData, featureFlag, userList } from '../../mock_data';
...@@ -9,15 +9,7 @@ describe('Feature flags store Mutations', () => { ...@@ -9,15 +9,7 @@ describe('Feature flags store Mutations', () => {
let stateCopy; let stateCopy;
beforeEach(() => { beforeEach(() => {
stateCopy = state(); stateCopy = state({});
});
describe('SET_FEATURE_FLAGS_ENDPOINT', () => {
it('should set endpoint', () => {
mutations[types.SET_FEATURE_FLAGS_ENDPOINT](stateCopy, 'feature_flags.json');
expect(stateCopy.endpoint).toEqual('feature_flags.json');
});
}); });
describe('SET_FEATURE_FLAGS_OPTIONS', () => { describe('SET_FEATURE_FLAGS_OPTIONS', () => {
...@@ -27,23 +19,6 @@ describe('Feature flags store Mutations', () => { ...@@ -27,23 +19,6 @@ describe('Feature flags store Mutations', () => {
expect(stateCopy.options).toEqual({ page: '1', scope: 'all' }); expect(stateCopy.options).toEqual({ page: '1', scope: 'all' });
}); });
}); });
describe('SET_INSTANCE_ID_ENDPOINT', () => {
it('should set provided endpoint', () => {
mutations[types.SET_INSTANCE_ID_ENDPOINT](stateCopy, 'rotate_token.json');
expect(stateCopy.rotateEndpoint).toEqual('rotate_token.json');
});
});
describe('SET_INSTANCE_ID', () => {
it('should set provided token', () => {
mutations[types.SET_INSTANCE_ID](stateCopy, rotateData.token);
expect(stateCopy.instanceId).toEqual(rotateData.token);
});
});
describe('REQUEST_FEATURE_FLAGS', () => { describe('REQUEST_FEATURE_FLAGS', () => {
it('should set isLoading to true', () => { it('should set isLoading to true', () => {
mutations[types.REQUEST_FEATURE_FLAGS](stateCopy); mutations[types.REQUEST_FEATURE_FLAGS](stateCopy);
......
...@@ -2,25 +2,20 @@ import MockAdapter from 'axios-mock-adapter'; ...@@ -2,25 +2,20 @@ import MockAdapter from 'axios-mock-adapter';
import testAction from 'helpers/vuex_action_helper'; import testAction from 'helpers/vuex_action_helper';
import { TEST_HOST } from 'spec/test_constants'; import { TEST_HOST } from 'spec/test_constants';
import { import {
setEndpoint,
setPath,
createFeatureFlag, createFeatureFlag,
requestCreateFeatureFlag, requestCreateFeatureFlag,
receiveCreateFeatureFlagSuccess, receiveCreateFeatureFlagSuccess,
receiveCreateFeatureFlagError, receiveCreateFeatureFlagError,
} from '~/feature_flags/store/modules/new/actions'; } from '~/feature_flags/store/new/actions';
import state from '~/feature_flags/store/modules/new/state'; import state from '~/feature_flags/store/new/state';
import * as types from '~/feature_flags/store/modules/new/mutation_types'; import * as types from '~/feature_flags/store/new/mutation_types';
import { import {
ROLLOUT_STRATEGY_ALL_USERS, ROLLOUT_STRATEGY_ALL_USERS,
ROLLOUT_STRATEGY_PERCENT_ROLLOUT, ROLLOUT_STRATEGY_PERCENT_ROLLOUT,
LEGACY_FLAG, LEGACY_FLAG,
NEW_VERSION_FLAG, NEW_VERSION_FLAG,
} from '~/feature_flags/constants'; } from '~/feature_flags/constants';
import { import { mapFromScopesViewModel, mapStrategiesToRails } from '~/feature_flags/store/helpers';
mapFromScopesViewModel,
mapStrategiesToRails,
} from '~/feature_flags/store/modules/helpers';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
jest.mock('~/lib/utils/url_utility'); jest.mock('~/lib/utils/url_utility');
...@@ -29,33 +24,7 @@ describe('Feature flags New Module Actions', () => { ...@@ -29,33 +24,7 @@ describe('Feature flags New Module Actions', () => {
let mockedState; let mockedState;
beforeEach(() => { beforeEach(() => {
mockedState = state(); mockedState = state({ endpoint: 'feature_flags.json', path: '/feature_flags' });
});
describe('setEndpoint', () => {
it('should commit SET_ENDPOINT mutation', done => {
testAction(
setEndpoint,
'feature_flags.json',
mockedState,
[{ type: types.SET_ENDPOINT, payload: 'feature_flags.json' }],
[],
done,
);
});
});
describe('setPath', () => {
it('should commit SET_PATH mutation', done => {
testAction(
setPath,
'/feature_flags',
mockedState,
[{ type: types.SET_PATH, payload: '/feature_flags' }],
[],
done,
);
});
}); });
describe('createFeatureFlag', () => { describe('createFeatureFlag', () => {
......
import state from '~/feature_flags/store/modules/new/state'; import state from '~/feature_flags/store/new/state';
import mutations from '~/feature_flags/store/modules/new/mutations'; import mutations from '~/feature_flags/store/new/mutations';
import * as types from '~/feature_flags/store/modules/new/mutation_types'; import * as types from '~/feature_flags/store/new/mutation_types';
describe('Feature flags New Module Mutations', () => { describe('Feature flags New Module Mutations', () => {
let stateCopy; let stateCopy;
beforeEach(() => { beforeEach(() => {
stateCopy = state(); stateCopy = state({ endpoint: 'feature_flags.json', path: 'feature_flags' });
});
describe('SET_ENDPOINT', () => {
it('should set endpoint', () => {
mutations[types.SET_ENDPOINT](stateCopy, 'feature_flags.json');
expect(stateCopy.endpoint).toEqual('feature_flags.json');
});
});
describe('SET_PATH', () => {
it('should set provided options', () => {
mutations[types.SET_PATH](stateCopy, 'feature_flags');
expect(stateCopy.path).toEqual('feature_flags');
});
}); });
describe('REQUEST_CREATE_FEATURE_FLAG', () => { describe('REQUEST_CREATE_FEATURE_FLAG', () => {
......
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