Files
zitadel/e2e/cypress/support/api/features.ts
Max Peintner d8518d48f2 fix(console): single feature patch (#10476)
# Which Problems Are Solved

This PR fixes an issue where all features where patched, instead of a
single one. This led to instance overrides which were not intended.
With this change, an update is executed whenever a toggle is hit, only
containing the respective feature, not all.

# How the Problems Are Solved

The console application was overriding the feature settings as an entire
request. A toggle change is now only changing the desired and targeted
feature using partial patches.

# Additional Context

Closes #10459

---------

Co-authored-by: Elio Bischof <elio@zitadel.com>
2025-08-22 09:55:31 +02:00

60 lines
1.4 KiB
TypeScript

import { API } from './types';
export function getInstanceFeatures(api: API) {
return cy.request({
method: 'GET',
url: `${api.featuresBaseURL}/instance`,
headers: {
authorization: `Bearer ${api.token}`,
},
body: {},
});
}
export function setInstanceFeature(api: API, feature: string, enabled: boolean, additionalConfig?: Record<string, any>) {
const body: Record<string, any> = {
[feature]: enabled,
...additionalConfig,
};
return cy.request({
method: 'PUT',
url: `${api.featuresBaseURL}/instance`,
headers: {
authorization: `Bearer ${api.token}`,
},
body,
});
}
export function resetInstanceFeatures(api: API) {
return cy.request({
method: 'DELETE',
url: `${api.featuresBaseURL}/instance`,
headers: {
authorization: `Bearer ${api.token}`,
},
});
}
export function ensureFeatureState(api: API, feature: string, enabled: boolean, additionalConfig?: Record<string, any>) {
return getInstanceFeatures(api).then((response) => {
const currentState = response.body?.[feature]?.enabled;
if (currentState !== enabled) {
return setInstanceFeature(api, feature, enabled, additionalConfig);
}
return cy.wrap(response);
});
}
export function ensureLoginV2FeatureState(api: API, required: boolean, baseUri?: string) {
return setInstanceFeature(api, 'loginV2', required, {
loginV2: {
required,
baseUri: baseUri || '',
},
});
}