chore: Fixed flaky test in partial export service (#30000)

## Description
Fixes flaky tests in partial export service.

#### 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
- [ ] 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
- [ ] 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


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

## Summary by CodeRabbit

- **Tests**
- Enhanced existing tests for partial export functionality to ensure
robustness and reliability.
	- Updated test assertions for better clarity and maintainability.


<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Nayan 2024-01-03 19:53:56 +06:00 committed by GitHub
parent 68b3b1ef1f
commit e3e7623cae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,7 @@ import com.appsmith.external.models.ActionDTO;
import com.appsmith.external.models.DBAuth;
import com.appsmith.external.models.Datasource;
import com.appsmith.external.models.DatasourceConfiguration;
import com.appsmith.external.models.DatasourceStorage;
import com.appsmith.external.models.DatasourceStorageDTO;
import com.appsmith.external.models.DefaultResources;
import com.appsmith.external.models.Property;
@ -12,6 +13,7 @@ import com.appsmith.server.applications.base.ApplicationService;
import com.appsmith.server.datasources.base.DatasourceService;
import com.appsmith.server.domains.Application;
import com.appsmith.server.domains.GitApplicationMetadata;
import com.appsmith.server.domains.NewAction;
import com.appsmith.server.domains.Plugin;
import com.appsmith.server.domains.User;
import com.appsmith.server.domains.Workspace;
@ -206,9 +208,6 @@ public class PartialExportServiceTest {
datasourceMap.put("DS1", ds1);
datasourceMap.put("DS2", ds2);
isSetupDone = true;
Mockito.when(pluginService.findAllByIdsWithoutPermission(Mockito.any(), Mockito.anyList()))
.thenReturn(Flux.fromIterable(List.of(installedPlugin, installedJsPlugin)));
}
private Application createGitConnectedApp(String applicationName) {
@ -237,6 +236,9 @@ public class PartialExportServiceTest {
@Test
@WithUserDetails(value = "api_user")
void testGetPartialExport_nonGitConnectedApp_success() {
Mockito.when(pluginService.findAllByIdsWithoutPermission(Mockito.any(), Mockito.anyList()))
.thenReturn(Flux.fromIterable(List.of(installedPlugin, installedJsPlugin)));
// Create an application with all resources
Application testApplication = new Application();
testApplication.setName("testGetPartialExport_nonGitConnectedApp_success");
@ -263,10 +265,10 @@ public class PartialExportServiceTest {
StepVerifier.create(partialExportFileDTOMono)
.assertNext(applicationJson -> {
assertThat(applicationJson.getDatasourceList().size()).isEqualTo(2);
assertThat(applicationJson.getDatasourceList().get(0).getName())
.isEqualTo("DS1");
assertThat(applicationJson.getDatasourceList().get(1).getName())
.isEqualTo("DS2");
List<String> dsNames = applicationJson.getDatasourceList().stream()
.map(DatasourceStorage::getName)
.toList();
assertThat(dsNames).containsAll(List.of("DS1", "DS2"));
assertThat(applicationJson.getDatasourceList().get(0).getPluginId())
.isEqualTo("installed-plugin");
assertThat(applicationJson.getDatasourceList().get(1).getPluginId())
@ -278,6 +280,9 @@ public class PartialExportServiceTest {
@Test
@WithUserDetails(value = "api_user")
public void testGetPartialExport_gitConnectedApp_branchResourceExported() {
Mockito.when(pluginService.findAllByIdsWithoutPermission(Mockito.any(), Mockito.anyList()))
.thenReturn(Flux.fromIterable(List.of(installedPlugin, installedJsPlugin)));
Application application = createGitConnectedApp("testGetPartialExport_gitConnectedApp_branchResourceExported");
// update git branch name for page
@ -318,28 +323,20 @@ public class PartialExportServiceTest {
StepVerifier.create(partialExportFileDTOMono)
.assertNext(applicationJson -> {
assertThat(applicationJson.getDatasourceList().size()).isEqualTo(2);
assertThat(applicationJson.getDatasourceList().get(0).getName())
.isEqualTo("DS1");
assertThat(applicationJson.getDatasourceList().get(1).getName())
.isEqualTo("DS2");
List<String> dsNames = applicationJson.getDatasourceList().stream()
.map(DatasourceStorage::getName)
.toList();
assertThat(dsNames).containsAll(List.of("DS1", "DS2"));
assertThat(applicationJson.getDatasourceList().get(0).getPluginId())
.isEqualTo("installed-plugin");
assertThat(applicationJson.getDatasourceList().get(1).getPluginId())
.isEqualTo("installed-plugin");
assertThat(applicationJson.getActionList().size()).isEqualTo(1);
assertThat(applicationJson
.getActionList()
.get(0)
.getUnpublishedAction()
.getName())
.isEqualTo("validAction");
assertThat(applicationJson
.getActionList()
.get(0)
.getUnpublishedAction()
.getPageId())
.isEqualTo("Page 2");
assertThat(applicationJson.getActionList().get(0).getId()).isEqualTo("Page 2_validAction");
NewAction newAction = applicationJson.getActionList().get(0);
assertThat(newAction.getUnpublishedAction().getName()).isEqualTo("validAction");
assertThat(newAction.getUnpublishedAction().getPageId()).isEqualTo("Page 2");
assertThat(newAction.getId()).isEqualTo("Page 2_validAction");
})
.verifyComplete();
}