2021-01-03 14:25:43 +05:30
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import testAction from 'helpers/vuex_action_helper';
|
2021-09-30 23:02:18 +05:30
|
|
|
import { ROLLOUT_STRATEGY_ALL_USERS } from '~/feature_flags/constants';
|
|
|
|
import { mapStrategiesToRails } from '~/feature_flags/store/helpers';
|
2021-03-11 19:13:27 +05:30
|
|
|
import {
|
|
|
|
createFeatureFlag,
|
|
|
|
requestCreateFeatureFlag,
|
|
|
|
receiveCreateFeatureFlagSuccess,
|
|
|
|
receiveCreateFeatureFlagError,
|
|
|
|
} from '~/feature_flags/store/new/actions';
|
|
|
|
import * as types from '~/feature_flags/store/new/mutation_types';
|
|
|
|
import state from '~/feature_flags/store/new/state';
|
2021-01-03 14:25:43 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
|
|
|
|
jest.mock('~/lib/utils/url_utility');
|
|
|
|
|
|
|
|
describe('Feature flags New Module Actions', () => {
|
|
|
|
let mockedState;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-09-30 23:02:18 +05:30
|
|
|
mockedState = state({ endpoint: '/feature_flags.json', path: '/feature_flags' });
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('createFeatureFlag', () => {
|
|
|
|
let mock;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('success', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
it('dispatches requestCreateFeatureFlag and receiveCreateFeatureFlagSuccess ', (done) => {
|
2021-09-30 23:02:18 +05:30
|
|
|
const actionParams = {
|
2021-01-03 14:25:43 +05:30
|
|
|
name: 'name',
|
|
|
|
description: 'description',
|
|
|
|
active: true,
|
|
|
|
strategies: [
|
|
|
|
{
|
|
|
|
name: ROLLOUT_STRATEGY_ALL_USERS,
|
|
|
|
parameters: {},
|
|
|
|
id: 1,
|
|
|
|
scopes: [{ id: 1, environmentScope: 'environmentScope', shouldBeDestroyed: false }],
|
|
|
|
shouldBeDestroyed: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2021-09-30 23:02:18 +05:30
|
|
|
mock.onPost(mockedState.endpoint, mapStrategiesToRails(actionParams)).replyOnce(200);
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
testAction(
|
|
|
|
createFeatureFlag,
|
2021-09-30 23:02:18 +05:30
|
|
|
actionParams,
|
2021-01-03 14:25:43 +05:30
|
|
|
mockedState,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'requestCreateFeatureFlag',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'receiveCreateFeatureFlagSuccess',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('error', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
it('dispatches requestCreateFeatureFlag and receiveCreateFeatureFlagError ', (done) => {
|
2021-09-30 23:02:18 +05:30
|
|
|
const actionParams = {
|
|
|
|
name: 'name',
|
|
|
|
description: 'description',
|
|
|
|
active: true,
|
|
|
|
strategies: [
|
|
|
|
{
|
|
|
|
name: ROLLOUT_STRATEGY_ALL_USERS,
|
|
|
|
parameters: {},
|
|
|
|
id: 1,
|
|
|
|
scopes: [{ id: 1, environmentScope: 'environmentScope', shouldBeDestroyed: false }],
|
|
|
|
shouldBeDestroyed: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2021-01-03 14:25:43 +05:30
|
|
|
mock
|
2021-09-30 23:02:18 +05:30
|
|
|
.onPost(mockedState.endpoint, mapStrategiesToRails(actionParams))
|
2021-01-03 14:25:43 +05:30
|
|
|
.replyOnce(500, { message: [] });
|
|
|
|
|
|
|
|
testAction(
|
|
|
|
createFeatureFlag,
|
|
|
|
actionParams,
|
|
|
|
mockedState,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'requestCreateFeatureFlag',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'receiveCreateFeatureFlagError',
|
|
|
|
payload: { message: [] },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('requestCreateFeatureFlag', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should commit REQUEST_CREATE_FEATURE_FLAG mutation', (done) => {
|
2021-01-03 14:25:43 +05:30
|
|
|
testAction(
|
|
|
|
requestCreateFeatureFlag,
|
|
|
|
null,
|
|
|
|
mockedState,
|
|
|
|
[{ type: types.REQUEST_CREATE_FEATURE_FLAG }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('receiveCreateFeatureFlagSuccess', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should commit RECEIVE_CREATE_FEATURE_FLAG_SUCCESS mutation', (done) => {
|
2021-01-03 14:25:43 +05:30
|
|
|
testAction(
|
|
|
|
receiveCreateFeatureFlagSuccess,
|
|
|
|
null,
|
|
|
|
mockedState,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: types.RECEIVE_CREATE_FEATURE_FLAG_SUCCESS,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('receiveCreateFeatureFlagError', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should commit RECEIVE_CREATE_FEATURE_FLAG_ERROR mutation', (done) => {
|
2021-01-03 14:25:43 +05:30
|
|
|
testAction(
|
|
|
|
receiveCreateFeatureFlagError,
|
|
|
|
'There was an error',
|
|
|
|
mockedState,
|
|
|
|
[{ type: types.RECEIVE_CREATE_FEATURE_FLAG_ERROR, payload: 'There was an error' }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|