Skip to content

Commit

Permalink
WIP 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigo Gomez Palacio committed Aug 9, 2024
1 parent 274b886 commit ecaef33
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface ISubscriptionBackendService {
appId: String,
subscriptionId: String,
subscription: SubscriptionObject,
) : Long
) : Long?

/**
* Delete an existing subscription.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ interface IUserBackendService {
properties: PropertiesObject,
refreshDeviceMetadata: Boolean,
propertyiesDelta: PropertiesDeltasObject,
) : Long
) : Long?

/**
* Retrieve a user from the backend.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,19 @@ internal class SubscriptionBackendService(
}

val responseBody = JSONObject(response.payload)
val offset = responseBody.getLong("offset")
var offset: Long? = null
if (responseBody.has("offset")) {
offset = responseBody.getLong("offset")
}

return Pair(subscriptionJSON.getString("id"), offset)
}

override suspend fun updateSubscription(
appId: String,
subscriptionId: String,
subscription: SubscriptionObject,
) : Long {
) : Long? {
val requestJSON =
JSONObject()
.put("subscription", JSONConverter.convertToJSON(subscription))
Expand All @@ -54,7 +58,11 @@ internal class SubscriptionBackendService(
}

val responseBody = JSONObject(response.payload)
return responseBody.getLong("offset")
return if (responseBody.has("offset")) {
responseBody.getLong("offset")
} else {
null
}
}

override suspend fun deleteSubscription(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ internal class UserBackendService(
properties: PropertiesObject,
refreshDeviceMetadata: Boolean,
propertyiesDelta: PropertiesDeltasObject,
): Long {
): Long? {
val jsonObject =
JSONObject()
.put("refresh_device_metadata", refreshDeviceMetadata)
Expand All @@ -72,10 +72,13 @@ internal class UserBackendService(
}

val responseBody = JSONObject(response.payload)
return responseBody.getLong("offset")
return if (responseBody.has("offset")) {
responseBody.getLong("offset")
} else {
null
}
}


override suspend fun getUser(
appId: String,
aliasLabel: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SubscriptionBackendServiceTests : FunSpec({
val response = subscriptionBackendService.createSubscription("appId", aliasLabel, aliasValue, subscription)

// Then
response shouldBe "subscriptionId"
response shouldBe Pair("subscriptionId", null)
coVerify {
spyHttpClient.post(
"apps/appId/users/by/$aliasLabel/$aliasValue/subscriptions",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package com.onesignal.inAppMessages.internal

import android.app.AlertDialog
import com.onesignal.common.AndroidUtils
import com.onesignal.common.ConsistencyManager
import com.onesignal.common.IDManager
import com.onesignal.common.JSONUtils
import com.onesignal.common.ConsistencyManager
import com.onesignal.common.consistency.IamFetchReadyCondition
import com.onesignal.common.events.EventProducer
import com.onesignal.common.exceptions.BackendException
Expand Down Expand Up @@ -68,7 +68,7 @@ internal class InAppMessagesManager(
private val _lifecycle: IInAppLifecycleService,
private val _languageContext: ILanguageContext,
private val _time: ITime,
private val _consistencyManager: ConsistencyManager
private val _consistencyManager: ConsistencyManager,
) : IInAppMessagesManager,
IStartableService,
ISubscriptionChangedHandler,
Expand Down Expand Up @@ -205,7 +205,6 @@ internal class InAppMessagesManager(

override fun onSubscriptionRemoved(subscription: ISubscription) { }


override fun onSubscriptionChanged(
subscription: ISubscription,
args: ModelChangedArgs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal interface IInAppBackendService {
suspend fun listInAppMessages(
appId: String,
subscriptionId: String,
offset: Long? = null
offset: Long? = null,
): List<InAppMessage>?

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal class InAppBackendService(
override suspend fun listInAppMessages(
appId: String,
subscriptionId: String,
offset: Long?
offset: Long?,
): List<InAppMessage>? {
// Construct the URL with or without the Kafka offset parameter
val url = buildString {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class InAppMessagesManagerTests : FunSpec({
mockk<IInAppLifecycleService>(),
MockHelper.languageContext(),
MockHelper.time(1000),
mockk<ConsistencyManager>()
mockk<ConsistencyManager>(),
)

// When
Expand Down

0 comments on commit ecaef33

Please sign in to comment.