diff --git a/app/server/appsmith-plugins/googleSheetsPlugin/src/main/java/com/external/utils/SheetsUtil.java b/app/server/appsmith-plugins/googleSheetsPlugin/src/main/java/com/external/utils/SheetsUtil.java index cae59d4c7f..91ebd3bfc0 100644 --- a/app/server/appsmith-plugins/googleSheetsPlugin/src/main/java/com/external/utils/SheetsUtil.java +++ b/app/server/appsmith-plugins/googleSheetsPlugin/src/main/java/com/external/utils/SheetsUtil.java @@ -34,6 +34,7 @@ public class SheetsUtil { public static Set getUserAuthorizedSheetIds(DatasourceConfiguration datasourceConfiguration) { OAuth2 oAuth2 = (OAuth2) datasourceConfiguration.getAuthentication(); if (!isEmpty(datasourceConfiguration.getProperties()) + && datasourceConfiguration.getProperties().size() > 1 && datasourceConfiguration.getProperties().get(USER_AUTHORIZED_SHEET_IDS_INDEX) != null && datasourceConfiguration.getProperties().get(USER_AUTHORIZED_SHEET_IDS_INDEX).getValue() != null && oAuth2.getScope() != null diff --git a/app/server/appsmith-plugins/googleSheetsPlugin/src/test/java/com/external/config/SheetsUtilTest.java b/app/server/appsmith-plugins/googleSheetsPlugin/src/test/java/com/external/config/SheetsUtilTest.java new file mode 100644 index 0000000000..e29d4b1bd5 --- /dev/null +++ b/app/server/appsmith-plugins/googleSheetsPlugin/src/test/java/com/external/config/SheetsUtilTest.java @@ -0,0 +1,54 @@ +package com.external.config; + +import com.appsmith.external.models.DatasourceConfiguration; +import com.appsmith.external.models.OAuth2; +import com.appsmith.external.models.Property; +import com.external.utils.SheetsUtil; +import com.fasterxml.jackson.core.JsonProcessingException; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.junit.jupiter.api.Test; + +public class SheetsUtilTest { + + @Test + public void testGetUserAuthorizedSheetIds_allsheets_returnsNull() throws JsonProcessingException { + DatasourceConfiguration dsConfig = new DatasourceConfiguration(); + List propList = new ArrayList(); + Property prop = new Property(); + prop.setKey("emailAddress"); + prop.setValue("test_email"); + propList.add(prop); + dsConfig.setProperties(propList); + Set result = SheetsUtil.getUserAuthorizedSheetIds(dsConfig); + assertEquals(result, null); + } + + @Test + public void testGetUserAuthorizedSheetIds_specificSheets_returnsSetOfFileIds() throws JsonProcessingException { + DatasourceConfiguration dsConfig = new DatasourceConfiguration(); + List propList = new ArrayList(); + OAuth2 oAuth2 = new OAuth2(); + + oAuth2.setScopeString("https://www.googleapis.com/auth/drive.file"); + dsConfig.setAuthentication(oAuth2); + + Property prop1 = new Property("emailAddress", "test_email"); + propList.add(prop1); + + List ids = new ArrayList(); + ids.add("id1"); + + Property prop2 = new Property("userAuthorizedSheetIds", ids); + propList.add(prop2); + + dsConfig.setProperties(propList); + Set result = SheetsUtil.getUserAuthorizedSheetIds(dsConfig); + assertEquals(result.size(), 1); + } +} \ No newline at end of file