PromucFlow_constructor/app/client/packages/rts/src/test/server.test.ts

246 lines
8.0 KiB
TypeScript
Raw Normal View History

chore: Refactor Codebase to Remove Telemetry from CE (#39421) ## Description > [!TIP] > _Add a TL;DR when the description is longer than 500 words or extremely technical (helps the content, marketing, and DevRel team)._ > > _Please also include relevant motivation and context. List any dependencies that are required for this change. Add links to Notion, Figma or any other documents that might be relevant to the PR._ Fixes #`Issue Number` _or_ Fixes `Issue URL` > [!WARNING] > _If no issue exists, please create an issue first, and check with the maintainers if the issue is valid._ ## Automation /ok-to-test tags="@tag.Sanity" ### :mag: 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/13504505801> > Commit: 79794e513fe12bc472bbb657dcefbf84b2574715 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=13504505801&attempt=2" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Mon, 24 Feb 2025 18:53:23 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 - **New Features** - Deployed an updated server implementation offering improved security, refined request handling, and robust API route integration. - Introduced a centralized configuration system that streamlines settings for performance, administration, and integrations with external services. - **Refactor / Chores** - Simplified internal observability by streamlining tracing and span management. - Cleaned up legacy instrumentation to enhance system efficiency and maintainability. - Removed deprecated configuration properties to consolidate settings and improve clarity. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-02-25 07:48:42 +00:00
import app from "../ce/server";
chore: Don't break when Appsmtih API URL isn't set (#37309) We actually don't need the `APPSMITH_API_BASE_URL` variable to be varying in production ever at all, and the `routes.ts` file already does have a default for this (on EE). Let's just use that instead of throwing an impact-less error. Ideally though, we shouldn't have this env variable at all. Less things that are configurable, less things that can break other things. ## Automation /test sanity ### :mag: 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/11812221529> > Commit: f049d468998530cddd9f7ad45542790c9e12241b > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11812221529&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Wed, 13 Nov 2024 07:41:57 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 ## Release Notes - **New Features** - Introduced constants for API URLs to streamline endpoint configurations. - **Bug Fixes** - Updated API request URLs to use new constants, ensuring consistency across the application. - **Refactor** - Centralized route constants to improve maintainability. - Renamed entities in test cases for clarity while preserving functionality. - **Chores** - Removed obsolete environment variable related to API base URL from the Docker configuration. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-11-15 08:04:35 +00:00
import { RTS_BASE_API_PATH } from "@constants/routes";
import supertest from "supertest";
const singleScript = {
script:
"(function abc() { let Api2 = { }; return Api2.data ? str.data + Api1.data : [] })()",
};
const multipleScripts = {
scripts: [
"(function abc() { return Api1.data })() ",
"(function abc() { let str = ''; return str ? Api1.data : [] })()",
],
};
const entityRefactor = [
{
script: "ApiNever",
oldName: "ApiNever",
newName: "ApiForever",
isJSObject: false,
evalVersion: 2,
},
{
script: "ApiNever.data",
oldName: "ApiNever",
newName: "ApiForever",
isJSObject: false,
},
{
script:
"// ApiNever \n function ApiNever(abc) {let foo = \"I'm getting data from ApiNever but don't rename this string\" + ApiNever.data; \n if(true) { return ApiNever }}",
oldName: "ApiNever",
newName: "ApiForever",
isJSObject: false,
evalVersion: 2,
},
{
script:
"//ApiNever \n function ApiNever(abc) {let ApiNever = \"I'm getting data from ApiNever but don't rename this string\" + ApiNever.data; \n if(true) { return ApiNever }}",
oldName: "ApiNever",
newName: "ApiForever",
isJSObject: false,
},
{
script:
"export default {\n\tmyVar1: [],\n\tmyVar2: {},\n\t\tsearch: () => {\n\t\tif(Input1Copy.text.length==0){\n\t\t\treturn select_repair_db.data\n\t\t}\n\t\telse{\n\t\t\treturn(select_repair_db.data.filter(word => word.cust_name.toLowerCase().includes(Input1Copy.text.toLowerCase())))\n\t\t}\n\t},\n}",
oldName: "Input1Copy",
newName: "Input1",
isJSObject: true,
evalVersion: 2,
},
{
script:
"// ApiNever \n function ApiNever(abc) {let foo = \"I'm getting data from ApiNever but don't rename this string\" + ApiNever.data; \n if(true) { return ApiNever }}",
oldName: "ApiNever.data",
newName: "ApiNever.input",
isJSObject: false,
evalVersion: 2,
},
{
script:
"// ApiNever \n function ApiNever(abc) {let foo = \"I'm getting data from ApiNever but don't rename this string\" + ApiNever.data; \n if(true) { return ApiNever }}",
oldName: "ApiNever.dat",
newName: "ApiNever.input",
isJSObject: false,
evalVersion: 2,
},
{
script: "\tApiNever.data",
oldName: "ApiNever",
newName: "ApiForever",
isJSObject: false,
evalVersion: 2,
},
{
script: "ApiNever.data + ApiNever.data",
oldName: "ApiNever",
newName: "ApiForever",
isJSObject: false,
evalVersion: 2,
},
{
script:
'export default {\n\tmyVar1: [],\n\tmyVar2: {},\n\tmyFun1: () => {\n\t\t//write code here\n\t\t// ApiNever.text\n\t\treturn "ApiNever.text" + ApiNever.text\n\t},\n\tmyFun2: async () => {\n\t\t//use async-await or promises\n\t\t// ApiNever.text\n\t\treturn "ApiNever.text" + ApiNever.text\n\t}\n}',
oldName: "ApiNever",
newName: "ApiForever",
isJSObject: true,
evalVersion: 2,
},
fix: Unblocking CI - Unexpected cyclic dependency error and Lint spec fixes (#20260) ## Description This PR fixes the false cyclic dependency error Cypress tests and the basic Lint error Cypress tests. > Add a TL;DR when description is extra long (helps content team) Fixes # (issue) > if no issue exists, please create an issue and ask the maintainers about this first Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video ## Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - Chore (housekeeping or task changes that don't impact user perception) - This change requires a documentation update ## How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Provide instructions, so we can reproduce. > Please also list any relevant details for your test configuration. > Delete anything that is not important - Manual - Jest - Cypress ### Test Plan > Add Testsmith test cases links that relate to this PR ### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) ## Checklist: ### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [ ] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test --------- Co-authored-by: ChandanBalajiBP <104058110+ChandanBalajiBP@users.noreply.github.com>
2023-01-31 14:33:10 +00:00
{
script:
'(function(){\n try{\n ApiNever.run(); \n showAlert("Sucessful Trigger");\n }catch(error){\nshowAlert("Unsucessful Trigger");\n }\n})()',
oldName: "ApiNever",
newName: "ApiForever",
isJSObject: false,
evalVersion: 2,
},
];
afterAll((done) => {
app.close();
done();
});
describe("AST tests", () => {
it("Checks to see if single script is parsed correctly using the API", async () => {
const expectedResponse = {
references: ["str.data", "Api1.data"],
functionalParams: [],
variables: ["Api2"],
chore: add isError to return value of extractIdentifierInfoFromCode in AST (#35525) ## Description Adds an isError flag to know if there is a syntax error while parsing PR for https://github.com/appsmithorg/appsmith-ee/pull/4547 ## Automation /ok-to-test tags="@tag.All" ### :mag: 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/10295486363> > Commit: d69958d73ceb625ce82101ee98e5c81fe3d46697 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10295486363&attempt=2" target="_blank">Cypress dashboard</a>. > Tags: `@tag.All` > Spec: > <hr>Thu, 08 Aug 2024 06:45:00 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new `isError` property in the identifier information interface, enhancing error reporting during code extraction. - **Bug Fixes** - Updated extraction function to properly set the `isError` property based on success or `SyntaxError`, improving clarity on extraction outcomes. - **Tests** - Enhanced test cases by incorporating the `isError` property, improving clarity on expected outcomes and robustness of the testing framework. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-08-08 08:16:12 +00:00
isError: false,
};
await supertest(app)
.post(`${RTS_BASE_API_PATH}/ast/single-script-data`, {
JSON: true,
})
.send(singleScript)
.expect(200)
.then((response) => {
expect(response.body.success).toEqual(true);
expect(response.body.data).toEqual(expectedResponse);
});
});
it("Checks to see if multiple scripts are parsed correctly using the API", async () => {
const expectedResponse = [
{
references: ["Api1.data"],
functionalParams: [],
variables: [],
chore: add isError to return value of extractIdentifierInfoFromCode in AST (#35525) ## Description Adds an isError flag to know if there is a syntax error while parsing PR for https://github.com/appsmithorg/appsmith-ee/pull/4547 ## Automation /ok-to-test tags="@tag.All" ### :mag: 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/10295486363> > Commit: d69958d73ceb625ce82101ee98e5c81fe3d46697 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10295486363&attempt=2" target="_blank">Cypress dashboard</a>. > Tags: `@tag.All` > Spec: > <hr>Thu, 08 Aug 2024 06:45:00 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new `isError` property in the identifier information interface, enhancing error reporting during code extraction. - **Bug Fixes** - Updated extraction function to properly set the `isError` property based on success or `SyntaxError`, improving clarity on extraction outcomes. - **Tests** - Enhanced test cases by incorporating the `isError` property, improving clarity on expected outcomes and robustness of the testing framework. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-08-08 08:16:12 +00:00
isError: false,
},
{
references: ["Api1.data"],
functionalParams: [],
variables: ["str"],
chore: add isError to return value of extractIdentifierInfoFromCode in AST (#35525) ## Description Adds an isError flag to know if there is a syntax error while parsing PR for https://github.com/appsmithorg/appsmith-ee/pull/4547 ## Automation /ok-to-test tags="@tag.All" ### :mag: 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/10295486363> > Commit: d69958d73ceb625ce82101ee98e5c81fe3d46697 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10295486363&attempt=2" target="_blank">Cypress dashboard</a>. > Tags: `@tag.All` > Spec: > <hr>Thu, 08 Aug 2024 06:45:00 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new `isError` property in the identifier information interface, enhancing error reporting during code extraction. - **Bug Fixes** - Updated extraction function to properly set the `isError` property based on success or `SyntaxError`, improving clarity on extraction outcomes. - **Tests** - Enhanced test cases by incorporating the `isError` property, improving clarity on expected outcomes and robustness of the testing framework. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-08-08 08:16:12 +00:00
isError: false,
},
];
await supertest(app)
.post(`${RTS_BASE_API_PATH}/ast/multiple-script-data`, {
JSON: true,
})
.send(multipleScripts)
.expect(200)
.then((response) => {
expect(response.body.success).toEqual(true);
expect(response.body.data.length).toBeGreaterThan(1);
expect(response.body.data).toEqual(expectedResponse);
});
});
entityRefactor.forEach(async (input, index) => {
it(`Entity refactor test case ${index + 1}`, async () => {
const expectedResponse = [
{ script: "ApiForever", refactorCount: 1 },
{ script: "ApiForever.data", refactorCount: 1 },
{
script:
"// ApiNever \n function ApiNever(abc) {let foo = \"I'm getting data from ApiNever but don't rename this string\" + ApiForever.data; \n if(true) { return ApiForever }}",
refactorCount: 2,
},
{
script:
"//ApiNever \n function ApiNever(abc) {let ApiNever = \"I'm getting data from ApiNever but don't rename this string\" + ApiNever.data; \n if(true) { return ApiNever }}",
refactorCount: 0,
},
{
script:
"export default {\n\tmyVar1: [],\n\tmyVar2: {},\n\t\tsearch: () => {\n\t\tif(Input1.text.length==0){\n\t\t\treturn select_repair_db.data\n\t\t}\n\t\telse{\n\t\t\treturn(select_repair_db.data.filter(word => word.cust_name.toLowerCase().includes(Input1.text.toLowerCase())))\n\t\t}\n\t},\n}",
refactorCount: 2,
},
{
script:
"// ApiNever \n function ApiNever(abc) {let foo = \"I'm getting data from ApiNever but don't rename this string\" + ApiNever.input; \n if(true) { return ApiNever }}",
refactorCount: 1,
},
{
script:
"// ApiNever \n function ApiNever(abc) {let foo = \"I'm getting data from ApiNever but don't rename this string\" + ApiNever.data; \n if(true) { return ApiNever }}",
refactorCount: 0,
},
{
script: "\tApiForever.data",
refactorCount: 1,
},
{
script: "ApiForever.data + ApiForever.data",
refactorCount: 2,
},
{
script:
'export default {\n\tmyVar1: [],\n\tmyVar2: {},\n\tmyFun1: () => {\n\t\t//write code here\n\t\t// ApiNever.text\n\t\treturn "ApiNever.text" + ApiForever.text\n\t},\n\tmyFun2: async () => {\n\t\t//use async-await or promises\n\t\t// ApiNever.text\n\t\treturn "ApiNever.text" + ApiForever.text\n\t}\n}',
refactorCount: 2,
},
fix: Unblocking CI - Unexpected cyclic dependency error and Lint spec fixes (#20260) ## Description This PR fixes the false cyclic dependency error Cypress tests and the basic Lint error Cypress tests. > Add a TL;DR when description is extra long (helps content team) Fixes # (issue) > if no issue exists, please create an issue and ask the maintainers about this first Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video ## Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - Chore (housekeeping or task changes that don't impact user perception) - This change requires a documentation update ## How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Provide instructions, so we can reproduce. > Please also list any relevant details for your test configuration. > Delete anything that is not important - Manual - Jest - Cypress ### Test Plan > Add Testsmith test cases links that relate to this PR ### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) ## Checklist: ### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [ ] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test --------- Co-authored-by: ChandanBalajiBP <104058110+ChandanBalajiBP@users.noreply.github.com>
2023-01-31 14:33:10 +00:00
{
script:
'(function(){\n try{\n ApiForever.run(); \n showAlert("Sucessful Trigger");\n }catch(error){\nshowAlert("Unsucessful Trigger");\n }\n})()',
refactorCount: 1,
},
];
await supertest(app)
.post(`${RTS_BASE_API_PATH}/ast/entity-refactor`, {
JSON: true,
})
.send(input)
.expect(200)
.then((response) => {
expect(response.body.success).toEqual(true);
expect(response.body.data.script).toEqual(
expectedResponse[index].script,
);
expect(response.body.data.refactorCount).toEqual(
expectedResponse[index].refactorCount,
);
});
});
});
it("Entity refactor syntax error", async () => {
const request = {
script: "ApiNever++++",
oldName: "ApiNever",
newName: "ApiForever",
isJSObject: true,
evalVersion: 2,
};
await supertest(app)
.post(`${RTS_BASE_API_PATH}/ast/entity-refactor`, {
JSON: true,
})
.send(request)
.expect(200)
.then((response) => {
expect(response.body.success).toEqual(false);
expect(response.body.data.error).toEqual("Syntax Error");
});
});
});