@adshift/react-native-plugin 1.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AdShiftReactNativePlugin.podspec +11 -7
- package/CHANGELOG.md +138 -0
- package/README.md +513 -542
- package/android/build.gradle +17 -3
- package/android/consumer-rules.pro +21 -0
- package/android/src/main/java/com/adshift/reactnativeplugin/AdShiftReactNativePluginModule.kt +786 -229
- package/android/src/test/java/com/adshift/reactnativeplugin/ConsentSnapshotTest.kt +180 -0
- package/android/src/test/java/com/adshift/reactnativeplugin/DeepLinkDeliveryTest.kt +146 -0
- package/android/src/test/java/com/adshift/reactnativeplugin/InitializeOrderingTest.kt +111 -0
- package/android/src/test/java/com/adshift/reactnativeplugin/IntentLinkDedupTest.kt +168 -0
- package/android/src/test/java/com/adshift/reactnativeplugin/LaunchIntentForwardingTest.kt +106 -0
- package/android/src/test/java/com/adshift/reactnativeplugin/ModuleTestSupport.kt +167 -0
- package/android/src/test/java/com/adshift/reactnativeplugin/StartVerdictTest.kt +164 -0
- package/ios/AdShiftReactNativePlugin.h +7 -7
- package/ios/AdShiftReactNativePlugin.mm +200 -181
- package/ios/AdShiftReactNativePluginHelper.swift +584 -286
- package/ios/Core/BridgeRules.swift +82 -0
- package/lib/commonjs/Adshift.js +1138 -0
- package/lib/commonjs/Adshift.js.map +1 -0
- package/lib/commonjs/NativeAdShiftReactNativePlugin.js +22 -0
- package/lib/commonjs/NativeAdShiftReactNativePlugin.js.map +1 -0
- package/lib/commonjs/index.js +94 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/jest/index.js +164 -0
- package/lib/commonjs/jest/index.js.map +1 -0
- package/lib/commonjs/nativeSdkVersions.js +17 -0
- package/lib/commonjs/nativeSdkVersions.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/types/AdshiftAdRevenue.js +47 -0
- package/lib/commonjs/types/AdshiftAdRevenue.js.map +1 -0
- package/lib/commonjs/types/AdshiftConfig.js +45 -0
- package/lib/commonjs/types/AdshiftConfig.js.map +1 -0
- package/lib/commonjs/types/AdshiftConsent.js +113 -0
- package/lib/commonjs/types/AdshiftConsent.js.map +1 -0
- package/lib/commonjs/types/AdshiftConsentSnapshot.js +69 -0
- package/lib/commonjs/types/AdshiftConsentSnapshot.js.map +1 -0
- package/lib/commonjs/types/AdshiftDeepLink.js +154 -0
- package/lib/commonjs/types/AdshiftDeepLink.js.map +1 -0
- package/lib/commonjs/types/AdshiftError.js +91 -0
- package/lib/commonjs/types/AdshiftError.js.map +1 -0
- package/lib/commonjs/types/AdshiftEventParam.js +140 -0
- package/lib/commonjs/types/AdshiftEventParam.js.map +1 -0
- package/lib/commonjs/types/AdshiftEventType.js +88 -0
- package/lib/commonjs/types/AdshiftEventType.js.map +1 -0
- package/lib/commonjs/types/AdshiftThirdPartySharing.js +70 -0
- package/lib/commonjs/types/AdshiftThirdPartySharing.js.map +1 -0
- package/lib/commonjs/types/index.js +123 -0
- package/lib/commonjs/types/index.js.map +1 -0
- package/lib/commonjs/version.js +9 -0
- package/lib/commonjs/version.js.map +1 -0
- package/lib/module/Adshift.js +962 -296
- package/lib/module/Adshift.js.map +1 -1
- package/lib/module/NativeAdShiftReactNativePlugin.js +10 -7
- package/lib/module/NativeAdShiftReactNativePlugin.js.map +1 -1
- package/lib/module/index.js +26 -25
- package/lib/module/index.js.map +1 -1
- package/lib/module/jest/index.js +144 -0
- package/lib/module/jest/index.js.map +1 -0
- package/lib/module/nativeSdkVersions.js +13 -0
- package/lib/module/nativeSdkVersions.js.map +1 -0
- package/lib/module/types/AdshiftAdRevenue.js +43 -0
- package/lib/module/types/AdshiftAdRevenue.js.map +1 -0
- package/lib/module/types/AdshiftConfig.js +23 -26
- package/lib/module/types/AdshiftConfig.js.map +1 -1
- package/lib/module/types/AdshiftConsent.js +57 -50
- package/lib/module/types/AdshiftConsent.js.map +1 -1
- package/lib/module/types/AdshiftConsentSnapshot.js +65 -0
- package/lib/module/types/AdshiftConsentSnapshot.js.map +1 -0
- package/lib/module/types/AdshiftDeepLink.js +97 -67
- package/lib/module/types/AdshiftDeepLink.js.map +1 -1
- package/lib/module/types/AdshiftError.js +87 -0
- package/lib/module/types/AdshiftError.js.map +1 -0
- package/lib/module/types/AdshiftEventParam.js +135 -0
- package/lib/module/types/AdshiftEventParam.js.map +1 -0
- package/lib/module/types/AdshiftEventType.js +11 -36
- package/lib/module/types/AdshiftEventType.js.map +1 -1
- package/lib/module/types/AdshiftThirdPartySharing.js +65 -0
- package/lib/module/types/AdshiftThirdPartySharing.js.map +1 -0
- package/lib/module/types/index.js +9 -7
- package/lib/module/types/index.js.map +1 -1
- package/lib/module/version.js +5 -0
- package/lib/module/version.js.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/Adshift.d.ts +314 -0
- package/lib/typescript/commonjs/src/Adshift.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/NativeAdShiftReactNativePlugin.d.ts +102 -0
- package/lib/typescript/commonjs/src/NativeAdShiftReactNativePlugin.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +51 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/jest/index.d.ts +103 -0
- package/lib/typescript/commonjs/src/jest/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/nativeSdkVersions.d.ts +11 -0
- package/lib/typescript/commonjs/src/nativeSdkVersions.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types/AdshiftAdRevenue.d.ts +56 -0
- package/lib/typescript/commonjs/src/types/AdshiftAdRevenue.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types/AdshiftConfig.d.ts +104 -0
- package/lib/typescript/commonjs/src/types/AdshiftConfig.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types/AdshiftConsent.d.ts +76 -0
- package/lib/typescript/commonjs/src/types/AdshiftConsent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types/AdshiftConsentSnapshot.d.ts +56 -0
- package/lib/typescript/commonjs/src/types/AdshiftConsentSnapshot.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types/AdshiftDeepLink.d.ts +89 -0
- package/lib/typescript/commonjs/src/types/AdshiftDeepLink.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types/AdshiftError.d.ts +57 -0
- package/lib/typescript/commonjs/src/types/AdshiftError.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types/AdshiftEventParam.d.ts +111 -0
- package/lib/typescript/commonjs/src/types/AdshiftEventParam.d.ts.map +1 -0
- package/lib/typescript/{src → commonjs/src}/types/AdshiftEventType.d.ts +12 -35
- package/lib/typescript/commonjs/src/types/AdshiftEventType.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types/AdshiftThirdPartySharing.d.ts +53 -0
- package/lib/typescript/commonjs/src/types/AdshiftThirdPartySharing.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types/index.d.ts +17 -0
- package/lib/typescript/commonjs/src/types/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/version.d.ts +2 -0
- package/lib/typescript/commonjs/src/version.d.ts.map +1 -0
- package/lib/typescript/module/src/Adshift.d.ts +314 -0
- package/lib/typescript/module/src/Adshift.d.ts.map +1 -0
- package/lib/typescript/module/src/NativeAdShiftReactNativePlugin.d.ts +102 -0
- package/lib/typescript/module/src/NativeAdShiftReactNativePlugin.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +51 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/lib/typescript/module/src/jest/index.d.ts +103 -0
- package/lib/typescript/module/src/jest/index.d.ts.map +1 -0
- package/lib/typescript/module/src/nativeSdkVersions.d.ts +11 -0
- package/lib/typescript/module/src/nativeSdkVersions.d.ts.map +1 -0
- package/lib/typescript/module/src/types/AdshiftAdRevenue.d.ts +56 -0
- package/lib/typescript/module/src/types/AdshiftAdRevenue.d.ts.map +1 -0
- package/lib/typescript/module/src/types/AdshiftConfig.d.ts +104 -0
- package/lib/typescript/module/src/types/AdshiftConfig.d.ts.map +1 -0
- package/lib/typescript/module/src/types/AdshiftConsent.d.ts +76 -0
- package/lib/typescript/module/src/types/AdshiftConsent.d.ts.map +1 -0
- package/lib/typescript/module/src/types/AdshiftConsentSnapshot.d.ts +56 -0
- package/lib/typescript/module/src/types/AdshiftConsentSnapshot.d.ts.map +1 -0
- package/lib/typescript/module/src/types/AdshiftDeepLink.d.ts +89 -0
- package/lib/typescript/module/src/types/AdshiftDeepLink.d.ts.map +1 -0
- package/lib/typescript/module/src/types/AdshiftError.d.ts +57 -0
- package/lib/typescript/module/src/types/AdshiftError.d.ts.map +1 -0
- package/lib/typescript/module/src/types/AdshiftEventParam.d.ts +111 -0
- package/lib/typescript/module/src/types/AdshiftEventParam.d.ts.map +1 -0
- package/lib/typescript/module/src/types/AdshiftEventType.d.ts +64 -0
- package/lib/typescript/module/src/types/AdshiftEventType.d.ts.map +1 -0
- package/lib/typescript/module/src/types/AdshiftThirdPartySharing.d.ts +53 -0
- package/lib/typescript/module/src/types/AdshiftThirdPartySharing.d.ts.map +1 -0
- package/lib/typescript/module/src/types/index.d.ts +17 -0
- package/lib/typescript/module/src/types/index.d.ts.map +1 -0
- package/lib/typescript/module/src/version.d.ts +2 -0
- package/lib/typescript/module/src/version.d.ts.map +1 -0
- package/package.json +50 -11
- package/src/Adshift.ts +1276 -342
- package/src/NativeAdShiftReactNativePlugin.ts +81 -115
- package/src/index.tsx +40 -25
- package/src/jest/index.ts +224 -0
- package/src/nativeSdkVersions.ts +10 -0
- package/src/types/AdshiftAdRevenue.ts +58 -0
- package/src/types/AdshiftConfig.ts +101 -53
- package/src/types/AdshiftConsent.ts +75 -72
- package/src/types/AdshiftConsentSnapshot.ts +103 -0
- package/src/types/AdshiftDeepLink.ts +123 -102
- package/src/types/AdshiftError.ts +107 -0
- package/src/types/AdshiftEventParam.ts +216 -0
- package/src/types/AdshiftEventType.ts +13 -35
- package/src/types/AdshiftThirdPartySharing.ts +63 -0
- package/src/types/index.ts +38 -6
- package/src/version.ts +2 -0
- package/lib/typescript/src/Adshift.d.ts +0 -335
- package/lib/typescript/src/Adshift.d.ts.map +0 -1
- package/lib/typescript/src/NativeAdShiftReactNativePlugin.d.ts +0 -143
- package/lib/typescript/src/NativeAdShiftReactNativePlugin.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts +0 -47
- package/lib/typescript/src/index.d.ts.map +0 -1
- package/lib/typescript/src/types/AdshiftConfig.d.ts +0 -74
- package/lib/typescript/src/types/AdshiftConfig.d.ts.map +0 -1
- package/lib/typescript/src/types/AdshiftConsent.d.ts +0 -88
- package/lib/typescript/src/types/AdshiftConsent.d.ts.map +0 -1
- package/lib/typescript/src/types/AdshiftDeepLink.d.ts +0 -93
- package/lib/typescript/src/types/AdshiftDeepLink.d.ts.map +0 -1
- package/lib/typescript/src/types/AdshiftEventType.d.ts.map +0 -1
- package/lib/typescript/src/types/index.d.ts +0 -5
- package/lib/typescript/src/types/index.d.ts.map +0 -1
- /package/lib/typescript/{package.json → module/package.json} +0 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
package com.adshift.reactnativeplugin
|
|
2
|
+
|
|
3
|
+
import android.content.Intent
|
|
4
|
+
import android.os.Bundle
|
|
5
|
+
import com.adshift.sdk.core.AdShiftLib
|
|
6
|
+
import io.mockk.Runs
|
|
7
|
+
import io.mockk.every
|
|
8
|
+
import io.mockk.just
|
|
9
|
+
import io.mockk.mockkStatic
|
|
10
|
+
import io.mockk.unmockkStatic
|
|
11
|
+
import org.junit.After
|
|
12
|
+
import org.junit.Assert.assertEquals
|
|
13
|
+
import org.junit.Assert.assertNull
|
|
14
|
+
import org.junit.Before
|
|
15
|
+
import org.junit.Test
|
|
16
|
+
import org.junit.runner.RunWith
|
|
17
|
+
import org.robolectric.RobolectricTestRunner
|
|
18
|
+
import org.robolectric.annotation.Config
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Launch Intents reach the SDK once per delivery: a new payload is forwarded, while the same
|
|
22
|
+
* payload redelivered to a recreated Activity is not.
|
|
23
|
+
*/
|
|
24
|
+
@RunWith(RobolectricTestRunner::class)
|
|
25
|
+
@Config(sdk = [35])
|
|
26
|
+
class LaunchIntentForwardingTest {
|
|
27
|
+
|
|
28
|
+
private val forwardedExtras = mutableListOf<Bundle?>()
|
|
29
|
+
|
|
30
|
+
private lateinit var context: TestReactContext
|
|
31
|
+
private lateinit var module: AdShiftReactNativePluginModule
|
|
32
|
+
|
|
33
|
+
@Before
|
|
34
|
+
fun setUp() {
|
|
35
|
+
ModuleState.reset()
|
|
36
|
+
mockkStatic(AdShiftLib::class)
|
|
37
|
+
every { AdShiftLib.initSdk(any(), any()) } just Runs
|
|
38
|
+
every { AdShiftLib.setDeepLinkListener(any()) } just Runs
|
|
39
|
+
every { AdShiftLib.setDebugLog(any()) } just Runs
|
|
40
|
+
every { AdShiftLib.setBrandedDomains(any()) } just Runs
|
|
41
|
+
every { AdShiftLib.addPushNotificationDeepLinkPath(*anyVararg()) } just Runs
|
|
42
|
+
every { AdShiftLib.handleAppLinkIntent(any()) } just Runs
|
|
43
|
+
every { AdShiftLib.handlePushNotification(any<Bundle>()) } answers {
|
|
44
|
+
forwardedExtras += firstArg<Bundle?>()
|
|
45
|
+
false
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
context = TestReactContext()
|
|
49
|
+
module = AdShiftReactNativePluginModule(context.reactContext)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@After
|
|
53
|
+
fun tearDown() {
|
|
54
|
+
unmockkStatic(AdShiftLib::class)
|
|
55
|
+
ModuleState.reset()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@Test
|
|
59
|
+
fun `forwards a notification launch that carries no data uri`() {
|
|
60
|
+
context.launchIntent = launcherIntent()
|
|
61
|
+
module.initialize(initializeConfig())
|
|
62
|
+
|
|
63
|
+
context.launchIntent = notificationIntent(PUSH_LINK, MESSAGE_ID)
|
|
64
|
+
module.onHostResume()
|
|
65
|
+
|
|
66
|
+
assertEquals("deliveries forwarded to the SDK", 2, forwardedExtras.size)
|
|
67
|
+
assertNull("plain launcher start carries no extras", forwardedExtras[0])
|
|
68
|
+
assertEquals(PUSH_LINK, forwardedExtras[1]?.getString(PUSH_LINK_KEY))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@Test
|
|
72
|
+
fun `skips a launch intent redelivered to a recreated activity`() {
|
|
73
|
+
context.launchIntent = launcherIntent()
|
|
74
|
+
module.initialize(initializeConfig())
|
|
75
|
+
|
|
76
|
+
context.launchIntent = notificationIntent(PUSH_LINK, MESSAGE_ID)
|
|
77
|
+
module.onHostResume()
|
|
78
|
+
|
|
79
|
+
// Activity recreation hands over an equal Intent in a new instance.
|
|
80
|
+
context.launchIntent = notificationIntent(PUSH_LINK, MESSAGE_ID)
|
|
81
|
+
module.onHostResume()
|
|
82
|
+
|
|
83
|
+
assertEquals(
|
|
84
|
+
"notification payload forwarded once",
|
|
85
|
+
1,
|
|
86
|
+
forwardedExtras.count { it?.getString(PUSH_LINK_KEY) == PUSH_LINK },
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@Test
|
|
91
|
+
fun `skips a launch intent restored from history`() {
|
|
92
|
+
context.launchIntent = launcherIntent()
|
|
93
|
+
module.initialize(initializeConfig())
|
|
94
|
+
|
|
95
|
+
context.launchIntent = notificationIntent(PUSH_LINK, MESSAGE_ID)
|
|
96
|
+
.apply { addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) }
|
|
97
|
+
module.onHostResume()
|
|
98
|
+
|
|
99
|
+
assertEquals("deliveries forwarded to the SDK", 1, forwardedExtras.size)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private companion object {
|
|
103
|
+
const val PUSH_LINK = "https://links.example.com/promo?id=42"
|
|
104
|
+
const val MESSAGE_ID = "0:1757600000000000%abcdef"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
package com.adshift.reactnativeplugin
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import android.content.Intent
|
|
6
|
+
import androidx.test.core.app.ApplicationProvider
|
|
7
|
+
import com.facebook.react.bridge.JavaOnlyArray
|
|
8
|
+
import com.facebook.react.bridge.JavaOnlyMap
|
|
9
|
+
import com.facebook.react.bridge.Promise
|
|
10
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
11
|
+
import com.facebook.react.bridge.WritableMap
|
|
12
|
+
import com.facebook.soloader.nativeloader.NativeLoader
|
|
13
|
+
import com.facebook.soloader.nativeloader.NativeLoaderDelegate
|
|
14
|
+
import io.mockk.every
|
|
15
|
+
import io.mockk.mockk
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The module keeps its Intent bookkeeping in the companion object, so it survives module
|
|
19
|
+
* instances the way it survives JavaScript reloads. Each test starts from a freshly launched
|
|
20
|
+
* process, which this helper restores through reflection.
|
|
21
|
+
*/
|
|
22
|
+
internal object ModuleState {
|
|
23
|
+
|
|
24
|
+
fun reset() {
|
|
25
|
+
set("currentModule", null)
|
|
26
|
+
set("sdkInitialized", false)
|
|
27
|
+
set("readyForIntents", false)
|
|
28
|
+
set("deepLinkListenerRegistered", false)
|
|
29
|
+
set("autoHandleDeepLinks", true)
|
|
30
|
+
set("collectOaidApplied", false)
|
|
31
|
+
set("pendingIntent", null)
|
|
32
|
+
set("lastLaunchIntentFingerprint", null)
|
|
33
|
+
clear("processedIntents")
|
|
34
|
+
clear("autoForwardedUrls")
|
|
35
|
+
clear("launchForwardedUrls")
|
|
36
|
+
clear("registeredPushPaths")
|
|
37
|
+
clear("pendingDeepLinks")
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Deep link results still waiting for a JavaScript listener. */
|
|
41
|
+
fun pendingDeepLinkCount(): Int = (field("pendingDeepLinks").get(null) as Collection<*>).size
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Simulates the short dedup window having passed, so what remains is the memory that lasts
|
|
45
|
+
* as long as the process. A reload can happen minutes after the app was opened.
|
|
46
|
+
*/
|
|
47
|
+
fun expireAutoForwardWindow() = clear("autoForwardedUrls")
|
|
48
|
+
|
|
49
|
+
private fun set(name: String, value: Any?) = field(name).set(null, value)
|
|
50
|
+
|
|
51
|
+
private fun clear(name: String) {
|
|
52
|
+
when (val value = field(name).get(null)) {
|
|
53
|
+
is MutableCollection<*> -> value.clear()
|
|
54
|
+
is MutableMap<*, *> -> value.clear()
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private fun field(name: String) = AdShiftReactNativePluginModule::class.java
|
|
59
|
+
.getDeclaredField(name)
|
|
60
|
+
.apply { isAccessible = true }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Minimal React context for the module: only the members it touches are stubbed. [launchIntent]
|
|
65
|
+
* is what `currentActivity.intent` returns and may change between deliveries.
|
|
66
|
+
*/
|
|
67
|
+
internal class TestReactContext {
|
|
68
|
+
|
|
69
|
+
var launchIntent: Intent? = null
|
|
70
|
+
|
|
71
|
+
val reactContext: ReactApplicationContext = mockk(relaxed = true)
|
|
72
|
+
|
|
73
|
+
init {
|
|
74
|
+
val activity = mockk<Activity>(relaxed = true)
|
|
75
|
+
every { activity.intent } answers { launchIntent }
|
|
76
|
+
every { reactContext.currentActivity } answers { launchIntent?.let { activity } }
|
|
77
|
+
every { reactContext.applicationContext } returns
|
|
78
|
+
ApplicationProvider.getApplicationContext<Context>()
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
internal const val API_KEY = "test-api-key"
|
|
83
|
+
internal const val BRANDED_DOMAIN = "links.example.com"
|
|
84
|
+
internal const val PUSH_LINK_KEY = "as_push_link"
|
|
85
|
+
|
|
86
|
+
/** Config as the JavaScript layer sends it: branded domains, a push path and the debug flag. */
|
|
87
|
+
internal fun initializeConfig(): JavaOnlyMap = JavaOnlyMap().apply {
|
|
88
|
+
putString("apiKey", API_KEY)
|
|
89
|
+
putBoolean("isDebug", true)
|
|
90
|
+
putArray("brandedDomains", JavaOnlyArray.of(BRANDED_DOMAIN))
|
|
91
|
+
putArray("pushDeepLinkPaths", JavaOnlyArray.of(JavaOnlyArray.of(PUSH_LINK_KEY)))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** A plain launcher start: no data URI and no extras. */
|
|
95
|
+
internal fun launcherIntent(): Intent = Intent(Intent.ACTION_MAIN).apply {
|
|
96
|
+
addCategory(Intent.CATEGORY_LAUNCHER)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** A launcher start carrying a notification payload, as delivered by a push tap. */
|
|
100
|
+
internal fun notificationIntent(link: String, messageId: String): Intent = launcherIntent().apply {
|
|
101
|
+
putExtra(PUSH_LINK_KEY, link)
|
|
102
|
+
putExtra("google.message_id", messageId)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Records what the module answered, in place of the JavaScript promise. */
|
|
106
|
+
internal class RecordingPromise : Promise {
|
|
107
|
+
|
|
108
|
+
var resolved = false
|
|
109
|
+
private set
|
|
110
|
+
|
|
111
|
+
var resolvedValue: Any? = null
|
|
112
|
+
private set
|
|
113
|
+
|
|
114
|
+
var rejectionCode: String? = null
|
|
115
|
+
private set
|
|
116
|
+
|
|
117
|
+
/** A promise can be answered once, so tests can tell a late answer from the first one. */
|
|
118
|
+
var answers = 0
|
|
119
|
+
private set
|
|
120
|
+
|
|
121
|
+
override fun resolve(value: Any?) {
|
|
122
|
+
resolved = true
|
|
123
|
+
resolvedValue = value
|
|
124
|
+
answers++
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
override fun reject(code: String, message: String?) = record(code)
|
|
128
|
+
|
|
129
|
+
override fun reject(code: String, throwable: Throwable?) = record(code)
|
|
130
|
+
|
|
131
|
+
override fun reject(code: String, message: String?, throwable: Throwable?) = record(code)
|
|
132
|
+
|
|
133
|
+
override fun reject(throwable: Throwable) = record(null)
|
|
134
|
+
|
|
135
|
+
override fun reject(throwable: Throwable, userInfo: WritableMap) = record(null)
|
|
136
|
+
|
|
137
|
+
override fun reject(code: String, userInfo: WritableMap) = record(code)
|
|
138
|
+
|
|
139
|
+
override fun reject(code: String, throwable: Throwable?, userInfo: WritableMap) = record(code)
|
|
140
|
+
|
|
141
|
+
override fun reject(code: String, message: String?, userInfo: WritableMap) = record(code)
|
|
142
|
+
|
|
143
|
+
override fun reject(
|
|
144
|
+
code: String?,
|
|
145
|
+
message: String?,
|
|
146
|
+
throwable: Throwable?,
|
|
147
|
+
userInfo: WritableMap?,
|
|
148
|
+
) = record(code)
|
|
149
|
+
|
|
150
|
+
@Deprecated("Prefer passing a module-specific error code to JS.")
|
|
151
|
+
override fun reject(message: String) = record(null)
|
|
152
|
+
|
|
153
|
+
private fun record(code: String?) {
|
|
154
|
+
rejectionCode = code ?: "UNKNOWN"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Lets the JNI-backed callback type load without a native library behind it. */
|
|
159
|
+
internal fun allowNativeCallbacks() {
|
|
160
|
+
NativeLoader.initIfUninitialized(object : NativeLoaderDelegate {
|
|
161
|
+
override fun loadLibrary(shortName: String, flags: Int): Boolean = true
|
|
162
|
+
|
|
163
|
+
override fun getLibraryPath(shortName: String): String = shortName
|
|
164
|
+
|
|
165
|
+
override fun getSoSourcesVersion(): Int = 0
|
|
166
|
+
})
|
|
167
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
package com.adshift.reactnativeplugin
|
|
2
|
+
|
|
3
|
+
import android.os.Bundle
|
|
4
|
+
import android.os.Looper
|
|
5
|
+
import com.adshift.sdk.core.AdShiftLib
|
|
6
|
+
import com.adshift.sdk.core.AdShiftRequestListener
|
|
7
|
+
import com.facebook.react.bridge.Arguments
|
|
8
|
+
import com.facebook.react.bridge.JavaOnlyMap
|
|
9
|
+
import com.facebook.react.bridge.ReadableMap
|
|
10
|
+
import io.mockk.Runs
|
|
11
|
+
import io.mockk.every
|
|
12
|
+
import io.mockk.just
|
|
13
|
+
import io.mockk.mockkStatic
|
|
14
|
+
import io.mockk.unmockkStatic
|
|
15
|
+
import io.mockk.verify
|
|
16
|
+
import java.time.Duration
|
|
17
|
+
import org.junit.After
|
|
18
|
+
import org.junit.Assert.assertEquals
|
|
19
|
+
import org.junit.Assert.assertFalse
|
|
20
|
+
import org.junit.Assert.assertTrue
|
|
21
|
+
import org.junit.Before
|
|
22
|
+
import org.junit.Test
|
|
23
|
+
import org.junit.runner.RunWith
|
|
24
|
+
import org.robolectric.RobolectricTestRunner
|
|
25
|
+
import org.robolectric.Shadows.shadowOf
|
|
26
|
+
import org.robolectric.annotation.Config
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* `start` answers with what the SDK reported, so a device that opted out or a key the backend
|
|
30
|
+
* refused is visible to JavaScript instead of only reaching the log.
|
|
31
|
+
*/
|
|
32
|
+
@RunWith(RobolectricTestRunner::class)
|
|
33
|
+
@Config(sdk = [35])
|
|
34
|
+
class StartVerdictTest {
|
|
35
|
+
|
|
36
|
+
private var listener: AdShiftRequestListener? = null
|
|
37
|
+
|
|
38
|
+
private lateinit var context: TestReactContext
|
|
39
|
+
private lateinit var module: AdShiftReactNativePluginModule
|
|
40
|
+
|
|
41
|
+
@Before
|
|
42
|
+
fun setUp() {
|
|
43
|
+
ModuleState.reset()
|
|
44
|
+
mockkStatic(AdShiftLib::class)
|
|
45
|
+
mockkStatic(Arguments::class)
|
|
46
|
+
every { Arguments.createMap() } answers { JavaOnlyMap() }
|
|
47
|
+
every { AdShiftLib.initSdk(any(), any()) } just Runs
|
|
48
|
+
every { AdShiftLib.setDeepLinkListener(any()) } just Runs
|
|
49
|
+
every { AdShiftLib.setDebugLog(any()) } just Runs
|
|
50
|
+
every { AdShiftLib.setBrandedDomains(any()) } just Runs
|
|
51
|
+
every { AdShiftLib.addPushNotificationDeepLinkPath(*anyVararg()) } just Runs
|
|
52
|
+
every { AdShiftLib.handlePushNotification(any<Bundle>()) } returns false
|
|
53
|
+
every { AdShiftLib.handleAppLinkIntent(any()) } just Runs
|
|
54
|
+
every { AdShiftLib.start(any()) } answers { listener = firstArg() }
|
|
55
|
+
|
|
56
|
+
context = TestReactContext()
|
|
57
|
+
module = AdShiftReactNativePluginModule(context.reactContext)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@After
|
|
61
|
+
fun tearDown() {
|
|
62
|
+
unmockkStatic(AdShiftLib::class)
|
|
63
|
+
unmockkStatic(Arguments::class)
|
|
64
|
+
ModuleState.reset()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@Test
|
|
68
|
+
fun `reports a start before initialize as not initialized`() {
|
|
69
|
+
val promise = RecordingPromise()
|
|
70
|
+
module.start(promise)
|
|
71
|
+
drainMainThread()
|
|
72
|
+
|
|
73
|
+
assertFalse("success", result(promise).getBoolean("success"))
|
|
74
|
+
assertEquals("NOT_INITIALIZED", result(promise).getString("errorCode"))
|
|
75
|
+
verify(exactly = 0) { AdShiftLib.start(any()) }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@Test
|
|
79
|
+
fun `reports a device that opted out instead of a successful start`() {
|
|
80
|
+
initialize()
|
|
81
|
+
val promise = RecordingPromise()
|
|
82
|
+
|
|
83
|
+
module.start(promise)
|
|
84
|
+
drainMainThread()
|
|
85
|
+
listener?.onError(SdkErrorCode.STOP_TRACKING, "Device opted out of tracking")
|
|
86
|
+
|
|
87
|
+
assertFalse("success", result(promise).getBoolean("success"))
|
|
88
|
+
assertEquals("OPTED_OUT", result(promise).getString("errorCode"))
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@Test
|
|
92
|
+
fun `reports an api key the backend refused`() {
|
|
93
|
+
initialize()
|
|
94
|
+
val promise = RecordingPromise()
|
|
95
|
+
|
|
96
|
+
module.start(promise)
|
|
97
|
+
drainMainThread()
|
|
98
|
+
listener?.onError(SdkErrorCode.NO_DEV_KEY, "Invalid Dev Key")
|
|
99
|
+
|
|
100
|
+
assertFalse("success", result(promise).getBoolean("success"))
|
|
101
|
+
assertEquals("INVALID_API_KEY", result(promise).getString("errorCode"))
|
|
102
|
+
assertEquals("invalid", result(promise).getString("apiKeyValidationStatus"))
|
|
103
|
+
assertEquals(SdkErrorCode.NO_DEV_KEY, result(promise).getInt("nativeCode"))
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@Test
|
|
107
|
+
fun `reports a valid key when the sdk answers the start request`() {
|
|
108
|
+
initialize()
|
|
109
|
+
val promise = RecordingPromise()
|
|
110
|
+
|
|
111
|
+
module.start(promise)
|
|
112
|
+
drainMainThread()
|
|
113
|
+
listener?.onSuccess()
|
|
114
|
+
|
|
115
|
+
assertTrue("success", result(promise).getBoolean("success"))
|
|
116
|
+
assertEquals("valid", result(promise).getString("apiKeyValidationStatus"))
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@Test
|
|
120
|
+
fun `answers without a verdict rather than leaving javascript waiting`() {
|
|
121
|
+
initialize()
|
|
122
|
+
val promise = RecordingPromise()
|
|
123
|
+
|
|
124
|
+
module.start(promise)
|
|
125
|
+
drainMainThread()
|
|
126
|
+
assertEquals("answers before the wait elapsed", 0, promise.answers)
|
|
127
|
+
|
|
128
|
+
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(5))
|
|
129
|
+
|
|
130
|
+
assertTrue("success", result(promise).getBoolean("success"))
|
|
131
|
+
assertEquals("pending", result(promise).getString("apiKeyValidationStatus"))
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@Test
|
|
135
|
+
fun `keeps the first answer when the sdk reports twice`() {
|
|
136
|
+
initialize()
|
|
137
|
+
val promise = RecordingPromise()
|
|
138
|
+
|
|
139
|
+
module.start(promise)
|
|
140
|
+
drainMainThread()
|
|
141
|
+
listener?.onSuccess()
|
|
142
|
+
listener?.onError(SdkErrorCode.NO_DEV_KEY, "Invalid Dev Key")
|
|
143
|
+
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(5))
|
|
144
|
+
|
|
145
|
+
assertEquals("answers", 1, promise.answers)
|
|
146
|
+
assertTrue("success", result(promise).getBoolean("success"))
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private fun initialize() {
|
|
150
|
+
context.launchIntent = launcherIntent()
|
|
151
|
+
module.initialize(initializeConfig())
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private fun drainMainThread() = shadowOf(Looper.getMainLooper()).idle()
|
|
155
|
+
|
|
156
|
+
private fun result(promise: RecordingPromise): ReadableMap =
|
|
157
|
+
promise.resolvedValue as ReadableMap
|
|
158
|
+
|
|
159
|
+
/** Codes the SDK passes to `AdShiftRequestListener.onError`. */
|
|
160
|
+
private object SdkErrorCode {
|
|
161
|
+
const val STOP_TRACKING = 12
|
|
162
|
+
const val NO_DEV_KEY = 41
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -2,22 +2,22 @@
|
|
|
2
2
|
// AdShiftReactNativePlugin.h
|
|
3
3
|
// AdShiftReactNativePlugin
|
|
4
4
|
//
|
|
5
|
-
// Turbo Module header for AdShift React Native Plugin.
|
|
6
|
-
// Conforms to the Codegen-generated spec.
|
|
5
|
+
// Turbo Module header for the AdShift React Native Plugin.
|
|
7
6
|
//
|
|
8
7
|
// Copyright © 2025 AdShift. All rights reserved.
|
|
9
8
|
//
|
|
10
9
|
|
|
11
|
-
#import <React/
|
|
10
|
+
#import <React/RCTInvalidating.h>
|
|
12
11
|
#import <AdShiftReactNativePluginSpec/AdShiftReactNativePluginSpec.h>
|
|
13
12
|
|
|
14
13
|
NS_ASSUME_NONNULL_BEGIN
|
|
15
14
|
|
|
16
|
-
/// AdShift
|
|
15
|
+
/// AdShift Turbo Module.
|
|
17
16
|
///
|
|
18
|
-
///
|
|
19
|
-
///
|
|
20
|
-
|
|
17
|
+
/// Implements the Codegen-generated `NativeAdShiftReactNativePluginSpec` and
|
|
18
|
+
/// forwards every call to the Swift helper, which talks to the AdShift iOS SDK.
|
|
19
|
+
/// Deep link results reach JavaScript through the `onDeepLink` event.
|
|
20
|
+
@interface AdShiftReactNativePlugin : NativeAdShiftReactNativePluginSpecBase <NativeAdShiftReactNativePluginSpec, RCTInvalidating>
|
|
21
21
|
|
|
22
22
|
@end
|
|
23
23
|
|