2021-01-03 14:25:43 +05:30
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import testAction from 'helpers/vuex_action_helper';
|
|
|
|
import { TEST_HOST } from 'spec/test_constants';
|
|
|
|
import {
|
|
|
|
requestFeatureFlags,
|
|
|
|
receiveFeatureFlagsSuccess,
|
|
|
|
receiveFeatureFlagsError,
|
|
|
|
fetchFeatureFlags,
|
|
|
|
setFeatureFlagsOptions,
|
|
|
|
rotateInstanceId,
|
|
|
|
requestRotateInstanceId,
|
|
|
|
receiveRotateInstanceIdSuccess,
|
|
|
|
receiveRotateInstanceIdError,
|
|
|
|
toggleFeatureFlag,
|
|
|
|
updateFeatureFlag,
|
|
|
|
receiveUpdateFeatureFlagSuccess,
|
|
|
|
receiveUpdateFeatureFlagError,
|
|
|
|
clearAlert,
|
|
|
|
} from '~/feature_flags/store/index/actions';
|
|
|
|
import * as types from '~/feature_flags/store/index/mutation_types';
|
2021-03-11 19:13:27 +05:30
|
|
|
import state from '~/feature_flags/store/index/state';
|
2021-01-03 14:25:43 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2021-09-04 01:27:46 +05:30
|
|
|
import { getRequestData, rotateData, featureFlag } from '../../mock_data';
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
jest.mock('~/api.js');
|
|
|
|
|
|
|
|
describe('Feature flags actions', () => {
|
|
|
|
let mockedState;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mockedState = state({});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setFeatureFlagsOptions', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('should commit SET_FEATURE_FLAGS_OPTIONS mutation', () => {
|
|
|
|
return testAction(
|
2021-01-03 14:25:43 +05:30
|
|
|
setFeatureFlagsOptions,
|
|
|
|
{ page: '1', scope: 'all' },
|
|
|
|
mockedState,
|
|
|
|
[{ type: types.SET_FEATURE_FLAGS_OPTIONS, payload: { page: '1', scope: 'all' } }],
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fetchFeatureFlags', () => {
|
|
|
|
let mock;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mockedState.endpoint = `${TEST_HOST}/endpoint.json`;
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('success', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
it('dispatches requestFeatureFlags and receiveFeatureFlagsSuccess', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
mock.onGet(`${TEST_HOST}/endpoint.json`).replyOnce(200, getRequestData, {});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return testAction(
|
2021-01-03 14:25:43 +05:30
|
|
|
fetchFeatureFlags,
|
|
|
|
null,
|
|
|
|
mockedState,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'requestFeatureFlags',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
payload: { data: getRequestData, headers: {} },
|
|
|
|
type: 'receiveFeatureFlagsSuccess',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('error', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
it('dispatches requestFeatureFlags and receiveFeatureFlagsError', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
mock.onGet(`${TEST_HOST}/endpoint.json`, {}).replyOnce(500, {});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return testAction(
|
2021-01-03 14:25:43 +05:30
|
|
|
fetchFeatureFlags,
|
|
|
|
null,
|
|
|
|
mockedState,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'requestFeatureFlags',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'receiveFeatureFlagsError',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('requestFeatureFlags', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('should commit RECEIVE_FEATURE_FLAGS_SUCCESS mutation', () => {
|
|
|
|
return testAction(
|
2021-01-03 14:25:43 +05:30
|
|
|
requestFeatureFlags,
|
|
|
|
null,
|
|
|
|
mockedState,
|
|
|
|
[{ type: types.REQUEST_FEATURE_FLAGS }],
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('receiveFeatureFlagsSuccess', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('should commit RECEIVE_FEATURE_FLAGS_SUCCESS mutation', () => {
|
|
|
|
return testAction(
|
2021-01-03 14:25:43 +05:30
|
|
|
receiveFeatureFlagsSuccess,
|
|
|
|
{ data: getRequestData, headers: {} },
|
|
|
|
mockedState,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: types.RECEIVE_FEATURE_FLAGS_SUCCESS,
|
|
|
|
payload: { data: getRequestData, headers: {} },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('receiveFeatureFlagsError', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('should commit RECEIVE_FEATURE_FLAGS_ERROR mutation', () => {
|
|
|
|
return testAction(
|
2021-01-03 14:25:43 +05:30
|
|
|
receiveFeatureFlagsError,
|
|
|
|
null,
|
|
|
|
mockedState,
|
|
|
|
[{ type: types.RECEIVE_FEATURE_FLAGS_ERROR }],
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('rotateInstanceId', () => {
|
|
|
|
let mock;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mockedState.rotateEndpoint = `${TEST_HOST}/endpoint.json`;
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('success', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
it('dispatches requestRotateInstanceId and receiveRotateInstanceIdSuccess', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
mock.onPost(`${TEST_HOST}/endpoint.json`).replyOnce(200, rotateData, {});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return testAction(
|
2021-01-03 14:25:43 +05:30
|
|
|
rotateInstanceId,
|
|
|
|
null,
|
|
|
|
mockedState,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'requestRotateInstanceId',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
payload: { data: rotateData, headers: {} },
|
|
|
|
type: 'receiveRotateInstanceIdSuccess',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('error', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
it('dispatches requestRotateInstanceId and receiveRotateInstanceIdError', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
mock.onGet(`${TEST_HOST}/endpoint.json`, {}).replyOnce(500, {});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return testAction(
|
2021-01-03 14:25:43 +05:30
|
|
|
rotateInstanceId,
|
|
|
|
null,
|
|
|
|
mockedState,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'requestRotateInstanceId',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'receiveRotateInstanceIdError',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('requestRotateInstanceId', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('should commit REQUEST_ROTATE_INSTANCE_ID mutation', () => {
|
|
|
|
return testAction(
|
2021-01-03 14:25:43 +05:30
|
|
|
requestRotateInstanceId,
|
|
|
|
null,
|
|
|
|
mockedState,
|
|
|
|
[{ type: types.REQUEST_ROTATE_INSTANCE_ID }],
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('receiveRotateInstanceIdSuccess', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('should commit RECEIVE_ROTATE_INSTANCE_ID_SUCCESS mutation', () => {
|
|
|
|
return testAction(
|
2021-01-03 14:25:43 +05:30
|
|
|
receiveRotateInstanceIdSuccess,
|
|
|
|
{ data: rotateData, headers: {} },
|
|
|
|
mockedState,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: types.RECEIVE_ROTATE_INSTANCE_ID_SUCCESS,
|
|
|
|
payload: { data: rotateData, headers: {} },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('receiveRotateInstanceIdError', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('should commit RECEIVE_ROTATE_INSTANCE_ID_ERROR mutation', () => {
|
|
|
|
return testAction(
|
2021-01-03 14:25:43 +05:30
|
|
|
receiveRotateInstanceIdError,
|
|
|
|
null,
|
|
|
|
mockedState,
|
|
|
|
[{ type: types.RECEIVE_ROTATE_INSTANCE_ID_ERROR }],
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('toggleFeatureFlag', () => {
|
|
|
|
let mock;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-03-08 18:12:59 +05:30
|
|
|
mockedState.featureFlags = getRequestData.feature_flags.map((flag) => ({
|
2021-01-03 14:25:43 +05:30
|
|
|
...flag,
|
|
|
|
}));
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
describe('success', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('dispatches updateFeatureFlag and receiveUpdateFeatureFlagSuccess', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
mock.onPut(featureFlag.update_path).replyOnce(200, featureFlag, {});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return testAction(
|
2021-01-03 14:25:43 +05:30
|
|
|
toggleFeatureFlag,
|
|
|
|
featureFlag,
|
|
|
|
mockedState,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'updateFeatureFlag',
|
|
|
|
payload: featureFlag,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
payload: featureFlag,
|
|
|
|
type: 'receiveUpdateFeatureFlagSuccess',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2022-06-21 17:19:12 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
describe('error', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('dispatches updateFeatureFlag and receiveUpdateFeatureFlagSuccess', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
mock.onPut(featureFlag.update_path).replyOnce(500);
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return testAction(
|
2021-01-03 14:25:43 +05:30
|
|
|
toggleFeatureFlag,
|
|
|
|
featureFlag,
|
|
|
|
mockedState,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'updateFeatureFlag',
|
|
|
|
payload: featureFlag,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
payload: featureFlag.id,
|
|
|
|
type: 'receiveUpdateFeatureFlagError',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('updateFeatureFlag', () => {
|
|
|
|
beforeEach(() => {
|
2021-03-08 18:12:59 +05:30
|
|
|
mockedState.featureFlags = getRequestData.feature_flags.map((f) => ({
|
2021-01-03 14:25:43 +05:30
|
|
|
...f,
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
it('commits UPDATE_FEATURE_FLAG with the given flag', () => {
|
|
|
|
return testAction(
|
2021-01-03 14:25:43 +05:30
|
|
|
updateFeatureFlag,
|
|
|
|
featureFlag,
|
|
|
|
mockedState,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'UPDATE_FEATURE_FLAG',
|
|
|
|
payload: featureFlag,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('receiveUpdateFeatureFlagSuccess', () => {
|
|
|
|
beforeEach(() => {
|
2021-03-08 18:12:59 +05:30
|
|
|
mockedState.featureFlags = getRequestData.feature_flags.map((f) => ({
|
2021-01-03 14:25:43 +05:30
|
|
|
...f,
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
it('commits RECEIVE_UPDATE_FEATURE_FLAG_SUCCESS with the given flag', () => {
|
|
|
|
return testAction(
|
2021-01-03 14:25:43 +05:30
|
|
|
receiveUpdateFeatureFlagSuccess,
|
|
|
|
featureFlag,
|
|
|
|
mockedState,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'RECEIVE_UPDATE_FEATURE_FLAG_SUCCESS',
|
|
|
|
payload: featureFlag,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('receiveUpdateFeatureFlagError', () => {
|
|
|
|
beforeEach(() => {
|
2021-03-08 18:12:59 +05:30
|
|
|
mockedState.featureFlags = getRequestData.feature_flags.map((f) => ({
|
2021-01-03 14:25:43 +05:30
|
|
|
...f,
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
it('commits RECEIVE_UPDATE_FEATURE_FLAG_ERROR with the given flag id', () => {
|
|
|
|
return testAction(
|
2021-01-03 14:25:43 +05:30
|
|
|
receiveUpdateFeatureFlagError,
|
|
|
|
featureFlag.id,
|
|
|
|
mockedState,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'RECEIVE_UPDATE_FEATURE_FLAG_ERROR',
|
|
|
|
payload: featureFlag.id,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('clearAlert', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('should commit RECEIVE_CLEAR_ALERT', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
const alertIndex = 3;
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return testAction(
|
2021-01-03 14:25:43 +05:30
|
|
|
clearAlert,
|
|
|
|
alertIndex,
|
|
|
|
mockedState,
|
|
|
|
[{ type: 'RECEIVE_CLEAR_ALERT', payload: alertIndex }],
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|