Skip to content

Commit f22755c

Browse files
@W-18186860: Actionable Notifications (Android) Additional Test Automation For Code Coverage (#2704)
1 parent dbe9c40 commit f22755c

17 files changed

+1844
-142
lines changed

libs/SalesforceSDK/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ dependencies {
5151
androidTestImplementation("androidx.test.ext:junit:1.2.1")
5252
androidTestImplementation("androidx.arch.core:core-testing:2.2.0")
5353
androidTestImplementation("androidx.compose.ui:ui-test-junit4:$composeVersion")
54+
androidTestImplementation("io.mockk:mockk-android:1.14.0")
5455
}
5556

5657
android {
@@ -92,7 +93,7 @@ android {
9293

9394
packaging {
9495
resources {
95-
excludes += setOf("META-INF/LICENSE", "META-INF/LICENSE.txt", "META-INF/DEPENDENCIES", "META-INF/NOTICE")
96+
excludes += setOf("META-INF/LICENSE*", "META-INF/LICENSE.txt", "META-INF/DEPENDENCIES", "META-INF/NOTICE")
9697
}
9798
}
9899

libs/SalesforceSDK/src/com/salesforce/androidsdk/app/SalesforceSDKManager.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ import androidx.compose.runtime.Composable
6262
import androidx.core.content.ContextCompat.RECEIVER_EXPORTED
6363
import androidx.core.content.ContextCompat.RECEIVER_NOT_EXPORTED
6464
import androidx.core.content.ContextCompat.registerReceiver
65-
import androidx.core.net.toUri
6665
import androidx.lifecycle.DefaultLifecycleObserver
6766
import androidx.lifecycle.LifecycleOwner
6867
import androidx.lifecycle.ProcessLifecycleOwner
@@ -622,28 +621,30 @@ open class SalesforceSDKManager protected constructor(
622621
*/
623622
fun getNotificationsType(
624623
type: String
625-
) = getNotificationsTypes(
626-
userAccountManager.currentUser
627-
)?.notificationTypes?.firstOrNull { notificationType ->
628-
notificationType.type == type
624+
) = userAccountManager.currentUser?.let { currentUser ->
625+
getNotificationsTypes(
626+
currentUser
627+
)?.notificationTypes?.firstOrNull { notificationType ->
628+
notificationType.type == type
629+
}
629630
}
630631

631632
/**
632633
* Invokes a Salesforce Notifications API notification action.
633634
* @param notificationId The Salesforce actionable notification's id
634635
* @param actionKey The Salesforce actionable notification's action key
636+
* @param restClient The REST client to use when invoking the Salesforce
637+
* Notifications API. Note the REST client determines the user account used
638+
* as well. This defaults to the current user's REST client.
635639
* @return The Salesforce Notifications API actions endpoint response or
636640
* null
637641
*/
638642
fun invokeServerNotificationAction(
639643
notificationId: String,
640-
actionKey: String
644+
actionKey: String,
645+
restClient: RestClient = clientManager.peekRestClient(userAccountManager.currentUser)
641646
): NotificationsActionsResponseBody? {
642-
val userAccount = userAccountManager.currentUser
643-
val instanceHost = userAccount.instanceServer.toUri().host ?: return null
644-
val restClient = clientManager.peekRestClient(userAccount)
645647
return NotificationsApiClient(
646-
apiHostName = instanceHost,
647648
restClient = restClient
648649
).submitNotificationAction(
649650
notificationId = notificationId,

libs/SalesforceSDK/src/com/salesforce/androidsdk/push/PushMessaging.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import com.salesforce.androidsdk.push.PushService.PushNotificationReRegistration
4545
import com.salesforce.androidsdk.rest.NotificationsTypesResponseBody
4646
import com.salesforce.androidsdk.security.KeyStoreWrapper
4747
import com.salesforce.androidsdk.util.SalesforceSDKLogger
48+
import kotlinx.serialization.json.Json
4849

4950

5051
/**
@@ -264,7 +265,7 @@ object PushMessaging {
264265

265266
/**
266267
* Stores the Salesforce notifications types for the provided user account.
267-
* @param userAccount THe user account
268+
* @param userAccount The user account
268269
*/
269270
@JvmStatic
270271
internal fun setNotificationTypes(
@@ -279,7 +280,10 @@ object PushMessaging {
279280
sharedPreferences.edit {
280281
putString(
281282
NOTIFICATIONS_TYPES,
282-
notificationsTypes.sourceJson
283+
Json.encodeToString(
284+
NotificationsTypesResponseBody.serializer(),
285+
notificationsTypes
286+
)
283287
)
284288
}
285289
}

0 commit comments

Comments
 (0)