Skip to content

Commit

Permalink
test: CGS connect negative tests (#38120)
Browse files Browse the repository at this point in the history
## 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=""

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!CAUTION]  
> If you modify the content in this section, you are likely to disrupt
the CI result for your PR.

<!-- 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**
- Enhanced error handling for Git operations, providing more detailed
feedback during failures.
- Added unit tests for connecting artifacts to Git repositories,
covering various error scenarios and permissions.

- **Bug Fixes**
- Improved error reporting for Git operations to include specific error
messages.

- **Tests**
- Introduced new test methods for validating action executions and
layout updates.
- Expanded coverage for error handling related to dynamic bindings and
action execution logic.

- **Chores**
  - Clean-up logic added to maintain test state.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
nidhi-nair authored Dec 12, 2024
1 parent 0808b27 commit af32283
Show file tree
Hide file tree
Showing 4 changed files with 505 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,27 +371,7 @@ public Mono<? extends Artifact> connectArtifactToGit(
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ORIGIN));
}

Mono<UserData> currentUserMono = userDataService
.getForCurrentUser()
.filter(userData -> !CollectionUtils.isEmpty(userData.getGitProfiles()))
.switchIfEmpty(
Mono.error(new AppsmithException(AppsmithError.INVALID_GIT_CONFIGURATION, GIT_PROFILE_ERROR)));

Mono<GitUser> gitUserMono = currentUserMono
.map(userData -> {
GitProfile profile = userData.getGitProfileByKey(baseArtifactId);
if (profile == null
|| Boolean.TRUE.equals(profile.getUseGlobalProfile())
|| !StringUtils.hasText(profile.getAuthorName())) {
profile = userData.getGitProfileByKey(DEFAULT);
}

GitUser gitUser = new GitUser();
gitUser.setName(profile.getAuthorName());
gitUser.setEmail(profile.getAuthorEmail());
return gitUser;
})
.cache();
Mono<GitUser> gitUserMono = getGitUserForArtifactId(baseArtifactId);

Mono<Map<String, GitProfile>> profileMono = gitProfileUtils
.updateOrCreateGitProfileForCurrentUser(gitConnectDTO.getGitProfile(), baseArtifactId)
Expand Down Expand Up @@ -441,9 +421,10 @@ public Mono<? extends Artifact> connectArtifactToGit(
.onErrorResume(error -> {
log.error("Error while cloning the remote repo, ", error);

AppsmithException appsmithException =
new AppsmithException(AppsmithError.GIT_GENERIC_ERROR, error.getMessage());
if (error instanceof TransportException) {
AppsmithException appsmithException = null;
if (error instanceof AppsmithException e) {
appsmithException = e;
} else if (error instanceof TransportException) {
appsmithException =
new AppsmithException(AppsmithError.INVALID_GIT_SSH_CONFIGURATION);
} else if (error instanceof InvalidRemoteException) {
Expand All @@ -458,6 +439,9 @@ public Mono<? extends Artifact> connectArtifactToGit(
appsmithException =
new AppsmithException(AppsmithError.INVALID_GIT_SSH_URL);
}
} else {
appsmithException = new AppsmithException(
AppsmithError.GIT_GENERIC_ERROR, error.getMessage());
}

ArtifactJsonTransformationDTO jsonTransformationDTO =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ public Mono<String> fetchRemoteRepository(
} else if (error instanceof TimeoutException) {
return Mono.error(new AppsmithException(AppsmithError.GIT_EXECUTION_TIMEOUT));
}
return Mono.error(
new AppsmithException(AppsmithError.GIT_ACTION_FAILED, "clone", error));
return Mono.error(new AppsmithException(
AppsmithError.GIT_ACTION_FAILED, "clone", error.getMessage()));
});
});
}
Expand Down Expand Up @@ -325,13 +325,16 @@ public Mono<String> createFirstCommit(ArtifactJsonTransformationDTO jsonTransfor
jsonTransformationDTO.getBaseArtifactId(),
jsonTransformationDTO.getRepoName());

return fsGitHandler.commitArtifact(
repoSuffix,
commitDTO.getMessage(),
commitDTO.getAuthor().getName(),
commitDTO.getAuthor().getEmail(),
true,
commitDTO.getIsAmendCommit());
return fsGitHandler
.commitArtifact(
repoSuffix,
commitDTO.getMessage(),
commitDTO.getAuthor().getName(),
commitDTO.getAuthor().getEmail(),
true,
commitDTO.getIsAmendCommit())
.onErrorResume(error -> Mono.error(
new AppsmithException(AppsmithError.GIT_ACTION_FAILED, "commit", error.getMessage())));
}

@Override
Expand Down
Loading

0 comments on commit af32283

Please sign in to comment.