From dbd98570a504902514ea0cab898a04caf880c52f Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Thu, 5 Dec 2024 10:05:25 +0530 Subject: [PATCH 1/7] Add include_types parameter --- .../wpcom/wc/product/ProductRestClient.kt | 12 +++++++---- .../android/fluxc/store/WCProductStore.kt | 21 ++++++++++++++++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/product/ProductRestClient.kt b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/product/ProductRestClient.kt index 2aeb1e80fa..908ca9ef65 100644 --- a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/product/ProductRestClient.kt +++ b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/product/ProductRestClient.kt @@ -534,7 +534,8 @@ class ProductRestClient @Inject constructor( excludedProductIds: List? = null, searchQuery: String? = null, skuSearchOptions: SkuSearchOptions = SkuSearchOptions.Disabled, - filterOptions: Map? = null + filterOptions: Map? = null, + includeTypes: List = emptyList() ): WooPayload> { val params = buildProductParametersMap( pageSize = pageSize, @@ -544,7 +545,8 @@ class ProductRestClient @Inject constructor( skuSearchOptions = skuSearchOptions, includedProductIds = includedProductIds, excludedProductIds = excludedProductIds, - filterOptions = filterOptions + filterOptions = filterOptions, + includeTypes = includeTypes, ) val url = WOOCOMMERCE.products.pathV3 @@ -585,7 +587,8 @@ class ProductRestClient @Inject constructor( skuSearchOptions: SkuSearchOptions, includedProductIds: List? = null, excludedProductIds: List? = null, - filterOptions: Map? = null + filterOptions: Map? = null, + includeTypes: List = emptyList() ): MutableMap { fun ProductSorting.asOrderByParameter() = when (this) { TITLE_ASC, TITLE_DESC -> "title" @@ -601,7 +604,8 @@ class ProductRestClient @Inject constructor( "per_page" to pageSize.toString(), "orderby" to sortType.asOrderByParameter(), "order" to sortType.asSortOrderParameter(), - "offset" to offset.toString() + "offset" to offset.toString(), + "include_types" to includeTypes.joinToString(",") { it.value } ) includedProductIds?.let { includedIds -> diff --git a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCProductStore.kt b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCProductStore.kt index b87c53948c..eeee057a4a 100644 --- a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCProductStore.kt +++ b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCProductStore.kt @@ -81,6 +81,23 @@ class WCProductStore @Inject constructor( const val VARIATIONS_CREATION_LIMIT = 100 } + sealed class IncludeType(val value: String) { + data object Simple : IncludeType("simple") + data object Variable : IncludeType("variable") + data object External : IncludeType("external") + data object Grouped : IncludeType("grouped") + + companion object { + fun fromValue(value: String): IncludeType? = when (value) { + "simple" -> Simple + "variable" -> Variable + "external" -> External + "grouped" -> Grouped + else -> null + } + } + } + /** * Defines the filter options currently supported in the app */ @@ -1586,6 +1603,7 @@ class WCProductStore @Inject constructor( includedProductIds: List = emptyList(), excludedProductIds: List = emptyList(), filterOptions: Map = emptyMap(), + includeTypes: List = emptyList(), forceRefresh: Boolean = true ): WooResult { return coroutineEngine.withDefaultContext(API, this, "fetchProducts") { @@ -1596,7 +1614,8 @@ class WCProductStore @Inject constructor( sortType = sortType, includedProductIds = includedProductIds, excludedProductIds = excludedProductIds, - filterOptions = filterOptions + filterOptions = filterOptions, + includeTypes = includeTypes, ) when { response.isError -> WooResult(response.error) From 57339f291b150a7ca9d8f144653db6922aa6fb09 Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Thu, 5 Dec 2024 10:06:15 +0530 Subject: [PATCH 2/7] Add test to verify that Simple type is returned --- .../android/fluxc/wc/product/WCProductStoreTest.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt b/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt index c12d71b49f..6410ca2fa6 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt @@ -27,12 +27,12 @@ import org.wordpress.android.fluxc.model.AccountModel import org.wordpress.android.fluxc.model.LocalOrRemoteId.RemoteId import org.wordpress.android.fluxc.model.ProductWithMetaData import org.wordpress.android.fluxc.model.SiteModel -import org.wordpress.android.fluxc.model.metadata.WCMetaData import org.wordpress.android.fluxc.model.WCProductCategoryModel import org.wordpress.android.fluxc.model.WCProductModel import org.wordpress.android.fluxc.model.WCProductReviewModel import org.wordpress.android.fluxc.model.WCProductVariationModel import org.wordpress.android.fluxc.model.WCProductVariationModel.ProductVariantOption +import org.wordpress.android.fluxc.model.metadata.WCMetaData import org.wordpress.android.fluxc.network.BaseRequest.GenericErrorType.NETWORK_ERROR import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooError import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooErrorType.GENERIC_ERROR @@ -830,4 +830,9 @@ class WCProductStoreTest { assertThat(storedProduct?.product).isEqualTo(product) assertThat(storedProduct?.metaData).isEqualTo(metadata) } + + @Test + fun `given include_type simple, then return type Simple` () { + assertThat(WCProductStore.IncludeType.fromValue("simple")).isEqualTo(WCProductStore.IncludeType.Simple) + } } From c12e8464e91ac6daa20253bb4cd9731c7b572f84 Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Thu, 5 Dec 2024 10:06:35 +0530 Subject: [PATCH 3/7] Add test to verify that Variable type is returned --- .../android/fluxc/wc/product/WCProductStoreTest.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt b/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt index 6410ca2fa6..1b85d21de2 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt @@ -27,12 +27,12 @@ import org.wordpress.android.fluxc.model.AccountModel import org.wordpress.android.fluxc.model.LocalOrRemoteId.RemoteId import org.wordpress.android.fluxc.model.ProductWithMetaData import org.wordpress.android.fluxc.model.SiteModel +import org.wordpress.android.fluxc.model.metadata.WCMetaData import org.wordpress.android.fluxc.model.WCProductCategoryModel import org.wordpress.android.fluxc.model.WCProductModel import org.wordpress.android.fluxc.model.WCProductReviewModel import org.wordpress.android.fluxc.model.WCProductVariationModel import org.wordpress.android.fluxc.model.WCProductVariationModel.ProductVariantOption -import org.wordpress.android.fluxc.model.metadata.WCMetaData import org.wordpress.android.fluxc.network.BaseRequest.GenericErrorType.NETWORK_ERROR import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooError import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooErrorType.GENERIC_ERROR @@ -835,4 +835,11 @@ class WCProductStoreTest { fun `given include_type simple, then return type Simple` () { assertThat(WCProductStore.IncludeType.fromValue("simple")).isEqualTo(WCProductStore.IncludeType.Simple) } + + @Test + fun `given include_type variable, then return type Variable` () { + assertThat( + WCProductStore.IncludeType.fromValue("variable") + ).isEqualTo(WCProductStore.IncludeType.Variable) + } } From 73dfc06838bc65951c7c0d6bb68d86446b74dbb3 Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Thu, 5 Dec 2024 10:06:52 +0530 Subject: [PATCH 4/7] Add test to verify that External type is returned --- .../android/fluxc/wc/product/WCProductStoreTest.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt b/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt index 1b85d21de2..16e2b99902 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt @@ -842,4 +842,11 @@ class WCProductStoreTest { WCProductStore.IncludeType.fromValue("variable") ).isEqualTo(WCProductStore.IncludeType.Variable) } + + @Test + fun `given include_type external, then return type External` () { + assertThat( + WCProductStore.IncludeType.fromValue("external") + ).isEqualTo(WCProductStore.IncludeType.External) + } } From 8bf715524946ff7ee7798e16874bce0e4499b42e Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Thu, 5 Dec 2024 10:07:07 +0530 Subject: [PATCH 5/7] Add test to verify that Grouped type is returned --- .../android/fluxc/wc/product/WCProductStoreTest.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt b/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt index 16e2b99902..71d21e070a 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt @@ -849,4 +849,11 @@ class WCProductStoreTest { WCProductStore.IncludeType.fromValue("external") ).isEqualTo(WCProductStore.IncludeType.External) } + + @Test + fun `given include_type grouped, then return type Grouped` () { + assertThat( + WCProductStore.IncludeType.fromValue("grouped") + ).isEqualTo(WCProductStore.IncludeType.Grouped) + } } From 6aaa1ad54212087e6ba2902bb36da3fc59a970be Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Thu, 5 Dec 2024 10:07:31 +0530 Subject: [PATCH 6/7] Add test to verify that empty type is handled --- .../android/fluxc/wc/product/WCProductStoreTest.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt b/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt index 71d21e070a..47b9b409e4 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt @@ -856,4 +856,11 @@ class WCProductStoreTest { WCProductStore.IncludeType.fromValue("grouped") ).isEqualTo(WCProductStore.IncludeType.Grouped) } + + @Test + fun `given include_type empty, then return type null` () { + assertThat( + WCProductStore.IncludeType.fromValue("") + ).isNull() + } } From 4ad2e36e22e0b3cd5413689f8e1c3ddd5d776a46 Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Thu, 5 Dec 2024 10:07:42 +0530 Subject: [PATCH 7/7] Add test to verify that invalid type is handled --- .../android/fluxc/wc/product/WCProductStoreTest.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt b/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt index 47b9b409e4..c79ad951ea 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt @@ -863,4 +863,11 @@ class WCProductStoreTest { WCProductStore.IncludeType.fromValue("") ).isNull() } + + @Test + fun `given include_type invalid, then return type null` () { + assertThat( + WCProductStore.IncludeType.fromValue("invalid") + ).isNull() + } }