debian-mirror-gitlab/spec/frontend/ci_variable_list/mocks.js

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

115 lines
2.1 KiB
JavaScript
Raw Normal View History

2022-10-11 01:57:18 +05:30
import {
variableTypes,
groupString,
instanceString,
projectString,
} from '~/ci_variable_list/constants';
2022-08-27 11:52:29 +05:30
export const devName = 'dev';
export const prodName = 'prod';
export const mockVariables = (kind) => {
return [
{
__typename: `Ci${kind}Variable`,
id: 1,
key: 'my-var',
masked: false,
protected: true,
2022-10-11 01:57:18 +05:30
value: 'variable_value',
variableType: variableTypes.envType,
2022-08-27 11:52:29 +05:30
},
{
__typename: `Ci${kind}Variable`,
id: 2,
key: 'secret',
masked: true,
protected: false,
2022-10-11 01:57:18 +05:30
value: 'another_value',
2022-08-27 11:52:29 +05:30
variableType: variableTypes.fileType,
},
];
};
export const mockVariablesWithScopes = (kind) =>
mockVariables(kind).map((variable) => {
return { ...variable, environmentScope: '*' };
});
const createDefaultVars = ({ withScope = true, kind } = {}) => {
let base = mockVariables(kind);
if (withScope) {
base = mockVariablesWithScopes(kind);
}
return {
__typename: `Ci${kind}VariableConnection`,
nodes: base,
};
};
const defaultEnvs = {
__typename: 'EnvironmentConnection',
nodes: [
{
__typename: 'Environment',
id: 1,
name: prodName,
},
{
__typename: 'Environment',
id: 2,
name: devName,
},
],
};
export const mockEnvs = defaultEnvs.nodes;
export const mockProjectEnvironments = {
data: {
project: {
__typename: 'Project',
id: 1,
environments: defaultEnvs,
},
},
};
export const mockProjectVariables = {
data: {
project: {
__typename: 'Project',
id: 1,
2022-10-11 01:57:18 +05:30
ciVariables: createDefaultVars({ kind: projectString }),
2022-08-27 11:52:29 +05:30
},
},
};
export const mockGroupVariables = {
data: {
group: {
__typename: 'Group',
id: 1,
ciVariables: createDefaultVars({ kind: groupString }),
},
},
};
export const mockAdminVariables = {
data: {
ciVariables: createDefaultVars({ withScope: false, kind: instanceString }),
},
};
export const newVariable = {
id: 3,
environmentScope: 'new',
key: 'AWS_RANDOM_THING',
masked: true,
protected: false,
value: 'devops',
variableType: variableTypes.variableType,
};