@@ -18,6 +18,7 @@ import org.wordpress.android.fluxc.model.SiteModel
1818import org.wordpress.android.fluxc.model.blaze.BlazeAdForecast
1919import org.wordpress.android.fluxc.model.blaze.BlazeAdSuggestion
2020import org.wordpress.android.fluxc.model.blaze.BlazeCampaignModel
21+ import org.wordpress.android.fluxc.model.blaze.BlazeCampaignObjective
2122import org.wordpress.android.fluxc.model.blaze.BlazeCampaignsModel
2223import org.wordpress.android.fluxc.model.blaze.BlazePaymentMethod
2324import org.wordpress.android.fluxc.model.blaze.BlazePaymentMethodUrls
@@ -38,6 +39,8 @@ import org.wordpress.android.fluxc.network.rest.wpcom.blaze.BlazeCreationRestCli
3839import org.wordpress.android.fluxc.network.rest.wpcom.blaze.CampaignImage
3940import org.wordpress.android.fluxc.persistence.blaze.BlazeCampaignsDao
4041import org.wordpress.android.fluxc.persistence.blaze.BlazeCampaignsDao.BlazeCampaignEntity
42+ import org.wordpress.android.fluxc.persistence.blaze.BlazeObjectivesDao
43+ import org.wordpress.android.fluxc.persistence.blaze.BlazeObjectivesDao.BlazeCampaignObjectiveEntity
4144import org.wordpress.android.fluxc.persistence.blaze.BlazeTargetingDao
4245import org.wordpress.android.fluxc.persistence.blaze.BlazeTargetingDeviceEntity
4346import org.wordpress.android.fluxc.persistence.blaze.BlazeTargetingLanguageEntity
@@ -121,6 +124,7 @@ class BlazeCampaignsStoreTest {
121124 private val creationRestClient: BlazeCreationRestClient = mock()
122125 private val blazeCampaignsDao: BlazeCampaignsDao = mock()
123126 private val blazeTargetingDao: BlazeTargetingDao = mock()
127+ private val blazeObjectivesDao: BlazeObjectivesDao = mock()
124128 private val siteModel = SiteModel ().apply { siteId = SITE_ID }
125129
126130 private lateinit var store: BlazeCampaignsStore
@@ -135,7 +139,8 @@ class BlazeCampaignsStoreTest {
135139 creationRestClient = creationRestClient,
136140 campaignsDao = blazeCampaignsDao,
137141 targetingDao = blazeTargetingDao,
138- coroutineEngine = initCoroutineEngine()
142+ coroutineEngine = initCoroutineEngine(),
143+ blazeObjectivesDao = blazeObjectivesDao
139144 )
140145 }
141146
@@ -214,6 +219,48 @@ class BlazeCampaignsStoreTest {
214219 assertThat(result).isNull()
215220 }
216221
222+ @Test
223+ fun `when fetching campaign objectives, then persist data in DB` () = test {
224+ whenever(creationRestClient.fetchCampaignObjectives(any(), any())).thenReturn(
225+ BlazeCreationRestClient .BlazePayload (
226+ List (4 ) {
227+ BlazeCampaignObjective (
228+ id = it.toString(),
229+ title = " Title $it " ,
230+ description = " Description $it " ,
231+ suitableForDescription = " Suitable for description $it "
232+ )
233+ }
234+ )
235+ )
236+
237+ store.fetchBlazeCampaignObjectives(siteModel)
238+
239+ verify(blazeObjectivesDao).replaceObjectives(any())
240+ }
241+
242+ @Test
243+ fun `when observing campaign objectives, then return data from DB` () = test {
244+ whenever(blazeObjectivesDao.observeObjectives(any())).thenReturn(
245+ flowOf(
246+ List (4 ) {
247+ BlazeCampaignObjectiveEntity (
248+ id = it.toString(),
249+ title = " Title $it " ,
250+ description = " Description $it " ,
251+ suitableForDescription = " Suitable for description $it " ,
252+ locale = " en"
253+ )
254+ }
255+ )
256+ )
257+
258+ val objectives = store.observeBlazeCampaignObjectives().first()
259+
260+ assertThat(objectives).isNotNull
261+ assertThat(objectives.size).isEqualTo(4 )
262+ }
263+
217264 @Test
218265 fun `when fetching targeting locations, then locations are returned` () = test {
219266 whenever(creationRestClient.fetchTargetingLocations(any(), any(), any())).thenReturn(
0 commit comments