From c9868ad8c7224bff2168f0cbc68ad26122cbc194 Mon Sep 17 00:00:00 2001 From: ashiagr Date: Mon, 17 Jan 2022 14:52:26 +0530 Subject: [PATCH 1/8] Feature: Create stats card response and model --- .../fluxc/model/dashboard/CardModel.kt | 11 +++++++ .../rest/wpcom/dashboard/CardsRestClient.kt | 31 +++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/model/dashboard/CardModel.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/model/dashboard/CardModel.kt index 3cbfd27b63..4d0bfb34e6 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/model/dashboard/CardModel.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/model/dashboard/CardModel.kt @@ -8,9 +8,20 @@ sealed class CardModel( enum class Type( val classOf: Class<*> ) { + STATS(StatsCardModel::class.java), POSTS(PostsCardModel::class.java) } + data class StatsCardModel( + val todaysStats: TodaysStatsModel + ) : CardModel(Type.STATS) { + data class TodaysStatsModel( + val views: Int, + val visitors: Int, + val likes: Int + ) + } + data class PostsCardModel( val hasPublished: Boolean, val draft: List, diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClient.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClient.kt index 6c7422d2ce..38319e947d 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClient.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClient.kt @@ -6,8 +6,11 @@ import com.google.gson.annotations.SerializedName import org.wordpress.android.fluxc.Dispatcher import org.wordpress.android.fluxc.generated.endpoint.WPCOMV2 import org.wordpress.android.fluxc.model.SiteModel +import org.wordpress.android.fluxc.model.dashboard.CardModel import org.wordpress.android.fluxc.model.dashboard.CardModel.PostsCardModel import org.wordpress.android.fluxc.model.dashboard.CardModel.PostsCardModel.PostCardModel +import org.wordpress.android.fluxc.model.dashboard.CardModel.StatsCardModel +import org.wordpress.android.fluxc.model.dashboard.CardModel.StatsCardModel.TodaysStatsModel import org.wordpress.android.fluxc.network.BaseRequest.GenericErrorType import org.wordpress.android.fluxc.network.UserAgent import org.wordpress.android.fluxc.network.rest.wpcom.BaseWPComRestClient @@ -47,10 +50,32 @@ class CardsRestClient @Inject constructor( } data class CardsResponse( - @SerializedName("posts") val posts: PostsResponse + @SerializedName("stats") val stats: StatsResponse? = null, + @SerializedName("posts") val posts: PostsResponse? = null ) { - fun toCards() = listOf( - posts.toPosts() + fun toCards() = arrayListOf().apply { + stats?.let { add(it.toStatsCard()) } + posts?.let { add(it.toPosts()) } + }.toList() + } + + data class StatsResponse( + @SerializedName("todays_stats") val todaysStatsResponse: TodaysStatsResponse + ) { + fun toStatsCard() = StatsCardModel( + todaysStats = todaysStatsResponse.toTodaysStats() + ) + } + + data class TodaysStatsResponse( + @SerializedName("views") val views: Int? = null, + @SerializedName("visitors") val visitors: Int? = null, + @SerializedName("likes") val likes: Int? = null + ) { + fun toTodaysStats() = TodaysStatsModel( + views = views ?: 0, + visitors = visitors ?: 0, + likes = likes ?: 0 ) } From 76fc2372cbdbbd93c1872c324ba203427b309326 Mon Sep 17 00:00:00 2001 From: ashiagr Date: Mon, 17 Jan 2022 17:32:40 +0530 Subject: [PATCH 2/8] Tests: Update cards rest client tests to include stats card response --- .../rest/wpcom/dashboard/CardsRestClientTest.kt | 13 +++++++++++++ example/src/test/resources/wp/dashboard/cards.json | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClientTest.kt b/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClientTest.kt index 4014d63439..7feb401a67 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClientTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClientTest.kt @@ -31,6 +31,8 @@ import org.wordpress.android.fluxc.network.rest.wpcom.auth.AccessToken import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.CardsResponse import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.PostResponse import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.PostsResponse +import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.StatsResponse +import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.TodaysStatsResponse import org.wordpress.android.fluxc.store.dashboard.CardsStore.CardsErrorType import org.wordpress.android.fluxc.store.dashboard.CardsStore.CardsPayload import org.wordpress.android.fluxc.test @@ -41,6 +43,16 @@ private const val DATE_FORMAT_PATTERN = "yyyy-MM-dd HH:mm:ss" /* RESPONSE */ +private val TODAYS_STATS_RESPONSE = TodaysStatsResponse( + views = 100, + visitors = 30, + likes = 50 +) + +private val STATS_RESPONSE = StatsResponse( + todaysStatsResponse = TODAYS_STATS_RESPONSE +) + private val DRAFT_POST_RESPONSE_TWO = PostResponse( id = 708, title = "", @@ -77,6 +89,7 @@ private val POSTS_RESPONSE = PostsResponse( ) private val CARDS_RESPONSE = CardsResponse( + stats = STATS_RESPONSE, posts = POSTS_RESPONSE ) diff --git a/example/src/test/resources/wp/dashboard/cards.json b/example/src/test/resources/wp/dashboard/cards.json index 9949521ff1..875e95237b 100644 --- a/example/src/test/resources/wp/dashboard/cards.json +++ b/example/src/test/resources/wp/dashboard/cards.json @@ -1,4 +1,11 @@ { + "stats": { + "todays_stats": { + "views": 100, + "visitors": 30, + "likes": 50 + } + }, "posts": { "has_published": true, "draft": [ From 00819283b3aab1c737a0c1480d67f81e63fd8c60 Mon Sep 17 00:00:00 2001 From: ashiagr Date: Mon, 17 Jan 2022 17:33:29 +0530 Subject: [PATCH 3/8] Tests: Update cards store tests to include stats card entity --- .../fluxc/store/dashboard/CardsStoreTest.kt | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt b/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt index a4b850a983..d650471298 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt @@ -14,10 +14,14 @@ import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.dashboard.CardModel import org.wordpress.android.fluxc.model.dashboard.CardModel.PostsCardModel import org.wordpress.android.fluxc.model.dashboard.CardModel.PostsCardModel.PostCardModel +import org.wordpress.android.fluxc.model.dashboard.CardModel.StatsCardModel +import org.wordpress.android.fluxc.model.dashboard.CardModel.StatsCardModel.TodaysStatsModel import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.CardsResponse import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.PostResponse import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.PostsResponse +import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.StatsResponse +import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.TodaysStatsResponse import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsUtils import org.wordpress.android.fluxc.persistence.dashboard.CardsDao import org.wordpress.android.fluxc.persistence.dashboard.CardsDao.CardEntity @@ -34,6 +38,12 @@ import kotlin.test.assertNull const val SITE_LOCAL_ID = 1 +/* STATS */ + +const val STATS_VIEWS = 100 +const val STATS_VISITORS = 30 +const val STATS_LIKES = 50 + /* POST */ const val POST_ID = 1 @@ -44,6 +54,16 @@ const val POST_DATE = "2021-12-27 11:33:55" /* RESPONSE */ +private val TODAYS_STATS_RESPONSE = TodaysStatsResponse( + views = STATS_VIEWS, + visitors = STATS_VISITORS, + likes = STATS_LIKES +) + +private val STATS_RESPONSE = StatsResponse( + todaysStatsResponse = TODAYS_STATS_RESPONSE +) + private val POST_RESPONSE = PostResponse( id = POST_ID, title = POST_TITLE, @@ -59,10 +79,18 @@ private val POSTS_RESPONSE = PostsResponse( ) private val CARDS_RESPONSE = CardsResponse( + stats = STATS_RESPONSE, posts = POSTS_RESPONSE ) /* MODEL */ +private val STATS_MODEL = StatsCardModel( + todaysStats = TodaysStatsModel( + views = STATS_VIEWS, + visitors = STATS_VISITORS, + likes = STATS_LIKES + ) +) private val POST_MODEL = PostCardModel( id = POST_ID, @@ -79,10 +107,17 @@ private val POSTS_MODEL = PostsCardModel( ) private val CARDS_MODEL = listOf( + STATS_MODEL, POSTS_MODEL ) /* ENTITY */ +private val STATS_ENTITY = CardEntity( + siteLocalId = SITE_LOCAL_ID, + type = CardModel.Type.STATS.name, + date = CardsUtils.getInsertDate(), + json = CardsUtils.GSON.toJson(STATS_MODEL) +) private val POSTS_ENTITY = CardEntity( siteLocalId = SITE_LOCAL_ID, @@ -92,6 +127,7 @@ private val POSTS_ENTITY = CardEntity( ) private val CARDS_ENTITY = listOf( + STATS_ENTITY, POSTS_ENTITY ) From 8defa517920da0aa9f0072c42c50c4667f2fd5e7 Mon Sep 17 00:00:00 2001 From: ashiagr Date: Wed, 26 Jan 2022 10:54:47 +0530 Subject: [PATCH 4/8] Refactor: Update dashboard/cards endpoint success response. - Added comments to todays_stats. - Moved nested todays_stats to keep it at the same level as posts node in cards.json and corresponding response and model classes. Note that the existing endpoint will not return the stats card yet. It will be switched to a newer version in future commits. --- .../wpcom/dashboard/CardsRestClientTest.kt | 10 ++--- .../fluxc/store/dashboard/CardsStoreTest.kt | 43 ++++++++----------- .../test/resources/wp/dashboard/cards.json | 7 ++- .../fluxc/model/dashboard/CardModel.kt | 17 +++----- .../rest/wpcom/dashboard/CardsRestClient.kt | 23 ++++------ 5 files changed, 40 insertions(+), 60 deletions(-) diff --git a/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClientTest.kt b/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClientTest.kt index 7feb401a67..9ab0a5b07b 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClientTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClientTest.kt @@ -31,7 +31,6 @@ import org.wordpress.android.fluxc.network.rest.wpcom.auth.AccessToken import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.CardsResponse import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.PostResponse import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.PostsResponse -import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.StatsResponse import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.TodaysStatsResponse import org.wordpress.android.fluxc.store.dashboard.CardsStore.CardsErrorType import org.wordpress.android.fluxc.store.dashboard.CardsStore.CardsPayload @@ -46,11 +45,8 @@ private const val DATE_FORMAT_PATTERN = "yyyy-MM-dd HH:mm:ss" private val TODAYS_STATS_RESPONSE = TodaysStatsResponse( views = 100, visitors = 30, - likes = 50 -) - -private val STATS_RESPONSE = StatsResponse( - todaysStatsResponse = TODAYS_STATS_RESPONSE + likes = 50, + comments = 10 ) private val DRAFT_POST_RESPONSE_TWO = PostResponse( @@ -89,7 +85,7 @@ private val POSTS_RESPONSE = PostsResponse( ) private val CARDS_RESPONSE = CardsResponse( - stats = STATS_RESPONSE, + todaysStats = TODAYS_STATS_RESPONSE, posts = POSTS_RESPONSE ) diff --git a/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt b/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt index d650471298..c01f12286d 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt @@ -14,13 +14,11 @@ import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.dashboard.CardModel import org.wordpress.android.fluxc.model.dashboard.CardModel.PostsCardModel import org.wordpress.android.fluxc.model.dashboard.CardModel.PostsCardModel.PostCardModel -import org.wordpress.android.fluxc.model.dashboard.CardModel.StatsCardModel -import org.wordpress.android.fluxc.model.dashboard.CardModel.StatsCardModel.TodaysStatsModel +import org.wordpress.android.fluxc.model.dashboard.CardModel.TodaysStatsCardModel import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.CardsResponse import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.PostResponse import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.PostsResponse -import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.StatsResponse import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.TodaysStatsResponse import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsUtils import org.wordpress.android.fluxc.persistence.dashboard.CardsDao @@ -38,11 +36,12 @@ import kotlin.test.assertNull const val SITE_LOCAL_ID = 1 -/* STATS */ +/* TODAY'S STATS */ -const val STATS_VIEWS = 100 -const val STATS_VISITORS = 30 -const val STATS_LIKES = 50 +const val TODAYS_STATS_VIEWS = 100 +const val TODAYS_STATS_VISITORS = 30 +const val TODAYS_STATS_LIKES = 50 +const val TODAYS_STATS_COMMENTS = 10 /* POST */ @@ -55,13 +54,10 @@ const val POST_DATE = "2021-12-27 11:33:55" /* RESPONSE */ private val TODAYS_STATS_RESPONSE = TodaysStatsResponse( - views = STATS_VIEWS, - visitors = STATS_VISITORS, - likes = STATS_LIKES -) - -private val STATS_RESPONSE = StatsResponse( - todaysStatsResponse = TODAYS_STATS_RESPONSE + views = TODAYS_STATS_VIEWS, + visitors = TODAYS_STATS_VISITORS, + likes = TODAYS_STATS_LIKES, + comments = TODAYS_STATS_COMMENTS ) private val POST_RESPONSE = PostResponse( @@ -79,17 +75,16 @@ private val POSTS_RESPONSE = PostsResponse( ) private val CARDS_RESPONSE = CardsResponse( - stats = STATS_RESPONSE, + todaysStats = TODAYS_STATS_RESPONSE, posts = POSTS_RESPONSE ) /* MODEL */ -private val STATS_MODEL = StatsCardModel( - todaysStats = TodaysStatsModel( - views = STATS_VIEWS, - visitors = STATS_VISITORS, - likes = STATS_LIKES - ) +private val TODAYS_STATS_MODEL = TodaysStatsCardModel( + views = TODAYS_STATS_VIEWS, + visitors = TODAYS_STATS_VISITORS, + likes = TODAYS_STATS_LIKES, + comments = TODAYS_STATS_COMMENTS ) private val POST_MODEL = PostCardModel( @@ -107,16 +102,16 @@ private val POSTS_MODEL = PostsCardModel( ) private val CARDS_MODEL = listOf( - STATS_MODEL, + TODAYS_STATS_MODEL, POSTS_MODEL ) /* ENTITY */ private val STATS_ENTITY = CardEntity( siteLocalId = SITE_LOCAL_ID, - type = CardModel.Type.STATS.name, + type = CardModel.Type.TODAYS_STATS.name, date = CardsUtils.getInsertDate(), - json = CardsUtils.GSON.toJson(STATS_MODEL) + json = CardsUtils.GSON.toJson(TODAYS_STATS_MODEL) ) private val POSTS_ENTITY = CardEntity( diff --git a/example/src/test/resources/wp/dashboard/cards.json b/example/src/test/resources/wp/dashboard/cards.json index 875e95237b..01fd779343 100644 --- a/example/src/test/resources/wp/dashboard/cards.json +++ b/example/src/test/resources/wp/dashboard/cards.json @@ -1,10 +1,9 @@ { - "stats": { - "todays_stats": { + "todays_stats": { "views": 100, "visitors": 30, - "likes": 50 - } + "likes": 50, + "comments": 10 }, "posts": { "has_published": true, diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/model/dashboard/CardModel.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/model/dashboard/CardModel.kt index 4d0bfb34e6..7e96029763 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/model/dashboard/CardModel.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/model/dashboard/CardModel.kt @@ -8,19 +8,16 @@ sealed class CardModel( enum class Type( val classOf: Class<*> ) { - STATS(StatsCardModel::class.java), + TODAYS_STATS(TodaysStatsCardModel::class.java), POSTS(PostsCardModel::class.java) } - data class StatsCardModel( - val todaysStats: TodaysStatsModel - ) : CardModel(Type.STATS) { - data class TodaysStatsModel( - val views: Int, - val visitors: Int, - val likes: Int - ) - } + data class TodaysStatsCardModel( + val views: Int, + val visitors: Int, + val likes: Int, + val comments: Int + ) : CardModel(Type.TODAYS_STATS) data class PostsCardModel( val hasPublished: Boolean, diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClient.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClient.kt index 38319e947d..b62eb5e7e7 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClient.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClient.kt @@ -9,8 +9,7 @@ import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.dashboard.CardModel import org.wordpress.android.fluxc.model.dashboard.CardModel.PostsCardModel import org.wordpress.android.fluxc.model.dashboard.CardModel.PostsCardModel.PostCardModel -import org.wordpress.android.fluxc.model.dashboard.CardModel.StatsCardModel -import org.wordpress.android.fluxc.model.dashboard.CardModel.StatsCardModel.TodaysStatsModel +import org.wordpress.android.fluxc.model.dashboard.CardModel.TodaysStatsCardModel import org.wordpress.android.fluxc.network.BaseRequest.GenericErrorType import org.wordpress.android.fluxc.network.UserAgent import org.wordpress.android.fluxc.network.rest.wpcom.BaseWPComRestClient @@ -50,32 +49,26 @@ class CardsRestClient @Inject constructor( } data class CardsResponse( - @SerializedName("stats") val stats: StatsResponse? = null, + @SerializedName("todays_stats") val todaysStats: TodaysStatsResponse? = null, @SerializedName("posts") val posts: PostsResponse? = null ) { fun toCards() = arrayListOf().apply { - stats?.let { add(it.toStatsCard()) } + todaysStats?.let { add(it.toTodaysStatsCard()) } posts?.let { add(it.toPosts()) } }.toList() } - data class StatsResponse( - @SerializedName("todays_stats") val todaysStatsResponse: TodaysStatsResponse - ) { - fun toStatsCard() = StatsCardModel( - todaysStats = todaysStatsResponse.toTodaysStats() - ) - } - data class TodaysStatsResponse( @SerializedName("views") val views: Int? = null, @SerializedName("visitors") val visitors: Int? = null, - @SerializedName("likes") val likes: Int? = null + @SerializedName("likes") val likes: Int? = null, + @SerializedName("comments") val comments: Int? = null ) { - fun toTodaysStats() = TodaysStatsModel( + fun toTodaysStatsCard() = TodaysStatsCardModel( views = views ?: 0, visitors = visitors ?: 0, - likes = likes ?: 0 + likes = likes ?: 0, + comments = comments ?: 0 ) } From dc240ed6934df8fceb7a2fb5800724ddb4af449f Mon Sep 17 00:00:00 2001 From: ashiagr Date: Thu, 17 Feb 2022 12:20:56 +0530 Subject: [PATCH 5/8] Replace dashboard cards endpoint --- .../rest/wpcom/dashboard/CardsRestClientTest.kt | 6 ++++-- .../src/main/resources/wp-com-v2-endpoints.txt | 2 +- .../network/rest/wpcom/dashboard/CardsRestClient.kt | 13 +++++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClientTest.kt b/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClientTest.kt index 9ab0a5b07b..dc11931bf2 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClientTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClientTest.kt @@ -99,6 +99,7 @@ class CardsRestClientTest { @Mock private lateinit var site: SiteModel private lateinit var urlCaptor: KArgumentCaptor + private lateinit var paramsCaptor: KArgumentCaptor> private lateinit var restClient: CardsRestClient private val siteId: Long = 1 @@ -106,6 +107,7 @@ class CardsRestClientTest { @Before fun setUp() { urlCaptor = argumentCaptor() + paramsCaptor = argumentCaptor() restClient = CardsRestClient( wpComGsonRequestBuilder, dispatcher, @@ -197,7 +199,7 @@ class CardsRestClientTest { wpComGsonRequestBuilder.syncGetRequest( eq(restClient), urlCaptor.capture(), - eq(mapOf()), + paramsCaptor.capture(), eq(CardsResponse::class.java), eq(false), any(), @@ -235,7 +237,7 @@ class CardsRestClientTest { companion object { private const val API_BASE_PATH = "https://public-api.wordpress.com/wpcom/v2" private const val API_SITE_PATH = "$API_BASE_PATH/sites" - private const val API_DASHBOARD_CARDS_PATH = "dashboard/cards/" + private const val API_DASHBOARD_CARDS_PATH = "dashboard/cards-data/" private const val DASHBOARD_CARDS_JSON = "wp/dashboard/cards.json" } diff --git a/fluxc-processor/src/main/resources/wp-com-v2-endpoints.txt b/fluxc-processor/src/main/resources/wp-com-v2-endpoints.txt index 6a5dd9c0d3..affad8cabe 100644 --- a/fluxc-processor/src/main/resources/wp-com-v2-endpoints.txt +++ b/fluxc-processor/src/main/resources/wp-com-v2-endpoints.txt @@ -2,7 +2,7 @@ /read/sites/$site#String/notification-subscriptions/$action#String -/sites/$site/dashboard/cards +/sites/$site/dashboard/cards-data /sites/$site/activity /sites/$site/activity/count/group diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClient.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClient.kt index b62eb5e7e7..688d34fe73 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClient.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClient.kt @@ -35,11 +35,12 @@ class CardsRestClient @Inject constructor( userAgent: UserAgent ) : BaseWPComRestClient(appContext, dispatcher, requestQueue, accessToken, userAgent) { suspend fun fetchCards(site: SiteModel): CardsPayload { - val url = WPCOMV2.sites.site(site.siteId).dashboard.cards.url + val url = WPCOMV2.sites.site(site.siteId).dashboard.cards_data.url + val params = buildDashboardCardsParams() val response = wpComGsonRequestBuilder.syncGetRequest( this, url, - mapOf(), + params, CardsResponse::class.java ) return when (response) { @@ -48,6 +49,8 @@ class CardsRestClient @Inject constructor( } } + private fun buildDashboardCardsParams() = mapOf(CARDS to listOf(POSTS, TODAYS_STATS).joinToString(",")) + data class CardsResponse( @SerializedName("todays_stats") val todaysStats: TodaysStatsResponse? = null, @SerializedName("posts") val posts: PostsResponse? = null @@ -99,6 +102,12 @@ class CardsRestClient @Inject constructor( date = CardsUtils.fromDate(date) ) } + + companion object { + private const val CARDS = "cards" + private const val POSTS = "posts" + private const val TODAYS_STATS = "todays_stats" + } } fun WPComGsonNetworkError.toCardsError(): CardsError { From a81e79ce1493c9010f295d3924a98acbbb349920 Mon Sep 17 00:00:00 2001 From: ashiagr Date: Thu, 17 Feb 2022 14:39:08 +0530 Subject: [PATCH 6/8] Pass card types to fetch cards --- .../wpcom/dashboard/CardsRestClientTest.kt | 19 +++++++---- .../fluxc/store/dashboard/CardsStoreTest.kt | 32 +++++++++++-------- .../fluxc/model/dashboard/CardModel.kt | 7 ++-- .../rest/wpcom/dashboard/CardsRestClient.kt | 9 +++--- .../fluxc/store/dashboard/CardsStore.kt | 5 +-- 5 files changed, 41 insertions(+), 31 deletions(-) diff --git a/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClientTest.kt b/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClientTest.kt index dc11931bf2..44849397ab 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClientTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClientTest.kt @@ -20,6 +20,7 @@ import org.mockito.junit.MockitoJUnitRunner import org.wordpress.android.fluxc.Dispatcher import org.wordpress.android.fluxc.UnitTestUtils import org.wordpress.android.fluxc.model.SiteModel +import org.wordpress.android.fluxc.model.dashboard.CardModel import org.wordpress.android.fluxc.network.BaseRequest.BaseNetworkError import org.wordpress.android.fluxc.network.BaseRequest.GenericErrorType import org.wordpress.android.fluxc.network.UserAgent @@ -40,6 +41,10 @@ import org.wordpress.android.fluxc.test private const val DATE_FORMAT_PATTERN = "yyyy-MM-dd HH:mm:ss" +/* CARD TYPES */ + +private val CARD_TYPES = listOf(CardModel.Type.TODAYS_STATS, CardModel.Type.POSTS) + /* RESPONSE */ private val TODAYS_STATS_RESPONSE = TodaysStatsResponse( @@ -123,7 +128,7 @@ class CardsRestClientTest { val json = UnitTestUtils.getStringFromResourceFile(javaClass, DASHBOARD_CARDS_JSON) initFetchCards(data = getCardsResponseFromJsonString(json)) - restClient.fetchCards(site) + restClient.fetchCards(site, CARD_TYPES) assertEquals(urlCaptor.firstValue, "$API_SITE_PATH/${site.siteId}/$API_DASHBOARD_CARDS_PATH") } @@ -133,7 +138,7 @@ class CardsRestClientTest { val json = UnitTestUtils.getStringFromResourceFile(javaClass, DASHBOARD_CARDS_JSON) initFetchCards(data = getCardsResponseFromJsonString(json)) - val result = restClient.fetchCards(site) + val result = restClient.fetchCards(site, CARD_TYPES) assertSuccess(CARDS_RESPONSE, result) } @@ -142,7 +147,7 @@ class CardsRestClientTest { fun `given timeout, when fetch cards gets triggered, then return cards timeout error`() = test { initFetchCards(error = WPComGsonNetworkError(BaseNetworkError(GenericErrorType.TIMEOUT))) - val result = restClient.fetchCards(site) + val result = restClient.fetchCards(site, CARD_TYPES) assertError(CardsErrorType.TIMEOUT, result) } @@ -151,7 +156,7 @@ class CardsRestClientTest { fun `given network error, when fetch cards gets triggered, then return cards api error`() = test { initFetchCards(error = WPComGsonNetworkError(BaseNetworkError(GenericErrorType.NETWORK_ERROR))) - val result = restClient.fetchCards(site) + val result = restClient.fetchCards(site, CARD_TYPES) assertError(CardsErrorType.API_ERROR, result) } @@ -160,7 +165,7 @@ class CardsRestClientTest { fun `given invalid response, when fetch cards gets triggered, then return cards invalid response error`() = test { initFetchCards(error = WPComGsonNetworkError(BaseNetworkError(GenericErrorType.INVALID_RESPONSE))) - val result = restClient.fetchCards(site) + val result = restClient.fetchCards(site, CARD_TYPES) assertError(CardsErrorType.INVALID_RESPONSE, result) } @@ -169,7 +174,7 @@ class CardsRestClientTest { fun `given not authenticated, when fetch cards gets triggered, then return cards auth required error`() = test { initFetchCards(error = WPComGsonNetworkError(BaseNetworkError(GenericErrorType.NOT_AUTHENTICATED))) - val result = restClient.fetchCards(site) + val result = restClient.fetchCards(site, CARD_TYPES) assertError(CardsErrorType.AUTHORIZATION_REQUIRED, result) } @@ -178,7 +183,7 @@ class CardsRestClientTest { fun `given unknown error, when fetch cards gets triggered, then return cards generic error`() = test { initFetchCards(error = WPComGsonNetworkError(BaseNetworkError(GenericErrorType.UNKNOWN))) - val result = restClient.fetchCards(site) + val result = restClient.fetchCards(site, CARD_TYPES) assertError(CardsErrorType.GENERIC_ERROR, result) } diff --git a/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt b/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt index c01f12286d..8e7eb62894 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt @@ -51,6 +51,10 @@ const val POST_CONTENT = "content" const val POST_FEATURED_IMAGE = "featuredImage" const val POST_DATE = "2021-12-27 11:33:55" +/* CARD TYPES */ + +private val CARD_TYPES = listOf(CardModel.Type.TODAYS_STATS, CardModel.Type.POSTS) + /* RESPONSE */ private val TODAYS_STATS_RESPONSE = TodaysStatsResponse( @@ -151,9 +155,9 @@ class CardsStoreTest { @Test fun `given cards response, when fetch cards gets triggered, then cards model is inserted into db`() = test { val payload = CardsPayload(CARDS_RESPONSE) - whenever(restClient.fetchCards(siteModel)).thenReturn(payload) + whenever(restClient.fetchCards(siteModel, CARD_TYPES)).thenReturn(payload) - cardsStore.fetchCards(siteModel) + cardsStore.fetchCards(siteModel, CARD_TYPES) verify(dao).insertWithDate(siteModel.id, CARDS_MODEL) } @@ -161,9 +165,9 @@ class CardsStoreTest { @Test fun `given cards response, when fetch cards gets triggered, then empty cards model is returned`() = test { val payload = CardsPayload(CARDS_RESPONSE) - whenever(restClient.fetchCards(siteModel)).thenReturn(payload) + whenever(restClient.fetchCards(siteModel, CARD_TYPES)).thenReturn(payload) - val result = cardsStore.fetchCards(siteModel) + val result = cardsStore.fetchCards(siteModel, CARD_TYPES) assertThat(result.model).isNull() assertThat(result.error).isNull() @@ -172,10 +176,10 @@ class CardsStoreTest { @Test fun `given card response with exception, when fetch cards gets triggered, then cards error is returned`() = test { val payload = CardsPayload(CARDS_RESPONSE) - whenever(restClient.fetchCards(siteModel)).thenReturn(payload) + whenever(restClient.fetchCards(siteModel, CARD_TYPES)).thenReturn(payload) whenever(dao.insertWithDate(siteModel.id, CARDS_MODEL)).thenThrow(IllegalStateException("Error")) - val result = cardsStore.fetchCards(siteModel) + val result = cardsStore.fetchCards(siteModel, CARD_TYPES) assertThat(result.model).isNull() assertEquals(CardsErrorType.GENERIC_ERROR, result.error.type) @@ -186,9 +190,9 @@ class CardsStoreTest { fun `given cards error, when fetch cards gets triggered, then cards error is returned`() = test { val errorType = CardsErrorType.API_ERROR val payload = CardsPayload(CardsError(errorType)) - whenever(restClient.fetchCards(siteModel)).thenReturn(payload) + whenever(restClient.fetchCards(siteModel, CARD_TYPES)).thenReturn(payload) - val result = cardsStore.fetchCards(siteModel) + val result = cardsStore.fetchCards(siteModel, CARD_TYPES) assertThat(result.model).isNull() assertEquals(errorType, result.error.type) @@ -199,9 +203,9 @@ class CardsStoreTest { fun `given authorization required, when fetch cards gets triggered, then db is cleared of cards model`() = test { val errorType = CardsErrorType.AUTHORIZATION_REQUIRED val payload = CardsPayload(CardsError(errorType)) - whenever(restClient.fetchCards(siteModel)).thenReturn(payload) + whenever(restClient.fetchCards(siteModel, CARD_TYPES)).thenReturn(payload) - cardsStore.fetchCards(siteModel) + cardsStore.fetchCards(siteModel, CARD_TYPES) verify(dao).clear() } @@ -210,9 +214,9 @@ class CardsStoreTest { fun `given authorization required, when fetch cards gets triggered, then empty cards model is returned`() = test { val errorType = CardsErrorType.AUTHORIZATION_REQUIRED val payload = CardsPayload(CardsError(errorType)) - whenever(restClient.fetchCards(siteModel)).thenReturn(payload) + whenever(restClient.fetchCards(siteModel, CARD_TYPES)).thenReturn(payload) - val result = cardsStore.fetchCards(siteModel) + val result = cardsStore.fetchCards(siteModel, CARD_TYPES) assertThat(result.model).isNull() assertThat(result.error).isNull() @@ -221,9 +225,9 @@ class CardsStoreTest { @Test fun `given empty cards payload, when fetch cards gets triggered, then cards error is returned`() = test { val payload = CardsPayload() - whenever(restClient.fetchCards(siteModel)).thenReturn(payload) + whenever(restClient.fetchCards(siteModel, CARD_TYPES)).thenReturn(payload) - val result = cardsStore.fetchCards(siteModel) + val result = cardsStore.fetchCards(siteModel, CARD_TYPES) assertThat(result.model).isNull() assertEquals(CardsErrorType.INVALID_RESPONSE, result.error.type) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/model/dashboard/CardModel.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/model/dashboard/CardModel.kt index 7e96029763..7cf3a0911c 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/model/dashboard/CardModel.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/model/dashboard/CardModel.kt @@ -6,10 +6,11 @@ sealed class CardModel( val type: Type ) { enum class Type( - val classOf: Class<*> + val classOf: Class<*>, + val label: String ) { - TODAYS_STATS(TodaysStatsCardModel::class.java), - POSTS(PostsCardModel::class.java) + TODAYS_STATS(TodaysStatsCardModel::class.java, "todays_stats"), + POSTS(PostsCardModel::class.java, "posts") } data class TodaysStatsCardModel( diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClient.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClient.kt index 688d34fe73..8803b80d9a 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClient.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClient.kt @@ -34,9 +34,9 @@ class CardsRestClient @Inject constructor( accessToken: AccessToken, userAgent: UserAgent ) : BaseWPComRestClient(appContext, dispatcher, requestQueue, accessToken, userAgent) { - suspend fun fetchCards(site: SiteModel): CardsPayload { + suspend fun fetchCards(site: SiteModel, cardTypes: List): CardsPayload { val url = WPCOMV2.sites.site(site.siteId).dashboard.cards_data.url - val params = buildDashboardCardsParams() + val params = buildDashboardCardsParams(cardTypes) val response = wpComGsonRequestBuilder.syncGetRequest( this, url, @@ -49,7 +49,8 @@ class CardsRestClient @Inject constructor( } } - private fun buildDashboardCardsParams() = mapOf(CARDS to listOf(POSTS, TODAYS_STATS).joinToString(",")) + private fun buildDashboardCardsParams(cardTypes: List) = + mapOf(CARDS to cardTypes.joinToString(",") { it.label }) data class CardsResponse( @SerializedName("todays_stats") val todaysStats: TodaysStatsResponse? = null, @@ -105,8 +106,6 @@ class CardsRestClient @Inject constructor( companion object { private const val CARDS = "cards" - private const val POSTS = "posts" - private const val TODAYS_STATS = "todays_stats" } } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/dashboard/CardsStore.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/store/dashboard/CardsStore.kt index 7fc57818b1..869467d133 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/dashboard/CardsStore.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/dashboard/CardsStore.kt @@ -21,9 +21,10 @@ class CardsStore @Inject constructor( private val coroutineEngine: CoroutineEngine ) { suspend fun fetchCards( - site: SiteModel + site: SiteModel, + cardTypes: List ) = coroutineEngine.withDefaultContext(AppLog.T.API, this, "fetchCards") { - val payload = restClient.fetchCards(site) + val payload = restClient.fetchCards(site, cardTypes) return@withDefaultContext storeCards(site, payload) } From d43abe809b8d9526e0a8126403c7186a30b3149a Mon Sep 17 00:00:00 2001 From: ashiagr Date: Thu, 17 Feb 2022 17:17:56 +0530 Subject: [PATCH 7/8] Pass cardTypes to getCards --- .../fluxc/store/dashboard/CardsStoreTest.kt | 28 ++++++++++++++++--- .../fluxc/persistence/dashboard/CardsDao.kt | 4 +-- .../fluxc/store/dashboard/CardsStore.kt | 5 ++-- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt b/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt index 8e7eb62894..00fc83d131 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt @@ -111,7 +111,7 @@ private val CARDS_MODEL = listOf( ) /* ENTITY */ -private val STATS_ENTITY = CardEntity( +private val TODAYS_STATS_ENTITY = CardEntity( siteLocalId = SITE_LOCAL_ID, type = CardModel.Type.TODAYS_STATS.name, date = CardsUtils.getInsertDate(), @@ -126,7 +126,7 @@ private val POSTS_ENTITY = CardEntity( ) private val CARDS_ENTITY = listOf( - STATS_ENTITY, + TODAYS_STATS_ENTITY, POSTS_ENTITY ) @@ -236,10 +236,30 @@ class CardsStoreTest { @Test fun `when get cards gets triggered, then a flow of cards model is returned`() = test { - whenever(dao.get(SITE_LOCAL_ID)).thenReturn(flowOf(CARDS_ENTITY)) + whenever(dao.get(SITE_LOCAL_ID, CARD_TYPES)).thenReturn(flowOf(CARDS_ENTITY)) - val result = cardsStore.getCards(siteModel).single() + val result = cardsStore.getCards(siteModel, CARD_TYPES).single() assertThat(result).isEqualTo(CardsResult(CARDS_MODEL)) } + + @Test + fun `when get cards gets triggered for today's stats only, then a flow of today's stats card model is returned`() = + test { + whenever(dao.get(SITE_LOCAL_ID, listOf(CardModel.Type.TODAYS_STATS))) + .thenReturn(flowOf(listOf(TODAYS_STATS_ENTITY))) + + val result = cardsStore.getCards(siteModel, listOf(CardModel.Type.TODAYS_STATS)).single() + + assertThat(result).isEqualTo(CardsResult(listOf(TODAYS_STATS_MODEL))) + } + + @Test + fun `when get cards gets triggered for posts only, then a flow of post card model is returned`() = test { + whenever(dao.get(SITE_LOCAL_ID, listOf(CardModel.Type.POSTS))).thenReturn(flowOf(listOf(POSTS_ENTITY))) + + val result = cardsStore.getCards(siteModel, listOf(CardModel.Type.POSTS)).single() + + assertThat(result).isEqualTo(CardsResult(listOf(POSTS_MODEL))) + } } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/dashboard/CardsDao.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/dashboard/CardsDao.kt index ada34d7d34..51a97a7502 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/dashboard/CardsDao.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/dashboard/CardsDao.kt @@ -11,8 +11,8 @@ import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsUtils @Dao abstract class CardsDao { - @Query("SELECT * FROM DashboardCards WHERE siteLocalId = :siteLocalId") - abstract fun get(siteLocalId: Int): Flow> + @Query("SELECT * FROM DashboardCards WHERE siteLocalId = :siteLocalId AND type IN (:cardTypes)") + abstract fun get(siteLocalId: Int, cardTypes: List): Flow> @Insert(onConflict = OnConflictStrategy.REPLACE) abstract suspend fun insert(card: List) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/dashboard/CardsStore.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/store/dashboard/CardsStore.kt index 869467d133..efcb9e4c5c 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/dashboard/CardsStore.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/dashboard/CardsStore.kt @@ -58,8 +58,9 @@ class CardsStore @Inject constructor( } fun getCards( - site: SiteModel - ) = cardsDao.get(site.id).map { cards -> + site: SiteModel, + cardTypes: List + ) = cardsDao.get(site.id, cardTypes).map { cards -> CardsResult(cards.map { it.toCard() }) } From 0fa2cf20fe743890b081e61737e4442e35c79283 Mon Sep 17 00:00:00 2001 From: ashiagr Date: Thu, 17 Feb 2022 17:22:22 +0530 Subject: [PATCH 8/8] Tests: Add tests for fetchCards with different card types --- .../fluxc/store/dashboard/CardsStoreTest.kt | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt b/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt index 00fc83d131..20a77065da 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt @@ -153,7 +153,7 @@ class CardsStoreTest { } @Test - fun `given cards response, when fetch cards gets triggered, then cards model is inserted into db`() = test { + fun `given all card types, when fetch cards triggered, then all cards model is inserted into db`() = test { val payload = CardsPayload(CARDS_RESPONSE) whenever(restClient.fetchCards(siteModel, CARD_TYPES)).thenReturn(payload) @@ -162,6 +162,26 @@ class CardsStoreTest { verify(dao).insertWithDate(siteModel.id, CARDS_MODEL) } + @Test + fun `given todays stats type, when fetch cards triggered, then today's stats card model inserted into db`() = test { + val payload = CardsPayload(CardsResponse(todaysStats = TODAYS_STATS_RESPONSE)) + whenever(restClient.fetchCards(siteModel, listOf(CardModel.Type.TODAYS_STATS))).thenReturn(payload) + + cardsStore.fetchCards(siteModel, listOf(CardModel.Type.TODAYS_STATS)) + + verify(dao).insertWithDate(siteModel.id, listOf(TODAYS_STATS_MODEL)) + } + + @Test + fun `given posts type, when fetch cards triggered, then post card model inserted into db`() = test { + val payload = CardsPayload(CardsResponse(posts = POSTS_RESPONSE)) + whenever(restClient.fetchCards(siteModel, listOf(CardModel.Type.POSTS))).thenReturn(payload) + + cardsStore.fetchCards(siteModel, listOf(CardModel.Type.POSTS)) + + verify(dao).insertWithDate(siteModel.id, listOf(POSTS_MODEL)) + } + @Test fun `given cards response, when fetch cards gets triggered, then empty cards model is returned`() = test { val payload = CardsPayload(CARDS_RESPONSE)