PromucFlow_constructor/app/client/src/sagas/helper.test.ts

167 lines
7.8 KiB
TypeScript
Raw Normal View History

/**
* @jest-environment jsdom
*/
import { TextEncoder, TextDecoder } from "util";
Object.assign(global, { TextDecoder, TextEncoder });
import {
enhanceRequestPayloadWithEventData,
cleanValuesInObjectForHashing,
generateHashFromString,
} from "sagas/helper";
feat: Store `originalActionId` as part of Action DTO for copied action (#25011) ## Description To measure the impact of query modules in Appsmith. We need to track the time a user takes to edit a copied query. Today, we do not have a mechanism to understand if a query in question is a copied query. To fix this, the data model of the Query action needs to change to include the `originalQueryId` if a query is, in fact, a copied query. - [ ] When a query is first copied, there will be no `originalActionId` in the action object. In this scenario, the client will populate the `originalActionId` field and call the POST API to create the copied query. - [ ] If the query is already a copied query, the client will duplicate the value of the `originalActionId` when calling the POST API to create the copied query. |POST|`/api/v1/actions`| ----------|------| ### [Related discussion on Notion](https://www.notion.so/appsmith/Backend-dependency-for-modules-instrumentation-889462d461844745be0a2599c8555ca5) #### PR fixes following issue(s) Fixes #24734 #### 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 > > > ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [x] Manual - [x] JUnit - [ ] 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 - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed > Pull Request Template > > Use this template to quickly create a well written pull request. Delete all quotes before creating the pull request. > ## Description > Add a TL;DR when description is extra long (helps content team) > > Please include a summary of the changes and which issue has been fixed. Please also include relevant motivation > and context. List any dependencies that are required for this change > > Links to Notion, Figma or any other documents that might be relevant to the PR > > #### PR fixes following issue(s) Fixes # (issue number) > 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 > > > ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [ ] 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: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed --------- Co-authored-by: Abhinav Jha <abhinav@appsmith.com>
2023-07-04 07:42:09 +00:00
describe("tests the redux saga helper functions", () => {
it("tests the enhanceRequestPayloadWithEventData function", () => {
const inputs = [
{ payload: { id: "xyz" }, type: "COPY_ACTION_INIT" },
{ payload: { id: "xyz" }, type: "DUMMY_ACTION" },
{
payload: {
id: "xyz",
eventData: { analyticsData: { originalActionId: "abc" } },
},
type: "COPY_ACTION_INIT",
},
{ payload: {}, type: "COPY_ACTION_INIT" },
{ payload: {}, type: "" },
{ payload: undefined, type: "" },
];
const outputs = [
{ id: "xyz", eventData: { analyticsData: { originalActionId: "xyz" } } },
{ id: "xyz" },
{ id: "xyz", eventData: { analyticsData: { originalActionId: "abc" } } },
{},
{},
undefined,
];
inputs.forEach((input, index) => {
expect(
enhanceRequestPayloadWithEventData(input.payload, input.type),
).toStrictEqual(outputs[index]);
});
});
it("tests the cleanValuesInObjectForHashing function", () => {
const inputs = [
{
body: 'UPDATE public.users SET "id"= \'{{Table2.updatedRow.id}}\', "gender"= \'{{Table2.updatedRow.gender}}\', "latitude"= \'{{Table2.updatedRow.latitude}}\', "longitude"= \'{{Table2.updatedRow.longitude}}\', "dob"= \'{{Table2.updatedRow.dob}}\', "phone"= \'{{Table2.updatedRow.phone}}\', "email"= \'{{Table2.updatedRow.email}}\', "image"= \'{{Table2.updatedRow.image}}\', "country"= \'{{Table2.updatedRow.country}}\', "name"= \'{{Table2.updatedRow.name}}\' WHERE "id"= {{Table2.updatedRow.id}};',
},
{
paginationType: "NONE",
encodeParamsToggle: true,
body: 'UPDATE public.users SET "id"= \'{{Table2.updatedRow.id}}\', "gender"= \'{{Table2.updatedRow.gender}}\', "latitude"= \'{{Table2.updatedRow.latitude}}\', "longitude"= \'{{Table2.updatedRow.longitude}}\', "dob"= \'{{Table2.updatedRow.dob}}\', "phone"= \'{{Table2.updatedRow.phone}}\', "email"= \'{{Table2.updatedRow.email}}\', "image"= \'{{Table2.updatedRow.image}}\', "country"= \'{{Table2.updatedRow.country}}\', "name"= \'{{Table2.updatedRow.name}}\' WHERE "id"= {{Table2.updatedRow.id}};',
selfReferencingDataPaths: [],
pluginSpecifiedTemplates: [{ value: false }],
},
{
paginationType: "NONE",
encodeParamsToggle: true,
selfReferencingDataPaths: [],
formData: {
aggregate: { limit: { data: "10" } },
smartSubstitution: { data: true },
insert: { documents: { data: "{{(Table3.newRow || {})}}" } },
command: { data: "INSERT" },
collection: { data: "movies" },
},
},
{
timeoutInMillisecond: 10000.0,
paginationType: "NONE",
encodeParamsToggle: true,
selfReferencingDataPaths: [],
formData: { pageSize: "100", command: "", sort: "" },
},
{
body: 'UPDATE public.users SET "id"= \'{{Table2.updatedRow.id}}\', "gender"= \'{{Table2.updatedRow.gender}}\', "latitude"= \'{{Table2.updatedRow.latitude}}\', "longitude"= \'{{Table2.updatedRow.longitude}}\', "dob"= \'{{Table2.updatedRow.dob}}\', "phone"= \'{{Table2.updatedRow.phone}}\', "email"= \'{{Table2.updatedRow.email}}\', "image"= \'{{Table2.updatedRow.image}}\', "country"= \'{{Table2.updatedRow.country}}\', "name"= \'{{Table2.updatedRow.name}}\' WHERE "id"= {{Table2.updatedRow.id}}; \n -- I am an SQL comment',
},
];
const outputs = [
{
body: `updatepublic.usersset"id"='',"gender"='',"latitude"='',"longitude"='',"dob"='',"phone"='',"email"='',"image"='',"country"='',"name"=''where"id"=;`,
},
{
paginationType: "none",
encodeParamsToggle: true,
body: `updatepublic.usersset"id"='',"gender"='',"latitude"='',"longitude"='',"dob"='',"phone"='',"email"='',"image"='',"country"='',"name"=''where"id"=;`,
selfReferencingDataPaths: [],
pluginSpecifiedTemplates: [{ value: false }],
},
{
paginationType: "none",
encodeParamsToggle: true,
selfReferencingDataPaths: [],
formData: {
aggregate: { limit: { data: "10" } },
smartSubstitution: { data: true },
insert: { documents: { data: "" } },
command: { data: "insert" },
collection: { data: "movies" },
},
},
{
timeoutInMillisecond: 10000.0,
paginationType: "none",
encodeParamsToggle: true,
selfReferencingDataPaths: [],
formData: { pageSize: "100", command: "", sort: "" },
},
{
body: `updatepublic.usersset"id"='',"gender"='',"latitude"='',"longitude"='',"dob"='',"phone"='',"email"='',"image"='',"country"='',"name"=''where"id"=;`,
},
];
inputs.forEach((input, index) => {
expect(cleanValuesInObjectForHashing(input)).toStrictEqual(
outputs[index],
);
});
});
it("tests the generateHashFromString function", async () => {
// verify that the same strings generate the same SHA1
const sameInputs = ["testString1", "testString1"];
const output1 = await generateHashFromString(sameInputs[0]);
const output2 = await generateHashFromString(sameInputs[1]);
expect(output1).toEqual(output2);
// verify that different strings generate different SHA1
const differentInputs = ["testString1", "testString2"];
const output3 = await generateHashFromString(differentInputs[0]);
const output4 = await generateHashFromString(differentInputs[1]);
expect(output3).not.toEqual(output4);
// verify that the SHA1 is the same in the future
// Note: There is something up with the algorithm, due to the it using
// ByteArrays and converting to hex strings
// If you google, the SHA1 for "testString", you get "956265657d0b637ef65b9b59f9f858eecf55ed6a"
// Nevertheless, for our purposes, this is fine
const testString = "testString";
const sha1fortestString = "21b695cef037e9a8e0b3edccac3e5e58271edf22";
const output = await generateHashFromString(testString);
expect(output).toEqual(sha1fortestString);
});
it("tests the generateHashFromString function with a complex object", async () => {
const input1 = {
body: 'UPDATE public.users SET "id"= \'{{Table2.updatedRow.id}}\', "gender"= \'{{Table2.updatedRow.gender}}\', "latitude"= \'{{Table2.updatedRow.latitude}}\', "longitude"= \'{{Table2.updatedRow.longitude}}\', "dob"= \'{{Table2.updatedRow.dob}}\', "phone"= \'{{Table2.updatedRow.phone}}\', "email"= \'{{Table2.updatedRow.email}}\', "image"= \'{{Table2.updatedRow.image}}\', "country"= \'{{Table2.updatedRow.country}}\', "name"= \'{{Table2.updatedRow.name}}\' WHERE "id"= {{Table2.updatedRow.id}}; \n -- I am an SQL comment',
};
const input2 = {
body: `UPDATE public.users SET "id"= \'{{Table2.updatedRow.id}}\', "gender"= \'{{Table2.updatedRow.gender}}\', "latitude"= \'{{Table2.updatedRow.latitude}}\', "longitude"= \'{{Table2.updatedRow.longitude}}\', "dob"= \'{{Table2.updatedRow.dob}}\', "phone"= \'{{Table2.updatedRow.phone}}\', "email"= \'{{Table2.updatedRow.email}}\', "image"= \'{{(() => { return "myvalue" })}}\', "country"= \'{{Table2.updatedRow.country}}\', "name"= \'{{GetQuery.updatedRow.name}}\' WHERE "id"= {{Table5.updatedRow.id}};`,
};
const cleanObjectInput1 = cleanValuesInObjectForHashing(input1);
const cleanObjectInput2 = cleanValuesInObjectForHashing(input2);
const hash1 = await generateHashFromString(
JSON.stringify(cleanObjectInput1),
);
const hash2 = await generateHashFromString(
JSON.stringify(cleanObjectInput2),
);
expect(hash1).toEqual(hash2);
});
feat: Store `originalActionId` as part of Action DTO for copied action (#25011) ## Description To measure the impact of query modules in Appsmith. We need to track the time a user takes to edit a copied query. Today, we do not have a mechanism to understand if a query in question is a copied query. To fix this, the data model of the Query action needs to change to include the `originalQueryId` if a query is, in fact, a copied query. - [ ] When a query is first copied, there will be no `originalActionId` in the action object. In this scenario, the client will populate the `originalActionId` field and call the POST API to create the copied query. - [ ] If the query is already a copied query, the client will duplicate the value of the `originalActionId` when calling the POST API to create the copied query. |POST|`/api/v1/actions`| ----------|------| ### [Related discussion on Notion](https://www.notion.so/appsmith/Backend-dependency-for-modules-instrumentation-889462d461844745be0a2599c8555ca5) #### PR fixes following issue(s) Fixes #24734 #### 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 > > > ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [x] Manual - [x] JUnit - [ ] 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 - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed > Pull Request Template > > Use this template to quickly create a well written pull request. Delete all quotes before creating the pull request. > ## Description > Add a TL;DR when description is extra long (helps content team) > > Please include a summary of the changes and which issue has been fixed. Please also include relevant motivation > and context. List any dependencies that are required for this change > > Links to Notion, Figma or any other documents that might be relevant to the PR > > #### PR fixes following issue(s) Fixes # (issue number) > 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 > > > ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [ ] 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: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed --------- Co-authored-by: Abhinav Jha <abhinav@appsmith.com>
2023-07-04 07:42:09 +00:00
});