Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TESTING EXTERNAL SCRIPT: external merge request from Contributor #35948

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import reactor.util.function.Tuple2;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -128,19 +129,23 @@ public Mono<TriggerResultDTO> trigger(
entitySelectorTriggerSolution(datasourceId, triggerRequestDTO, trueEnvironmentId))
.map(Tuple2::getT2))
.map(entityNames -> {
List<Object> result = new ArrayList<>();
List<Map<String, String>> result = new ArrayList<>();

if (ClientDataDisplayType.DROP_DOWN.equals(displayType)) {
// label, value
// Create maps and add them to the result list
for (String entityName : entityNames) {
Map<String, String> entity = new HashMap<>();
entity.put("label", entityName);
entity.put("value", entityName);
result.add(entity);
}
// Sort the list of maps based on the 'label' value
result.sort(Comparator.comparing(
entity -> entity.get("label").toLowerCase()));
}

return new TriggerResultDTO(result);
// Convert the result into a list of objects
List<Object> objectResult = new ArrayList<>(result);
return new TriggerResultDTO(objectResult);
});

return resultFromPluginMono.switchIfEmpty(defaultResultMono);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,71 @@ public void datasourceTriggerTest() {
})
.verifyComplete();
}

@Test
@WithUserDetails(value = "api_user")
public void datasourceTriggerTest_should_return_collections_inorder() {
Mockito.when(pluginExecutorHelper.getPluginExecutor(Mockito.any()))
.thenReturn(Mono.just(new MockPluginExecutor()));

DatasourceStructure.Column[] table1Columns = {
new DatasourceStructure.Column("_id1", "ObjectId", null, true),
new DatasourceStructure.Column("age1", "Integer", null, false),
new DatasourceStructure.Column("dob1", "Date", null, false),
new DatasourceStructure.Column("gender1", "String", null, false),
new DatasourceStructure.Column("luckyNumber1", "Long", null, false),
new DatasourceStructure.Column("name1", "String", null, false),
new DatasourceStructure.Column("netWorth1", "BigDecimal", null, false),
new DatasourceStructure.Column("updatedByCommand1", "Object", null, false),
};

DatasourceStructure.Table table1 =
new DatasourceStructure.Table(TABLE, null, "Table1", List.of(table1Columns), null, null);

DatasourceStructure.Column[] table2Columns = {
new DatasourceStructure.Column("_id2", "ObjectId", null, true),
new DatasourceStructure.Column("age2", "Integer", null, false),
new DatasourceStructure.Column("dob2", "Date", null, false),
new DatasourceStructure.Column("gender2", "String", null, false),
new DatasourceStructure.Column("luckyNumber2", "Long", null, false),
new DatasourceStructure.Column("name2", "String", null, false),
new DatasourceStructure.Column("netWorth2", "BigDecimal", null, false),
new DatasourceStructure.Column("updatedByCommand2", "Object", null, false),
};

DatasourceStructure.Table table2 =
new DatasourceStructure.Table(TABLE, null, "Table2", List.of(table2Columns), null, null);

DatasourceStructure testStructure = new DatasourceStructure(List.of(table1, table2));

Mockito.when(datasourceStructureSolution.getStructure(Mockito.anyString(), Mockito.anyBoolean(), Mockito.any()))
.thenReturn(Mono.just(testStructure));

datasourceService
.findById(datasourceId, datasourcePermission.getReadPermission())
.block();
Mockito.doReturn(Mono.just(Boolean.TRUE)).when(featureFlagService).check(Mockito.any());

Mono<TriggerResultDTO> tableNameMono = datasourceTriggerSolution.trigger(
datasourceId,
defaultEnvironmentId,
new TriggerRequestDTO("ENTITY_SELECTOR", Map.of(), ClientDataDisplayType.DROP_DOWN));

Mono<TriggerResultDTO> columnNamesMono = datasourceTriggerSolution.trigger(
datasourceId,
defaultEnvironmentId,
new TriggerRequestDTO(
"ENTITY_SELECTOR", Map.of("tableName", "Table1"), ClientDataDisplayType.DROP_DOWN));

StepVerifier.create(tableNameMono)
.assertNext(tablesResult -> {
List<Map<String, String>> tables = (List<Map<String, String>>) tablesResult.getTrigger();

assertEquals(2, tables.size());
// Check the order of the tables
assertEquals("Table1", tables.get(0).get("label"));
assertEquals("Table2", tables.get(1).get("label"));
})
.verifyComplete();
}
}
Loading