PromucFlow_constructor/app/client/cypress/support/Objects/FeatureFlags.ts
Sagar Khalasi f30ef2ee64
chore: Removed immur dependancy (#39324)
## Description
Fixing this error :
https://github.com/appsmithorg/appsmith-ee/pull/6115/files
Removed dependencies.

Fixes #
https://app.zenhub.com/workspaces/qa-63316faf86bb2e170ed2e46b/issues/gh/appsmithorg/appsmith/39318

## Automation

/ok-to-test tags="@tag.All"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/13383377889>
> Commit: 55e9bb0a1366246508ed2e12be9cfae922212a02
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=13383377889&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Tue, 18 Feb 2025 05:52:11 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Refactor**
- Updated the app’s internal data handling to ensure more consistent and
reliable feature management.
- Enhanced robustness through improved error management, leading to
smoother operation and better control over feature updates.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-02-18 11:58:20 +05:30

110 lines
3.2 KiB
TypeScript

import { LICENSE_FEATURE_FLAGS } from "../Constants";
import { ObjectsRegistry } from "./Registry";
const defaultFlags = {
rollout_remove_feature_walkthrough_enabled: false, // remove this flag from here when it's removed from code
release_git_modularisation_enabled: true,
};
export const featureFlagIntercept = (
flags: Record<string, boolean> = {},
reload = true,
) => {
getConsolidatedDataApi({ ...flags, ...defaultFlags }, false);
const response = {
responseMeta: {
status: 200,
success: true,
},
data: {
...flags,
...defaultFlags,
},
errorDisplay: "",
};
cy.intercept("GET", "/api/v1/users/features", response);
if (reload) ObjectsRegistry.AggregateHelper.CypressReload();
};
export const getConsolidatedDataApi = (
flags: Record<string, boolean> = {},
reload = true,
) => {
cy.intercept("GET", "/api/v1/consolidated-api/*?*", (req) => {
delete req.headers["if-none-match"];
req.reply((res: any) => {
if (
res.statusCode === 200 ||
res.statusCode === 401 ||
res.statusCode === 500
) {
const originalResponse = res?.body;
try {
const updatedResponse = JSON.parse(JSON.stringify(originalResponse));
updatedResponse.data.featureFlags.data = { ...flags };
return res.send(updatedResponse);
} catch (e) {
cy.log(`vamsi error `, e);
}
}
});
}).as("getConsolidatedData");
if (reload) ObjectsRegistry.AggregateHelper.CypressReload();
};
export const featureFlagInterceptForLicenseFlags = () => {
cy.intercept(
{
method: "GET",
url: "/api/v1/users/features",
},
(req) => {
req.reply((res) => {
if (res) {
const originalResponse = res.body;
let modifiedResponse: any = {};
Object.keys(originalResponse.data).forEach((flag) => {
if (LICENSE_FEATURE_FLAGS.includes(flag)) {
modifiedResponse[flag] = originalResponse.data[flag];
}
});
modifiedResponse = {
...modifiedResponse,
release_app_sidebar_enabled: true,
};
res.send({
responseMeta: {
status: 200,
success: true,
},
data: { ...modifiedResponse },
errorDisplay: "",
});
}
});
},
).as("getLicenseFeatures");
cy.intercept("GET", "/api/v1/consolidated-api/*?*", (req) => {
req.reply((res: any) => {
delete req.headers["if-none-match"];
if (res.statusCode === 200) {
const originalResponse = res?.body;
const updatedResponse = JSON.parse(JSON.stringify(originalResponse));
updatedResponse.data.featureFlags.data = {};
Object.keys(originalResponse.data.featureFlags.data).forEach((flag) => {
if (LICENSE_FEATURE_FLAGS.includes(flag)) {
updatedResponse.data.featureFlags.data[flag] =
originalResponse.data.featureFlags.data[flag];
}
});
updatedResponse.data.featureFlags.data["release_app_sidebar_enabled"] =
true;
return res.send(updatedResponse);
}
});
}).as("getConsolidatedData");
ObjectsRegistry.AggregateHelper.CypressReload();
};