Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit 8667e16

Browse files
Merge pull request #3095 from wordpress-mobile/feature/campaigns-objectives-endpoint
Add campaigns/objectives endpoint
2 parents a6a3b2f + 6cba3d9 commit 8667e16

File tree

8 files changed

+1169
-4
lines changed

8 files changed

+1169
-4
lines changed

example/src/test/java/org/wordpress/android/fluxc/store/blaze/BlazeCampaignsStoreTest.kt

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import org.wordpress.android.fluxc.model.SiteModel
1818
import org.wordpress.android.fluxc.model.blaze.BlazeAdForecast
1919
import org.wordpress.android.fluxc.model.blaze.BlazeAdSuggestion
2020
import org.wordpress.android.fluxc.model.blaze.BlazeCampaignModel
21+
import org.wordpress.android.fluxc.model.blaze.BlazeCampaignObjective
2122
import org.wordpress.android.fluxc.model.blaze.BlazeCampaignsModel
2223
import org.wordpress.android.fluxc.model.blaze.BlazePaymentMethod
2324
import org.wordpress.android.fluxc.model.blaze.BlazePaymentMethodUrls
@@ -38,6 +39,8 @@ import org.wordpress.android.fluxc.network.rest.wpcom.blaze.BlazeCreationRestCli
3839
import org.wordpress.android.fluxc.network.rest.wpcom.blaze.CampaignImage
3940
import org.wordpress.android.fluxc.persistence.blaze.BlazeCampaignsDao
4041
import 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
4144
import org.wordpress.android.fluxc.persistence.blaze.BlazeTargetingDao
4245
import org.wordpress.android.fluxc.persistence.blaze.BlazeTargetingDeviceEntity
4346
import 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(

fluxc-processor/src/main/resources/wp-com-v2-endpoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
/sites/$site/wordads/dsp/api/v1.1/forecast
4545
/sites/$site/wordads/dsp/api/v1.1/payment-methods
4646
/sites/$site/wordads/dsp/api/v1.1/campaigns
47+
/sites/$site/wordads/dsp/api/v1.1/campaigns/objectives
4748

4849
/sites/$site/launch
4950

0 commit comments

Comments
 (0)