debian-mirror-gitlab/spec/frontend/feature_flags/store/new/actions_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

149 lines
4 KiB
JavaScript
Raw Normal View History

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', () => {
2022-10-11 01:57:18 +05:30
it('dispatches requestCreateFeatureFlag and receiveCreateFeatureFlagSuccess', () => {
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
2022-06-21 17:19:12 +05:30
return testAction(
2021-01-03 14:25:43 +05:30
createFeatureFlag,
2021-09-30 23:02:18 +05:30
actionParams,
2021-01-03 14:25:43 +05:30
mockedState,
[],
[
{
type: 'requestCreateFeatureFlag',
},
{
type: 'receiveCreateFeatureFlagSuccess',
},
],
);
});
});
describe('error', () => {
2022-10-11 01:57:18 +05:30
it('dispatches requestCreateFeatureFlag and receiveCreateFeatureFlagError', () => {
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: [] });
2022-06-21 17:19:12 +05:30
return testAction(
2021-01-03 14:25:43 +05:30
createFeatureFlag,
actionParams,
mockedState,
[],
[
{
type: 'requestCreateFeatureFlag',
},
{
type: 'receiveCreateFeatureFlagError',
payload: { message: [] },
},
],
);
});
});
});
describe('requestCreateFeatureFlag', () => {
2022-06-21 17:19:12 +05:30
it('should commit REQUEST_CREATE_FEATURE_FLAG mutation', () => {
return testAction(
2021-01-03 14:25:43 +05:30
requestCreateFeatureFlag,
null,
mockedState,
[{ type: types.REQUEST_CREATE_FEATURE_FLAG }],
[],
);
});
});
describe('receiveCreateFeatureFlagSuccess', () => {
2022-06-21 17:19:12 +05:30
it('should commit RECEIVE_CREATE_FEATURE_FLAG_SUCCESS mutation', () => {
return testAction(
2021-01-03 14:25:43 +05:30
receiveCreateFeatureFlagSuccess,
null,
mockedState,
[
{
type: types.RECEIVE_CREATE_FEATURE_FLAG_SUCCESS,
},
],
[],
);
});
});
describe('receiveCreateFeatureFlagError', () => {
2022-06-21 17:19:12 +05:30
it('should commit RECEIVE_CREATE_FEATURE_FLAG_ERROR mutation', () => {
return testAction(
2021-01-03 14:25:43 +05:30
receiveCreateFeatureFlagError,
'There was an error',
mockedState,
[{ type: types.RECEIVE_CREATE_FEATURE_FLAG_ERROR, payload: 'There was an error' }],
[],
);
});
});
});