From a3555e8949dea442273ddef57c1078a4bf495e6c Mon Sep 17 00:00:00 2001 From: Alejo Date: Thu, 5 Sep 2024 20:24:33 -0600 Subject: [PATCH 1/5] update FluxC version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 4a70901dabe..77b9ec0d5e7 100644 --- a/build.gradle +++ b/build.gradle @@ -100,7 +100,7 @@ tasks.register("installGitHooks", Copy) { } ext { - fluxCVersion = 'trunk-3d8b46e8151493d563fd519c4406a5b83bc95255' + fluxCVersion = '3090-3d6d1df2e25d7ea902359f75488bd95541c23df3' glideVersion = '4.16.0' coilVersion = '2.1.0' constraintLayoutVersion = '1.2.0' From e4fdcf2d31642f91397b757ac909711b327a8aea Mon Sep 17 00:00:00 2001 From: Alejo Date: Thu, 5 Sep 2024 20:25:20 -0600 Subject: [PATCH 2/5] check list state to update the list --- .../ui/orders/list/ShouldUpdateOrdersList.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/list/ShouldUpdateOrdersList.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/list/ShouldUpdateOrdersList.kt index e021e79f674..60b521be033 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/list/ShouldUpdateOrdersList.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/list/ShouldUpdateOrdersList.kt @@ -2,12 +2,21 @@ package com.woocommerce.android.ui.orders.list import com.woocommerce.android.background.LastUpdateDataStore import kotlinx.coroutines.flow.first +import org.wordpress.android.fluxc.model.list.ListDescriptor +import org.wordpress.android.fluxc.model.list.ListState +import org.wordpress.android.fluxc.store.ListStore import javax.inject.Inject -class ShouldUpdateOrdersList @Inject constructor(private val lastUpdateDataStore: LastUpdateDataStore) { - suspend operator fun invoke(listId: Int): Boolean { - return lastUpdateDataStore.getLastUpdateKeyByOrdersListId(listId).let { key -> +class ShouldUpdateOrdersList @Inject constructor( + private val lastUpdateDataStore: LastUpdateDataStore, + private val listStore: ListStore +) { + suspend operator fun invoke(listDescriptor: ListDescriptor): Boolean { + val listId = listDescriptor.uniqueIdentifier.value + val shouldUpdateByState= listStore.getListState(listDescriptor) == ListState.NEEDS_REFRESH + val shouldUpdateByCache = lastUpdateDataStore.getLastUpdateKeyByOrdersListId(listId).let { key -> lastUpdateDataStore.shouldUpdateData(key).first() } + return shouldUpdateByState || shouldUpdateByCache } } From 424ab5ef023c60dde4499a21c30fa4bab3b0ba2a Mon Sep 17 00:00:00 2001 From: Alejo Date: Thu, 5 Sep 2024 20:26:18 -0600 Subject: [PATCH 3/5] refactor listId -> listDescriptor --- .../woocommerce/android/ui/orders/list/OrderListViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/list/OrderListViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/list/OrderListViewModel.kt index eafebf73832..15690ff1ea3 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/list/OrderListViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/list/OrderListViewModel.kt @@ -270,7 +270,7 @@ class OrderListViewModel @Inject constructor( ) val listId = listDescriptor.uniqueIdentifier.value launch { - if (shouldUpdateOrdersList(listId)) { + if (shouldUpdateOrdersList(listDescriptor)) { fetchOrdersAndOrderDependencies() } else { // List is displayed from cache From ef9b1aa002c152608a7e8b6be798f758ff808cd7 Mon Sep 17 00:00:00 2001 From: Alejo Date: Thu, 5 Sep 2024 20:26:35 -0600 Subject: [PATCH 4/5] update unit tests --- .../ShouldUpdateOrdersListByStoreIdTest.kt | 55 +++++++++++++++++-- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/list/ShouldUpdateOrdersListByStoreIdTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/list/ShouldUpdateOrdersListByStoreIdTest.kt index 5620dd2e47e..17acf93ac77 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/list/ShouldUpdateOrdersListByStoreIdTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/list/ShouldUpdateOrdersListByStoreIdTest.kt @@ -11,33 +11,78 @@ import org.mockito.kotlin.doReturn import org.mockito.kotlin.eq import org.mockito.kotlin.mock import org.mockito.kotlin.whenever +import org.wordpress.android.fluxc.model.WCOrderListDescriptor +import org.wordpress.android.fluxc.model.list.ListDescriptorUniqueIdentifier +import org.wordpress.android.fluxc.model.list.ListState +import org.wordpress.android.fluxc.store.ListStore import kotlin.test.assertTrue @OptIn(ExperimentalCoroutinesApi::class) class ShouldUpdateOrdersListByStoreIdTest : BaseUnitTest() { private val lastUpdateDataStore: LastUpdateDataStore = mock() - val sut = ShouldUpdateOrdersList(lastUpdateDataStore) + private val lisStore: ListStore = mock() + val sut = ShouldUpdateOrdersList(lastUpdateDataStore, lisStore) @Test - fun `when should update return true, then the result is the expected`() = testBlocking { + fun `when should update return true and list state is not refresh, then the result is the expected`() = testBlocking { val listId = 1 val key = "key-1" + val listDescriptor: WCOrderListDescriptor = mock{ + on { uniqueIdentifier }.doReturn(ListDescriptorUniqueIdentifier(listId)) + } whenever(lastUpdateDataStore.getLastUpdateKeyByOrdersListId(eq(listId))).doReturn(key) whenever(lastUpdateDataStore.shouldUpdateData(eq(key), any())).doReturn(flowOf(true)) + whenever(lisStore.getListState(eq(listDescriptor))).doReturn(ListState.CAN_LOAD_MORE) - val result = sut.invoke(listId) + val result = sut.invoke(listDescriptor) assertTrue(result) } @Test - fun `when should update return false, then the result is the expected`() = testBlocking { + fun `when should update return true and list state is refresh, then the result is the expected`() = testBlocking { val listId = 1 val key = "key-1" + val listDescriptor: WCOrderListDescriptor = mock{ + on { uniqueIdentifier }.doReturn(ListDescriptorUniqueIdentifier(listId)) + } + whenever(lastUpdateDataStore.getLastUpdateKeyByOrdersListId(eq(listId))).doReturn(key) + whenever(lastUpdateDataStore.shouldUpdateData(eq(key), any())).doReturn(flowOf(true)) + whenever(lisStore.getListState(eq(listDescriptor))).doReturn(ListState.NEEDS_REFRESH) + + val result = sut.invoke(listDescriptor) + + assertTrue(result) + } + + @Test + fun `when should update return false and list state is refresh, then the result is the expected`() = testBlocking { + val listId = 1 + val key = "key-1" + val listDescriptor: WCOrderListDescriptor = mock{ + on { uniqueIdentifier }.doReturn(ListDescriptorUniqueIdentifier(listId)) + } + whenever(lastUpdateDataStore.getLastUpdateKeyByOrdersListId(eq(listId))).doReturn(key) + whenever(lastUpdateDataStore.shouldUpdateData(eq(key), any())).doReturn(flowOf(false)) + whenever(lisStore.getListState(eq(listDescriptor))).doReturn(ListState.NEEDS_REFRESH) + + val result = sut.invoke(listDescriptor) + + assertTrue(result) + } + + @Test + fun `when should update return false and list state is not refresh, then the result is the expected`() = testBlocking { + val listId = 1 + val key = "key-1" + val listDescriptor: WCOrderListDescriptor = mock{ + on { uniqueIdentifier }.doReturn(ListDescriptorUniqueIdentifier(listId)) + } whenever(lastUpdateDataStore.getLastUpdateKeyByOrdersListId(eq(listId))).doReturn(key) whenever(lastUpdateDataStore.shouldUpdateData(eq(key), any())).doReturn(flowOf(false)) + whenever(lisStore.getListState(eq(listDescriptor))).doReturn(ListState.CAN_LOAD_MORE) - val result = sut.invoke(listId) + val result = sut.invoke(listDescriptor) assertFalse(result) } From 0dfce14a244ea3967739d956ae233794fccdc41e Mon Sep 17 00:00:00 2001 From: Alejo Date: Thu, 5 Sep 2024 20:36:25 -0600 Subject: [PATCH 5/5] fix detekt issues --- .../android/ui/orders/list/ShouldUpdateOrdersList.kt | 2 +- .../ui/orders/list/ShouldUpdateOrdersListByStoreIdTest.kt | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/list/ShouldUpdateOrdersList.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/list/ShouldUpdateOrdersList.kt index 60b521be033..c51912fc1dd 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/list/ShouldUpdateOrdersList.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/list/ShouldUpdateOrdersList.kt @@ -13,7 +13,7 @@ class ShouldUpdateOrdersList @Inject constructor( ) { suspend operator fun invoke(listDescriptor: ListDescriptor): Boolean { val listId = listDescriptor.uniqueIdentifier.value - val shouldUpdateByState= listStore.getListState(listDescriptor) == ListState.NEEDS_REFRESH + val shouldUpdateByState = listStore.getListState(listDescriptor) == ListState.NEEDS_REFRESH val shouldUpdateByCache = lastUpdateDataStore.getLastUpdateKeyByOrdersListId(listId).let { key -> lastUpdateDataStore.shouldUpdateData(key).first() } diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/list/ShouldUpdateOrdersListByStoreIdTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/list/ShouldUpdateOrdersListByStoreIdTest.kt index 17acf93ac77..0b5d8a1c02c 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/list/ShouldUpdateOrdersListByStoreIdTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/list/ShouldUpdateOrdersListByStoreIdTest.kt @@ -27,7 +27,7 @@ class ShouldUpdateOrdersListByStoreIdTest : BaseUnitTest() { fun `when should update return true and list state is not refresh, then the result is the expected`() = testBlocking { val listId = 1 val key = "key-1" - val listDescriptor: WCOrderListDescriptor = mock{ + val listDescriptor: WCOrderListDescriptor = mock { on { uniqueIdentifier }.doReturn(ListDescriptorUniqueIdentifier(listId)) } whenever(lastUpdateDataStore.getLastUpdateKeyByOrdersListId(eq(listId))).doReturn(key) @@ -43,7 +43,7 @@ class ShouldUpdateOrdersListByStoreIdTest : BaseUnitTest() { fun `when should update return true and list state is refresh, then the result is the expected`() = testBlocking { val listId = 1 val key = "key-1" - val listDescriptor: WCOrderListDescriptor = mock{ + val listDescriptor: WCOrderListDescriptor = mock { on { uniqueIdentifier }.doReturn(ListDescriptorUniqueIdentifier(listId)) } whenever(lastUpdateDataStore.getLastUpdateKeyByOrdersListId(eq(listId))).doReturn(key) @@ -59,7 +59,7 @@ class ShouldUpdateOrdersListByStoreIdTest : BaseUnitTest() { fun `when should update return false and list state is refresh, then the result is the expected`() = testBlocking { val listId = 1 val key = "key-1" - val listDescriptor: WCOrderListDescriptor = mock{ + val listDescriptor: WCOrderListDescriptor = mock { on { uniqueIdentifier }.doReturn(ListDescriptorUniqueIdentifier(listId)) } whenever(lastUpdateDataStore.getLastUpdateKeyByOrdersListId(eq(listId))).doReturn(key) @@ -75,7 +75,7 @@ class ShouldUpdateOrdersListByStoreIdTest : BaseUnitTest() { fun `when should update return false and list state is not refresh, then the result is the expected`() = testBlocking { val listId = 1 val key = "key-1" - val listDescriptor: WCOrderListDescriptor = mock{ + val listDescriptor: WCOrderListDescriptor = mock { on { uniqueIdentifier }.doReturn(ListDescriptorUniqueIdentifier(listId)) } whenever(lastUpdateDataStore.getLastUpdateKeyByOrdersListId(eq(listId))).doReturn(key)