import { cloneDeep } from 'lodash';
import { HousekeepingPolicy } from '../../apps/audit-logs/utils';
import { SettingValue } from '../../types/settings';
-import { getValues } from '../settings';
+import { getValue } from '../settings';
export default class AuditLogsServiceMock {
- settingValue: SettingValue[];
- defaultValues: SettingValue[] = [{ key: 'test', value: HousekeepingPolicy.Weekly }];
+ settingValue: SettingValue;
+ defaultValues: SettingValue = { key: 'test', value: HousekeepingPolicy.Weekly };
constructor() {
this.settingValue = cloneDeep(this.defaultValues);
- (getValues as jest.Mock).mockImplementation(this.getValuesHandler);
+ (getValue as jest.Mock).mockImplementation(this.getValuesHandler);
}
getValuesHandler = () => {
getValuesHandler = (data: { keys: string; component?: string } & BranchParameters) => {
if (data.keys) {
- return Promise.resolve(
- this.settingValues.filter(set => data.keys.split(',').includes(set.key))
- );
+ return Promise.resolve(this.settingValues.filter(set => data.keys.includes(set.key)));
}
return Promise.resolve(this.settingValues);
};
);
}
+export function getValue(
+ data: { key: string; component?: string } & BranchParameters
+): Promise<SettingValue> {
+ return getValues({ keys: [data.key], component: data.component }).then(([result]) => result);
+}
+
export function getValues(
- data: { keys: string; component?: string } & BranchParameters
+ data: { keys: string[]; component?: string } & BranchParameters
): Promise<SettingValue[]> {
- return getJSON('/api/settings/values', data).then((r: SettingValueResponse) => [
+ return getJSON('/api/settings/values', {
+ keys: data.keys.join(','),
+ component: data.component
+ }).then((r: SettingValueResponse) => [
...r.settings,
...r.setSecuredSettings.map(key => ({ key }))
]);
getSettings = async () => {
const values: SettingValue[] = await getValues({
- keys: [GlobalSettingKeys.DisplaySystemMessage, GlobalSettingKeys.SystemMessage].join(',')
+ keys: [GlobalSettingKeys.DisplaySystemMessage, GlobalSettingKeys.SystemMessage]
});
const settings = keyBy(values, 'key');
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import * as React from 'react';
-import { getValues } from '../../../api/settings';
+import { getValue } from '../../../api/settings';
import withAdminPagesOutletContext from '../../../app/components/admin/withAdminPagesOutletContext';
import { AdminPageExtension } from '../../../types/extension';
import { SettingsKey } from '../../../types/settings';
}
fetchHouseKeepingPolicy = async () => {
- const results = await getValues({ keys: SettingsKey.AuditHouseKeeping });
+ const result = await getValue({ key: SettingsKey.AuditHouseKeeping });
this.setState({
housekeepingPolicy:
- (results[0]?.value as HousekeepingPolicy | undefined) ?? HousekeepingPolicy.Monthly
+ (result?.value as HousekeepingPolicy | undefined) ?? HousekeepingPolicy.Monthly
});
};
import { subDays } from 'date-fns';
import { shallow } from 'enzyme';
import * as React from 'react';
-import { getValues } from '../../../../api/settings';
+import { getValue } from '../../../../api/settings';
import { waitAndUpdate } from '../../../../helpers/testUtils';
import { AdminPageExtension } from '../../../../types/extension';
import { HousekeepingPolicy, RangeOption } from '../../utils';
import AuditAppRenderer from '../AuditAppRenderer';
jest.mock('../../../../api/settings', () => ({
- getValues: jest.fn().mockResolvedValue([])
+ getValue: jest.fn().mockResolvedValue({})
}));
beforeEach(() => {
await waitAndUpdate(wrapper);
expect(wrapper.type()).toBeNull();
- expect(getValues).not.toBeCalled();
+ expect(getValue).not.toBeCalled();
});
it('should handle housekeeping policy', async () => {
- (getValues as jest.Mock).mockResolvedValueOnce([{ value: HousekeepingPolicy.Weekly }]);
+ (getValue as jest.Mock).mockResolvedValueOnce({ value: HousekeepingPolicy.Weekly });
const wrapper = shallowRender();
await waitAndUpdate(wrapper);
expect(wrapper.type()).toBeNull();
- expect(getValues).not.toBeCalled();
+ expect(getValue).not.toBeCalled();
wrapper.setProps({ adminPages: [{ key: AdminPageExtension.GovernanceConsole, name: 'name' }] });
await waitAndUpdate(wrapper);
- expect(getValues).toBeCalled();
+ expect(getValue).toBeCalled();
});
function shallowRender(props: Partial<AuditApp['props']> = {}) {
getInstalledPluginsWithUpdates,
getPluginUpdates
} from '../../api/plugins';
-import { getValues, setSimpleSettingValue } from '../../api/settings';
+import { getValue, setSimpleSettingValue } from '../../api/settings';
import Link from '../../components/common/Link';
import Suggestions from '../../components/embed-docs-modal/Suggestions';
import { Location, Router, withRouter } from '../../components/hoc/withRouter';
};
fetchRiskConsent = async () => {
- const result = await getValues({ keys: SettingsKey.PluginRiskConsent });
+ const consent = await getValue({ key: SettingsKey.PluginRiskConsent });
- if (!result || result.length < 1) {
+ if (consent === undefined) {
return;
}
- const [consent] = result;
-
this.setState({ riskConsent: consent.value as RiskConsent | undefined });
};
getInstalledPluginsWithUpdates,
getPluginUpdates
} from '../../../api/plugins';
-import { getValues, setSimpleSettingValue } from '../../../api/settings';
+import { getValue, setSimpleSettingValue } from '../../../api/settings';
import { mockLocation, mockRouter } from '../../../helpers/testMocks';
import { waitAndUpdate } from '../../../helpers/testUtils';
import { EditionKey } from '../../../types/editions';
});
jest.mock('../../../api/settings', () => ({
- getValues: jest.fn().mockResolvedValue([]),
+ getValue: jest.fn().mockResolvedValue({}),
setSimpleSettingValue: jest.fn().mockResolvedValue(true)
}));
});
it('should handle accepting the risk', async () => {
- (getValues as jest.Mock)
- .mockResolvedValueOnce([{ value: RiskConsent.NotAccepted }])
- .mockResolvedValueOnce([{ value: RiskConsent.Accepted }]);
+ (getValue as jest.Mock)
+ .mockResolvedValueOnce({ value: RiskConsent.NotAccepted })
+ .mockResolvedValueOnce({ value: RiskConsent.Accepted });
const wrapper = shallowRender();
await waitAndUpdate(wrapper);
- expect(getValues).toBeCalledWith({ keys: SettingsKey.PluginRiskConsent });
+ expect(getValue).toBeCalledWith({ key: SettingsKey.PluginRiskConsent });
wrapper.instance().acknowledgeRisk();
await new Promise(setImmediate);
expect(setSimpleSettingValue).toBeCalled();
- expect(getValues).toBeCalledWith({ keys: SettingsKey.PluginRiskConsent });
+ expect(getValue).toBeCalledWith({ key: SettingsKey.PluginRiskConsent });
expect(wrapper.state().riskConsent).toBe(RiskConsent.Accepted);
});
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import * as React from 'react';
-import { getValues } from '../../../api/settings';
+import { getValue } from '../../../api/settings';
import withAppStateContext from '../../../app/components/app-state/withAppStateContext';
import { AppState } from '../../../types/appstate';
import { SettingsKey } from '../../../types/settings';
}
fetchBranchAndPullRequestLifetimeSetting() {
- getValues({ keys: SettingsKey.DaysBeforeDeletingInactiveBranchesAndPRs }).then(
+ getValue({ key: SettingsKey.DaysBeforeDeletingInactiveBranchesAndPRs }).then(
settings => {
if (this.mounted) {
this.setState({
loading: false,
- branchAndPullRequestLifeTimeInDays: settings.length > 0 ? settings[0].value : undefined
+ branchAndPullRequestLifeTimeInDays: settings?.value
});
}
},
*/
import { shallow } from 'enzyme';
import * as React from 'react';
-import { getValues } from '../../../../api/settings';
+import { getValue } from '../../../../api/settings';
import { mockAppState } from '../../../../helpers/testMocks';
import { waitAndUpdate } from '../../../../helpers/testUtils';
import { SettingsKey } from '../../../../types/settings';
import { LifetimeInformation } from '../LifetimeInformation';
jest.mock('../../../../api/settings', () => ({
- getValues: jest.fn().mockResolvedValue([{ value: '45' }])
+ getValue: jest.fn().mockResolvedValue({ value: '45' })
}));
it('should render correctly', async () => {
await waitAndUpdate(wrapper);
- expect(getValues).toHaveBeenCalledWith({
- keys: SettingsKey.DaysBeforeDeletingInactiveBranchesAndPRs
+ expect(getValue).toHaveBeenCalledWith({
+ key: SettingsKey.DaysBeforeDeletingInactiveBranchesAndPRs
});
expect(wrapper).toMatchSnapshot('after_fetching_data');
});
import { Helmet } from 'react-helmet-async';
import { getComponents, Project } from '../../api/components';
import { changeProjectDefaultVisibility } from '../../api/permissions';
-import { getValues } from '../../api/settings';
+import { getValue } from '../../api/settings';
import withCurrentUserContext from '../../app/components/current-user/withCurrentUserContext';
import ListFooter from '../../components/controls/ListFooter';
import Suggestions from '../../components/embed-docs-modal/Suggestions';
}
fetchDefaultProjectVisibility = async () => {
- const results = await getValues({ keys: SettingsKey.DefaultProjectVisibility });
+ const results = await getValue({ key: SettingsKey.DefaultProjectVisibility });
- if (this.mounted && results.length > 0 && results[0].value) {
- this.setState({ defaultProjectVisibility: results[0].value as Visibility });
+ if (this.mounted && results?.value !== undefined) {
+ this.setState({ defaultProjectVisibility: results.value as Visibility });
}
};
}));
jest.mock('../../../api/settings', () => ({
- getValues: jest.fn().mockResolvedValue([{ value: 'public' }])
+ getValue: jest.fn().mockResolvedValue({ value: 'public' })
}));
const components = mockComponents(11);
import * as React from 'react';
import { getComponents } from '../../../api/components';
import { changeProjectDefaultVisibility } from '../../../api/permissions';
-import { getValues } from '../../../api/settings';
+import { getValue } from '../../../api/settings';
import { mockLoggedInUser } from '../../../helpers/testMocks';
import { waitAndUpdate } from '../../../helpers/testUtils';
import { ProjectManagementApp, Props } from '../ProjectManagementApp';
}));
jest.mock('../../../api/settings', () => ({
- getValues: jest.fn().mockResolvedValue([{ value: 'public' }])
+ getValue: jest.fn().mockResolvedValue({ value: 'public' })
}));
const defaultSearchParameters = {
const wrapper = shallowRender();
await waitAndUpdate(wrapper);
expect(getComponents).lastCalledWith({ ...defaultSearchParameters, qualifiers: 'TRK' });
- expect(getValues).toBeCalled();
+ expect(getValue).toBeCalled();
expect(wrapper.state().defaultProjectVisibility).toBe('public');
});
definition => definition.category.toLowerCase() === category.toLowerCase()
);
- const keys = categoryDefinitions.map(definition => definition.key).join(',');
+ const keys = categoryDefinitions.map(definition => definition.key);
const values: SettingValue[] = await getValues({
keys,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import * as React from 'react';
-import { getValues, resetSettingValue, setSettingValue } from '../../../api/settings';
+import { getValue, resetSettingValue, setSettingValue } from '../../../api/settings';
import { translate, translateWithParameters } from '../../../helpers/l10n';
import { parseError } from '../../../helpers/request';
import { ExtendedSettingDefinition, SettingType, SettingValue } from '../../../types/settings';
try {
await resetSettingValue({ keys: definition.key, component: component?.key });
- const result = await getValues({ keys: definition.key, component: component?.key });
- const settingValue = result[0];
+ const settingValue = await getValue({ key: definition.key, component: component?.key });
this.setState({
changedValue: undefined,
try {
await setSettingValue(definition, changedValue, component?.key);
- const result = await getValues({ keys: definition.key, component: component?.key });
- const settingValue = result[0];
+ const settingValue = await getValue({ key: definition.key, component: component?.key });
this.setState({
changedValue: undefined,
await waitAndUpdate(wrapper);
- expect(getValues).toBeCalledWith({ keys: 'yes,yesagain', component: undefined });
+ expect(getValues).toBeCalledWith({ keys: ['yes', 'yesagain'], component: undefined });
expect(wrapper.state().settings).toEqual([
{ definition: definitions[0], settingValue: settings[0] },
await waitAndUpdate(wrapper);
- expect(getValues).toBeCalledWith({ keys: 'yes,yesagain', component: 'comp-key' });
+ expect(getValues).toBeCalledWith({ keys: ['yes', 'yesagain'], component: 'comp-key' });
wrapper.setProps({ category: 'other' });
await waitAndUpdate(wrapper);
- expect(getValues).toBeCalledWith({ keys: 'nope', component: 'comp-key' });
+ expect(getValues).toBeCalledWith({ keys: ['nope'], component: 'comp-key' });
});
function shallowRender(props: Partial<CategoryDefinitionsList['props']> = {}) {
*/
import { shallow } from 'enzyme';
import * as React from 'react';
-import { getValues, resetSettingValue, setSettingValue } from '../../../../api/settings';
+import { getValue, resetSettingValue, setSettingValue } from '../../../../api/settings';
import { mockDefinition, mockSettingValue } from '../../../../helpers/mocks/settings';
import { waitAndUpdate } from '../../../../helpers/testUtils';
import { SettingType } from '../../../../types/settings';
import Definition from '../Definition';
jest.mock('../../../../api/settings', () => ({
- getValues: jest.fn().mockResolvedValue([]),
+ getValue: jest.fn().mockResolvedValue({}),
resetSettingValue: jest.fn().mockResolvedValue(undefined),
setSettingValue: jest.fn().mockResolvedValue(undefined)
}));
it('should save and update setting value', async () => {
const settingValue = mockSettingValue();
- (getValues as jest.Mock).mockResolvedValueOnce([settingValue]);
+ (getValue as jest.Mock).mockResolvedValueOnce(settingValue);
const definition = mockDefinition();
const wrapper = shallowRender({ definition });
await waitAndUpdate(wrapper);
expect(setSettingValue).toBeCalledWith(definition, 'new value', undefined);
- expect(getValues).toBeCalledWith({ keys: definition.key, component: undefined });
+ expect(getValue).toBeCalledWith({ key: definition.key, component: undefined });
expect(wrapper.state().changedValue).toBeUndefined();
expect(wrapper.state().loading).toBe(false);
expect(wrapper.state().success).toBe(true);
it('should reset and update setting value', async () => {
const settingValue = mockSettingValue();
- (getValues as jest.Mock).mockResolvedValueOnce([settingValue]);
+ (getValue as jest.Mock).mockResolvedValueOnce(settingValue);
const definition = mockDefinition();
const wrapper = shallowRender({ definition });
await waitAndUpdate(wrapper);
expect(resetSettingValue).toBeCalledWith({ keys: definition.key, component: undefined });
- expect(getValues).toBeCalledWith({ keys: definition.key, component: undefined });
+ expect(getValue).toBeCalledWith({ key: definition.key, component: undefined });
expect(wrapper.state().changedValue).toBeUndefined();
expect(wrapper.state().loading).toBe(false);
expect(wrapper.state().success).toBe(true);
componentDidMount() {
const { definitions } = this.props;
- const keys = definitions.map(definition => definition.key).join(',');
+ const keys = definitions.map(definition => definition.key);
// Added setTimeout to make sure the component gets updated before scrolling
setTimeout(() => {
if (location.hash) {
});
};
- async loadSettingValues(keys: string) {
+ async loadSettingValues(keys: string[]) {
const { settingValue, securedFieldsSubmitted } = this.state;
const values = await getValues({
keys
}
this.setState({ success: dirtyFields.length !== dataWithError.length });
});
- await this.loadSettingValues(dirtyFields.join(','));
+ await this.loadSettingValues(dirtyFields);
this.setState({ submitting: false, dirtyFields: [] });
};
import * as React from 'react';
import { getAlmSettingsNoCatch } from '../../api/alm-settings';
import { getScannableProjects } from '../../api/components';
-import { getValues } from '../../api/settings';
+import { getValue } from '../../api/settings';
import { getHostUrl } from '../../helpers/urls';
import { hasGlobalPermission } from '../../helpers/users';
import { AlmSettingsInstance, ProjectAlmBindingResponse } from '../../types/alm-settings';
};
fetchBaseUrl = async () => {
- const settings = await getValues({ keys: SettingsKey.ServerBaseUrl }).catch(() => undefined);
- const baseUrl = settings && settings.find(s => s.key === SettingsKey.ServerBaseUrl)?.value;
+ const setting = await getValue({ key: SettingsKey.ServerBaseUrl }).catch(() => undefined);
+ const baseUrl = setting?.value;
if (baseUrl && baseUrl.length > 0 && this.mounted) {
this.setState({ baseUrl });
}
import * as React from 'react';
import { getAlmSettingsNoCatch } from '../../../api/alm-settings';
import { getScannableProjects } from '../../../api/components';
-import { getValues } from '../../../api/settings';
+import { getValue } from '../../../api/settings';
import {
mockAlmSettingsInstance,
mockProjectBitbucketBindingResponse
}));
jest.mock('../../../api/settings', () => ({
- getValues: jest.fn().mockResolvedValue([])
+ getValue: jest.fn().mockResolvedValue({})
}));
jest.mock('../../../api/components', () => ({
});
it('should fetch the correct baseUrl', async () => {
- (getValues as jest.Mock)
- .mockResolvedValueOnce([{ key: SettingsKey.ServerBaseUrl, value: '' }])
- .mockResolvedValueOnce([{ key: SettingsKey.ServerBaseUrl, value: 'http://sq.example.com' }])
+ (getValue as jest.Mock)
+ .mockResolvedValueOnce({ key: SettingsKey.ServerBaseUrl, value: '' })
+ .mockResolvedValueOnce({ key: SettingsKey.ServerBaseUrl, value: 'http://sq.example.com' })
.mockRejectedValueOnce(null);
let wrapper = shallowRender();
- expect(getValues).toBeCalled();
+ expect(getValue).toBeCalled();
expect(getHostUrl).toBeCalled();
// No baseURL, fallback to the URL in the browser.