Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ internal object NotificationFormatHelper {
}

private fun getOSNotificationIdFromJsonString(jsonStr: String?): String? {
if (jsonStr == null) {
Logging.debug("Not a OneSignal formatted JSON. No 'custom' field in the payload.")
return null
}
try {
val customJSON = JSONObject(jsonStr)
if (customJSON.has(PAYLOAD_OS_NOTIFICATION_ID)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.onesignal.notifications.internal.common

import android.os.Bundle
import br.com.colman.kotest.android.extensions.robolectric.RobolectricTest
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import org.json.JSONObject

@RobolectricTest
class NotificationFormatHelperTests : FunSpec({
test("getOSNotificationIdFromJson returns the id from custom") {
val json = JSONObject().put("custom", """{"i":"notification-id"}""")

NotificationFormatHelper.getOSNotificationIdFromJson(json) shouldBe "notification-id"
}

test("getOSNotificationIdFromJson returns null when custom is missing") {
val json = JSONObject().put("type", "call")

NotificationFormatHelper.getOSNotificationIdFromJson(json) shouldBe null
}

test("getOSNotificationIdFromJson returns null when custom is not JSON") {
val json = JSONObject().put("custom", "not-json")

NotificationFormatHelper.getOSNotificationIdFromJson(json) shouldBe null
}

test("isOneSignalBundle is false when custom is missing") {
NotificationFormatHelper.isOneSignalBundle(Bundle().apply { putString("type", "call") }) shouldBe false
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ class NotificationIngressTests : FunSpec({
NotificationIngress.pendingCountForTest(context) shouldBe 1
}

test("FCM input without a OneSignal payload is rejected without scheduling") {
var scheduled = false
NotificationIngress.drainSchedulerForTest = { scheduled = true }
val bundle = Bundle().apply { putString("type", "call") }

NotificationIngress.persistFcm(context, Intent("com.google.android.c2dm.intent.RECEIVE"), bundle) shouldBe false

NotificationIngress.pendingCountForTest(context) shouldBe 0
scheduled shouldBe false
}

test("dismiss input is persisted before scheduling") {
var countAtSchedule = 0
NotificationIngress.drainSchedulerForTest = {
Expand Down
Loading