Skip to content

Commit

Permalink
fix: git auto generate header issue fixed (#33016)
Browse files Browse the repository at this point in the history
## Description
The autoGeneratedHeaders property in actionConfiguration is
unnecessarily getting introduced as git changes. This PR fixes that
issue.

With current implementation, In a git connected application, when we
create any action and bind it to table widget, once we successfully
commit these changes, after surfing the application without making any
changes, we can see new changes to be committed for git and in those
changes we can see `autoGeneratedHeaders: []` inside
actionConfiguration. This issue has been fixed by initialising the field
by default when we create action.

<img width="932" alt="gittest"
src="https://github.com/appsmithorg/appsmith/assets/30018882/9d76ab45-7cb4-4aa4-ba44-baf19a1f38e0">


Redux unit tests have been added to assert the fix


Fixes #27941 
_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.Datasource"

### 🔍 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/8874903423>
> Commit: 769749d
> Cypress dashboard url: <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=8874903423&attempt=1"
target="_blank">Click here!</a>

<!-- 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**
- Enhanced API and GraphQL editors with support for auto-generated
headers to streamline configuration processes.
- **Tests**
- Added new tests to ensure the reliability of API configuration
functionalities.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: “sneha122” <“sneha@appsmith.com”>
  • Loading branch information
sneha122 and “sneha122” committed Apr 30, 2024
1 parent 0d89168 commit 32cbf2d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const DEFAULT_API_ACTION_CONFIG: ApiActionConfig = {
httpVersion: DEFAULT_HTTP_VERSION_TYPE,
headers: EMPTY_KEY_VALUE_PAIRS.slice(),
queryParameters: EMPTY_KEY_VALUE_PAIRS.slice(),
autoGeneratedHeaders: [],
body: "",
bodyFormData: [],
formData: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const DEFAULT_GRAPHQL_ACTION_CONFIG: ApiActionConfig = {
formData: {
apiContentType: POST_BODY_FORMAT_OPTIONS.JSON,
},
autoGeneratedHeaders: [],
pluginSpecifiedTemplates: [
{
// JSON smart substitution
Expand Down
52 changes: 52 additions & 0 deletions app/client/src/sagas/__tests__/ApiPaneSagas.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { CreateApiActionDefaultsParams } from "entities/Action";
import { createDefaultApiActionPayload } from "sagas/ApiPaneSagas";

describe("tests the sagas in ApiPaneSagas", () => {
const inputPayload: CreateApiActionDefaultsParams = {
apiType: "graphql-plugin",
newActionName: "newName",
};

it("1. Bug 27941: Tests createDefaultApiActionPayload to return prepopulated empty array for autoGeneratedHeaders", function () {
const outputPayloadGenerator: Generator =
createDefaultApiActionPayload(inputPayload);

// Mocking getCurrentWorkspaceId selector
const workspaceIdSelectorEffect = outputPayloadGenerator.next().value;
workspaceIdSelectorEffect.payload.selector = jest.fn();
workspaceIdSelectorEffect.payload.selector.mockReturnValue(
"testWorkspaceId",
);

// Mock getPluginIdOfPackageName selector
const pluginIdSelectorEffect = outputPayloadGenerator.next().value;
pluginIdSelectorEffect.payload.selector = jest.fn();
pluginIdSelectorEffect.payload.selector.mockReturnValue("pluginId");

// Get actionconfig value now
const outputPayload = outputPayloadGenerator.next().value;
expect(outputPayload?.actionConfiguration.autoGeneratedHeaders).toEqual([]);
});

it("2. Bug 27941: Tests createDefaultApiActionPayload to return prepopulated empty array for autoGeneratedHeaders", function () {
inputPayload.apiType = "restapi-plugin";
const outputPayloadGenerator: Generator =
createDefaultApiActionPayload(inputPayload);

// Mocking getCurrentWorkspaceId selector
const workspaceIdSelectorEffect = outputPayloadGenerator.next().value;
workspaceIdSelectorEffect.payload.selector = jest.fn();
workspaceIdSelectorEffect.payload.selector.mockReturnValue(
"testWorkspaceId",
);

// Mock getPluginIdOfPackageName selector
const pluginIdSelectorEffect = outputPayloadGenerator.next().value;
pluginIdSelectorEffect.payload.selector = jest.fn();
pluginIdSelectorEffect.payload.selector.mockReturnValue("pluginId");

// Get actionconfig value now
const outputPayload = outputPayloadGenerator.next().value;
expect(outputPayload?.actionConfiguration.autoGeneratedHeaders).toEqual([]);
});
});

0 comments on commit 32cbf2d

Please sign in to comment.