react-native-mparticle 2.8.1 → 2.9.1
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/README.md +252 -94
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +6 -0
- package/android/gradle.properties +26 -0
- package/android/gradlew +160 -0
- package/android/gradlew.bat +90 -0
- package/android/libs/java-json.jar +0 -0
- package/android/src/main/java/com/mparticle/react/MParticleModule.kt +1 -1
- package/android/src/test/java/com/mparticle/react/IdentityApiTest.java +230 -0
- package/android/src/test/java/com/mparticle/react/MParticleUserTest.java +173 -0
- package/android/src/test/java/com/mparticle/react/testutils/MockMParticleUser.java +109 -0
- package/android/src/test/java/com/mparticle/react/testutils/MockMap.java +203 -0
- package/android/src/test/java/com/mparticle/react/testutils/MockReadableArray.java +68 -0
- package/android/src/test/java/com/mparticle/react/testutils/MockWritableMap.java +4 -0
- package/android/src/test/java/com/mparticle/react/testutils/Mutable.java +13 -0
- package/app.plugin.js +1 -0
- package/ios/RNMParticle/RNMPRokt.mm +93 -20
- package/ios/RNMParticle/RNMParticle.mm +2 -1
- package/ios/RNMParticle/RoktEventManager.m +24 -0
- package/js/codegenSpecs/NativeMParticle.ts +3 -4
- package/js/rokt/rokt-layout-view.android.tsx +2 -1
- package/lib/codegenSpecs/NativeMParticle.d.ts +3 -4
- package/lib/codegenSpecs/NativeMParticle.js.map +1 -1
- package/lib/rokt/rokt-layout-view.android.js +1 -0
- package/lib/rokt/rokt-layout-view.android.js.map +1 -1
- package/package.json +28 -4
- package/plugin/build/withMParticle.d.ts +60 -0
- package/plugin/build/withMParticle.js +30 -0
- package/plugin/build/withMParticleAndroid.d.ts +6 -0
- package/plugin/build/withMParticleAndroid.js +266 -0
- package/plugin/build/withMParticleIOS.d.ts +6 -0
- package/plugin/build/withMParticleIOS.js +362 -0
- package/plugin/src/withMParticle.ts +106 -0
- package/plugin/src/withMParticleAndroid.ts +359 -0
- package/plugin/src/withMParticleIOS.ts +459 -0
- package/plugin/tsconfig.json +8 -0
- package/react-native-mparticle.podspec +11 -0
- package/SECURITY.md +0 -9
package/android/gradlew
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
##############################################################################
|
|
4
|
+
##
|
|
5
|
+
## Gradle start up script for UN*X
|
|
6
|
+
##
|
|
7
|
+
##############################################################################
|
|
8
|
+
|
|
9
|
+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
10
|
+
DEFAULT_JVM_OPTS=""
|
|
11
|
+
|
|
12
|
+
APP_NAME="Gradle"
|
|
13
|
+
APP_BASE_NAME=`basename "$0"`
|
|
14
|
+
|
|
15
|
+
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
|
16
|
+
MAX_FD="maximum"
|
|
17
|
+
|
|
18
|
+
warn ( ) {
|
|
19
|
+
echo "$*"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
die ( ) {
|
|
23
|
+
echo
|
|
24
|
+
echo "$*"
|
|
25
|
+
echo
|
|
26
|
+
exit 1
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
# OS specific support (must be 'true' or 'false').
|
|
30
|
+
cygwin=false
|
|
31
|
+
msys=false
|
|
32
|
+
darwin=false
|
|
33
|
+
case "`uname`" in
|
|
34
|
+
CYGWIN* )
|
|
35
|
+
cygwin=true
|
|
36
|
+
;;
|
|
37
|
+
Darwin* )
|
|
38
|
+
darwin=true
|
|
39
|
+
;;
|
|
40
|
+
MINGW* )
|
|
41
|
+
msys=true
|
|
42
|
+
;;
|
|
43
|
+
esac
|
|
44
|
+
|
|
45
|
+
# Attempt to set APP_HOME
|
|
46
|
+
# Resolve links: $0 may be a link
|
|
47
|
+
PRG="$0"
|
|
48
|
+
# Need this for relative symlinks.
|
|
49
|
+
while [ -h "$PRG" ] ; do
|
|
50
|
+
ls=`ls -ld "$PRG"`
|
|
51
|
+
link=`expr "$ls" : '.*-> \(.*\)$'`
|
|
52
|
+
if expr "$link" : '/.*' > /dev/null; then
|
|
53
|
+
PRG="$link"
|
|
54
|
+
else
|
|
55
|
+
PRG=`dirname "$PRG"`"/$link"
|
|
56
|
+
fi
|
|
57
|
+
done
|
|
58
|
+
SAVED="`pwd`"
|
|
59
|
+
cd "`dirname \"$PRG\"`/" >/dev/null
|
|
60
|
+
APP_HOME="`pwd -P`"
|
|
61
|
+
cd "$SAVED" >/dev/null
|
|
62
|
+
|
|
63
|
+
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
|
64
|
+
|
|
65
|
+
# Determine the Java command to use to start the JVM.
|
|
66
|
+
if [ -n "$JAVA_HOME" ] ; then
|
|
67
|
+
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
|
68
|
+
# IBM's JDK on AIX uses strange locations for the executables
|
|
69
|
+
JAVACMD="$JAVA_HOME/jre/sh/java"
|
|
70
|
+
else
|
|
71
|
+
JAVACMD="$JAVA_HOME/bin/java"
|
|
72
|
+
fi
|
|
73
|
+
if [ ! -x "$JAVACMD" ] ; then
|
|
74
|
+
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
|
75
|
+
|
|
76
|
+
Please set the JAVA_HOME variable in your environment to match the
|
|
77
|
+
location of your Java installation."
|
|
78
|
+
fi
|
|
79
|
+
else
|
|
80
|
+
JAVACMD="java"
|
|
81
|
+
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
82
|
+
|
|
83
|
+
Please set the JAVA_HOME variable in your environment to match the
|
|
84
|
+
location of your Java installation."
|
|
85
|
+
fi
|
|
86
|
+
|
|
87
|
+
# Increase the maximum file descriptors if we can.
|
|
88
|
+
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
|
89
|
+
MAX_FD_LIMIT=`ulimit -H -n`
|
|
90
|
+
if [ $? -eq 0 ] ; then
|
|
91
|
+
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
|
92
|
+
MAX_FD="$MAX_FD_LIMIT"
|
|
93
|
+
fi
|
|
94
|
+
ulimit -n $MAX_FD
|
|
95
|
+
if [ $? -ne 0 ] ; then
|
|
96
|
+
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
|
97
|
+
fi
|
|
98
|
+
else
|
|
99
|
+
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
|
100
|
+
fi
|
|
101
|
+
fi
|
|
102
|
+
|
|
103
|
+
# For Darwin, add options to specify how the application appears in the dock
|
|
104
|
+
if $darwin; then
|
|
105
|
+
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
|
106
|
+
fi
|
|
107
|
+
|
|
108
|
+
# For Cygwin, switch paths to Windows format before running java
|
|
109
|
+
if $cygwin ; then
|
|
110
|
+
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
|
111
|
+
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
|
112
|
+
JAVACMD=`cygpath --unix "$JAVACMD"`
|
|
113
|
+
|
|
114
|
+
# We build the pattern for arguments to be converted via cygpath
|
|
115
|
+
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
|
116
|
+
SEP=""
|
|
117
|
+
for dir in $ROOTDIRSRAW ; do
|
|
118
|
+
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
|
119
|
+
SEP="|"
|
|
120
|
+
done
|
|
121
|
+
OURCYGPATTERN="(^($ROOTDIRS))"
|
|
122
|
+
# Add a user-defined pattern to the cygpath arguments
|
|
123
|
+
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
|
124
|
+
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
|
125
|
+
fi
|
|
126
|
+
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
127
|
+
i=0
|
|
128
|
+
for arg in "$@" ; do
|
|
129
|
+
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
|
130
|
+
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
|
131
|
+
|
|
132
|
+
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
|
133
|
+
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
|
134
|
+
else
|
|
135
|
+
eval `echo args$i`="\"$arg\""
|
|
136
|
+
fi
|
|
137
|
+
i=$((i+1))
|
|
138
|
+
done
|
|
139
|
+
case $i in
|
|
140
|
+
(0) set -- ;;
|
|
141
|
+
(1) set -- "$args0" ;;
|
|
142
|
+
(2) set -- "$args0" "$args1" ;;
|
|
143
|
+
(3) set -- "$args0" "$args1" "$args2" ;;
|
|
144
|
+
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
|
145
|
+
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
|
146
|
+
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
|
147
|
+
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
|
148
|
+
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
|
149
|
+
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
|
150
|
+
esac
|
|
151
|
+
fi
|
|
152
|
+
|
|
153
|
+
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
|
154
|
+
function splitJvmOpts() {
|
|
155
|
+
JVM_OPTS=("$@")
|
|
156
|
+
}
|
|
157
|
+
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
|
158
|
+
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
|
159
|
+
|
|
160
|
+
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
@if "%DEBUG%" == "" @echo off
|
|
2
|
+
@rem ##########################################################################
|
|
3
|
+
@rem
|
|
4
|
+
@rem Gradle startup script for Windows
|
|
5
|
+
@rem
|
|
6
|
+
@rem ##########################################################################
|
|
7
|
+
|
|
8
|
+
@rem Set local scope for the variables with windows NT shell
|
|
9
|
+
if "%OS%"=="Windows_NT" setlocal
|
|
10
|
+
|
|
11
|
+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
12
|
+
set DEFAULT_JVM_OPTS=
|
|
13
|
+
|
|
14
|
+
set DIRNAME=%~dp0
|
|
15
|
+
if "%DIRNAME%" == "" set DIRNAME=.
|
|
16
|
+
set APP_BASE_NAME=%~n0
|
|
17
|
+
set APP_HOME=%DIRNAME%
|
|
18
|
+
|
|
19
|
+
@rem Find java.exe
|
|
20
|
+
if defined JAVA_HOME goto findJavaFromJavaHome
|
|
21
|
+
|
|
22
|
+
set JAVA_EXE=java.exe
|
|
23
|
+
%JAVA_EXE% -version >NUL 2>&1
|
|
24
|
+
if "%ERRORLEVEL%" == "0" goto init
|
|
25
|
+
|
|
26
|
+
echo.
|
|
27
|
+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
28
|
+
echo.
|
|
29
|
+
echo Please set the JAVA_HOME variable in your environment to match the
|
|
30
|
+
echo location of your Java installation.
|
|
31
|
+
|
|
32
|
+
goto fail
|
|
33
|
+
|
|
34
|
+
:findJavaFromJavaHome
|
|
35
|
+
set JAVA_HOME=%JAVA_HOME:"=%
|
|
36
|
+
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|
37
|
+
|
|
38
|
+
if exist "%JAVA_EXE%" goto init
|
|
39
|
+
|
|
40
|
+
echo.
|
|
41
|
+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
|
42
|
+
echo.
|
|
43
|
+
echo Please set the JAVA_HOME variable in your environment to match the
|
|
44
|
+
echo location of your Java installation.
|
|
45
|
+
|
|
46
|
+
goto fail
|
|
47
|
+
|
|
48
|
+
:init
|
|
49
|
+
@rem Get command-line arguments, handling Windowz variants
|
|
50
|
+
|
|
51
|
+
if not "%OS%" == "Windows_NT" goto win9xME_args
|
|
52
|
+
if "%@eval[2+2]" == "4" goto 4NT_args
|
|
53
|
+
|
|
54
|
+
:win9xME_args
|
|
55
|
+
@rem Slurp the command line arguments.
|
|
56
|
+
set CMD_LINE_ARGS=
|
|
57
|
+
set _SKIP=2
|
|
58
|
+
|
|
59
|
+
:win9xME_args_slurp
|
|
60
|
+
if "x%~1" == "x" goto execute
|
|
61
|
+
|
|
62
|
+
set CMD_LINE_ARGS=%*
|
|
63
|
+
goto execute
|
|
64
|
+
|
|
65
|
+
:4NT_args
|
|
66
|
+
@rem Get arguments from the 4NT Shell from JP Software
|
|
67
|
+
set CMD_LINE_ARGS=%$
|
|
68
|
+
|
|
69
|
+
:execute
|
|
70
|
+
@rem Setup the command line
|
|
71
|
+
|
|
72
|
+
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
|
73
|
+
|
|
74
|
+
@rem Execute Gradle
|
|
75
|
+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
|
76
|
+
|
|
77
|
+
:end
|
|
78
|
+
@rem End local scope for the variables with windows NT shell
|
|
79
|
+
if "%ERRORLEVEL%"=="0" goto mainEnd
|
|
80
|
+
|
|
81
|
+
:fail
|
|
82
|
+
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
|
83
|
+
rem the _cmd.exe /c_ return code!
|
|
84
|
+
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
|
85
|
+
exit /b 1
|
|
86
|
+
|
|
87
|
+
:mainEnd
|
|
88
|
+
if "%OS%"=="Windows_NT" endlocal
|
|
89
|
+
|
|
90
|
+
:omega
|
|
Binary file
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
package com.mparticle.react;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.bridge.Callback;
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
7
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
8
|
+
import com.mparticle.MParticle;
|
|
9
|
+
import com.mparticle.identity.AliasRequest;
|
|
10
|
+
import com.mparticle.identity.IdentityApi;
|
|
11
|
+
import com.mparticle.identity.MParticleUser;
|
|
12
|
+
import com.mparticle.react.testutils.MockMParticleUser;
|
|
13
|
+
import com.mparticle.react.testutils.MockMap;
|
|
14
|
+
import com.mparticle.react.testutils.Mutable;
|
|
15
|
+
|
|
16
|
+
import org.json.JSONException;
|
|
17
|
+
import org.json.JSONObject;
|
|
18
|
+
import org.junit.Before;
|
|
19
|
+
import org.junit.Test;
|
|
20
|
+
import org.junit.runner.RunWith;
|
|
21
|
+
import org.mockito.ArgumentCaptor;
|
|
22
|
+
import org.mockito.Mockito;
|
|
23
|
+
import org.mockito.MockitoAnnotations;
|
|
24
|
+
import org.mockito.junit.MockitoJUnitRunner;
|
|
25
|
+
|
|
26
|
+
import java.util.Random;
|
|
27
|
+
|
|
28
|
+
import static junit.framework.TestCase.assertEquals;
|
|
29
|
+
import static org.junit.Assert.assertNull;
|
|
30
|
+
import static org.junit.Assert.assertTrue;
|
|
31
|
+
|
|
32
|
+
@RunWith(MockitoJUnitRunner.class)
|
|
33
|
+
public class IdentityApiTest {
|
|
34
|
+
MParticleModule identityApi;
|
|
35
|
+
Random random = new Random();
|
|
36
|
+
|
|
37
|
+
@Before
|
|
38
|
+
public void before() {
|
|
39
|
+
MockitoAnnotations.openMocks(this);
|
|
40
|
+
MParticle.setInstance(Mockito.mock(MParticle.class));
|
|
41
|
+
Mockito.when(MParticle.getInstance().Identity()).thenReturn(Mockito.mock(IdentityApi.class));
|
|
42
|
+
Mockito.lenient().when(MParticle.getInstance().Identity().getUser(0L)).thenReturn(null);
|
|
43
|
+
identityApi = new MParticleModule(Mockito.mock(ReactApplicationContext.class));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@Test
|
|
48
|
+
public void testGetCurrentUser() {
|
|
49
|
+
final Mutable<Boolean> callbackCalled = new Mutable<>(false);
|
|
50
|
+
final Long mockId = random.nextLong();
|
|
51
|
+
|
|
52
|
+
MParticleUser mockUser = new MockMParticleUser() {
|
|
53
|
+
@NonNull
|
|
54
|
+
@Override
|
|
55
|
+
public long getId() {
|
|
56
|
+
return mockId;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
Mockito.when(MParticle.getInstance().Identity().getCurrentUser()).thenReturn(mockUser);
|
|
60
|
+
identityApi.getCurrentUserWithCompletion(new Callback() {
|
|
61
|
+
@Override
|
|
62
|
+
public void invoke(Object... args) {
|
|
63
|
+
assertNull(args[0]);
|
|
64
|
+
assertEquals(mockId.toString(), args[1]);
|
|
65
|
+
callbackCalled.value = true;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
assertTrue(callbackCalled.value);
|
|
70
|
+
callbackCalled.value = false;
|
|
71
|
+
|
|
72
|
+
Mockito.when(MParticle.getInstance().Identity().getCurrentUser()).thenReturn(null);
|
|
73
|
+
identityApi.getCurrentUserWithCompletion(new Callback() {
|
|
74
|
+
@Override
|
|
75
|
+
public void invoke(Object... args) {
|
|
76
|
+
assertNull(args[0]);
|
|
77
|
+
assertNull(args[1]);
|
|
78
|
+
callbackCalled.value = true;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
assertTrue(callbackCalled.value);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@Test
|
|
86
|
+
public void testAliasRequest() throws JSONException {
|
|
87
|
+
ArgumentCaptor<AliasRequest> aliasCaptor = ArgumentCaptor.forClass(AliasRequest.class);
|
|
88
|
+
final Mutable<Object[]> callbackResult = new Mutable<>();
|
|
89
|
+
|
|
90
|
+
Mockito.when(MParticle.getInstance().Identity().aliasUsers(Mockito.any(AliasRequest.class))).thenReturn(true);
|
|
91
|
+
|
|
92
|
+
JSONObject aliasJson = new JSONObject()
|
|
93
|
+
.put("sourceMpid", "1")
|
|
94
|
+
.put("destinationMpid", "2")
|
|
95
|
+
.put("startTime", "3")
|
|
96
|
+
.put("endTime", "4");
|
|
97
|
+
ReadableMap map = new MockMap(aliasJson);
|
|
98
|
+
|
|
99
|
+
identityApi.aliasUsers(map, new Callback() {
|
|
100
|
+
@Override
|
|
101
|
+
public void invoke(Object... args) {
|
|
102
|
+
callbackResult.value = args;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
Mockito.verify(MParticle.getInstance().Identity()).aliasUsers(aliasCaptor.capture());
|
|
107
|
+
assertEquals(1, callbackResult.value.length);
|
|
108
|
+
assertEquals(true, callbackResult.value[0]);
|
|
109
|
+
|
|
110
|
+
assertEquals(1, aliasCaptor.getValue().getSourceMpid());
|
|
111
|
+
assertEquals(2, aliasCaptor.getValue().getDestinationMpid());
|
|
112
|
+
assertEquals(3, aliasCaptor.getValue().getStartTime());
|
|
113
|
+
assertEquals(4, aliasCaptor.getValue().getEndTime());
|
|
114
|
+
|
|
115
|
+
//start time and end time can be longs
|
|
116
|
+
aliasJson
|
|
117
|
+
.put("startTime", 3)
|
|
118
|
+
.put("endTime", 4);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@Test
|
|
122
|
+
public void testAliasRequestPartial() throws JSONException {
|
|
123
|
+
ArgumentCaptor<AliasRequest> aliasCaptor = ArgumentCaptor.forClass(AliasRequest.class);
|
|
124
|
+
final Mutable<Object[]> callbackResult = new Mutable<>();
|
|
125
|
+
Long startTime = System.currentTimeMillis();
|
|
126
|
+
|
|
127
|
+
MParticleUser sourceUser = Mockito.mock(MParticleUser.class);
|
|
128
|
+
Mockito.when(sourceUser.getId()).thenReturn(1L);
|
|
129
|
+
Mockito.when(sourceUser.getFirstSeenTime()).thenReturn(startTime - 200);
|
|
130
|
+
Mockito.when(sourceUser.getLastSeenTime()).thenReturn(startTime - 100L);
|
|
131
|
+
|
|
132
|
+
MParticleUser destinationUser = Mockito.mock(MParticleUser.class);
|
|
133
|
+
Mockito.when(destinationUser.getId()).thenReturn(2L);
|
|
134
|
+
|
|
135
|
+
Mockito.when(MParticle.getInstance().Identity().getUser(1L)).thenReturn(sourceUser);
|
|
136
|
+
Mockito.when(MParticle.getInstance().Identity().getUser(2L)).thenReturn(destinationUser);
|
|
137
|
+
|
|
138
|
+
Mockito.when(MParticle.getInstance().Identity().aliasUsers(Mockito.any(AliasRequest.class))).thenReturn(true);
|
|
139
|
+
|
|
140
|
+
JSONObject aliasJson = new JSONObject()
|
|
141
|
+
.put("sourceMpid", "1")
|
|
142
|
+
.put("destinationMpid", "2");
|
|
143
|
+
ReadableMap map = new MockMap(aliasJson);
|
|
144
|
+
|
|
145
|
+
identityApi.aliasUsers(map, new Callback() {
|
|
146
|
+
@Override
|
|
147
|
+
public void invoke(Object... args) {
|
|
148
|
+
callbackResult.value = args;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
Mockito.verify(MParticle.getInstance().Identity()).aliasUsers(aliasCaptor.capture());
|
|
153
|
+
assertEquals(1, callbackResult.value.length);
|
|
154
|
+
assertEquals(true, callbackResult.value[0]);
|
|
155
|
+
|
|
156
|
+
assertEquals(1, aliasCaptor.getValue().getSourceMpid());
|
|
157
|
+
assertEquals(2, aliasCaptor.getValue().getDestinationMpid());
|
|
158
|
+
assertEquals(startTime - 200, aliasCaptor.getValue().getStartTime());
|
|
159
|
+
assertEquals(startTime - 100, aliasCaptor.getValue().getEndTime());
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
@Test
|
|
163
|
+
public void testAliasRejectedReactNative() throws JSONException {
|
|
164
|
+
final Mutable<Object[]> callbackResult = new Mutable<>();
|
|
165
|
+
Callback callback = new Callback() {
|
|
166
|
+
@Override
|
|
167
|
+
public void invoke(Object... args) {
|
|
168
|
+
callbackResult.value = args;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
//MPIDs need to be Strings, this will fail
|
|
173
|
+
JSONObject aliasJson = new JSONObject()
|
|
174
|
+
.put("sourceMpid", 1)
|
|
175
|
+
.put("destinationMpid", "2")
|
|
176
|
+
.put("startTime", "3")
|
|
177
|
+
.put("endTime", "4");
|
|
178
|
+
|
|
179
|
+
identityApi.aliasUsers(new MockMap(aliasJson), callback);
|
|
180
|
+
|
|
181
|
+
Mockito.lenient().when(MParticle.getInstance().Identity().aliasUsers(Mockito.any(AliasRequest.class))).thenThrow(new RuntimeException("aliasUsers() should not be called"));
|
|
182
|
+
assertEquals(2, callbackResult.value.length);
|
|
183
|
+
assertEquals(false, callbackResult.value[0]);
|
|
184
|
+
assertTrue(((String)callbackResult.value[1]).length() > 5);
|
|
185
|
+
callbackResult.value = null;
|
|
186
|
+
|
|
187
|
+
aliasJson
|
|
188
|
+
.put("sourceMpid", "1")
|
|
189
|
+
.put("destinationMpid", 2);
|
|
190
|
+
|
|
191
|
+
identityApi.aliasUsers(new MockMap(aliasJson), callback);
|
|
192
|
+
|
|
193
|
+
Mockito.lenient().when(MParticle.getInstance().Identity().aliasUsers(Mockito.any(AliasRequest.class))).thenThrow(new RuntimeException("aliasUsers() should not be called"));
|
|
194
|
+
assertEquals(2, callbackResult.value.length);
|
|
195
|
+
assertEquals(false, callbackResult.value[0]);
|
|
196
|
+
assertTrue(((String)callbackResult.value[1]).length() > 5);
|
|
197
|
+
callbackResult.value = null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
@Test
|
|
201
|
+
public void testAliasRejectedNativeSdk() throws JSONException {
|
|
202
|
+
ArgumentCaptor<AliasRequest> aliasCaptor = ArgumentCaptor.forClass(AliasRequest.class);
|
|
203
|
+
final Mutable<Object[]> callbackResult = new Mutable<>();
|
|
204
|
+
|
|
205
|
+
Mockito.when(MParticle.getInstance().Identity().aliasUsers(Mockito.any(AliasRequest.class))).thenReturn(false);
|
|
206
|
+
|
|
207
|
+
JSONObject aliasJson = new JSONObject()
|
|
208
|
+
.put("sourceMpid", "1")
|
|
209
|
+
.put("destinationMpid", "2")
|
|
210
|
+
.put("startTime", "3")
|
|
211
|
+
.put("endTime", "4");
|
|
212
|
+
ReadableMap map = new MockMap(aliasJson);
|
|
213
|
+
|
|
214
|
+
identityApi.aliasUsers(map, new Callback() {
|
|
215
|
+
@Override
|
|
216
|
+
public void invoke(Object... args) {
|
|
217
|
+
callbackResult.value = args;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
Mockito.verify(MParticle.getInstance().Identity()).aliasUsers(aliasCaptor.capture());
|
|
222
|
+
assertEquals(1, callbackResult.value.length);
|
|
223
|
+
assertEquals(false, callbackResult.value[0]);
|
|
224
|
+
|
|
225
|
+
assertEquals(1, aliasCaptor.getValue().getSourceMpid());
|
|
226
|
+
assertEquals(2, aliasCaptor.getValue().getDestinationMpid());
|
|
227
|
+
assertEquals(3, aliasCaptor.getValue().getStartTime());
|
|
228
|
+
assertEquals(4, aliasCaptor.getValue().getEndTime());
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
package com.mparticle.react;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.bridge.Callback;
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
7
|
+
import com.facebook.react.bridge.WritableMap;
|
|
8
|
+
import com.mparticle.MParticle;
|
|
9
|
+
import com.mparticle.identity.IdentityApi;
|
|
10
|
+
import com.mparticle.identity.MParticleUser;
|
|
11
|
+
import com.mparticle.react.testutils.MockMParticleUser;
|
|
12
|
+
import com.mparticle.react.testutils.MockMap;
|
|
13
|
+
import com.mparticle.react.testutils.MockReadableArray;
|
|
14
|
+
import com.mparticle.react.testutils.Mutable;
|
|
15
|
+
|
|
16
|
+
import org.junit.Before;
|
|
17
|
+
import org.junit.Test;
|
|
18
|
+
import org.junit.runner.RunWith;
|
|
19
|
+
import org.mockito.Mockito;
|
|
20
|
+
import org.mockito.MockitoAnnotations;
|
|
21
|
+
import org.mockito.junit.MockitoJUnitRunner;
|
|
22
|
+
|
|
23
|
+
import java.util.HashMap;
|
|
24
|
+
import java.util.Map;
|
|
25
|
+
import java.util.Random;
|
|
26
|
+
|
|
27
|
+
import static junit.framework.TestCase.assertEquals;
|
|
28
|
+
import static org.junit.Assert.assertNotNull;
|
|
29
|
+
import static org.junit.Assert.assertNull;
|
|
30
|
+
import static org.junit.Assert.assertTrue;
|
|
31
|
+
import static org.mockito.Mockito.doReturn;
|
|
32
|
+
|
|
33
|
+
@RunWith(MockitoJUnitRunner.class)
|
|
34
|
+
public class MParticleUserTest {
|
|
35
|
+
MParticleModule mParticleUser;
|
|
36
|
+
Random random = new Random();
|
|
37
|
+
|
|
38
|
+
@Before
|
|
39
|
+
public void before() {
|
|
40
|
+
MockitoAnnotations.openMocks(this);
|
|
41
|
+
MParticle.setInstance(Mockito.mock(MParticle.class));
|
|
42
|
+
Mockito.when(MParticle.getInstance().Identity()).thenReturn(Mockito.mock(IdentityApi.class));
|
|
43
|
+
Mockito.lenient().when(MParticle.getInstance().Identity().getUser(0L)).thenReturn(null);
|
|
44
|
+
MParticleModule realModule = new MParticleModule(Mockito.mock(ReactApplicationContext.class));
|
|
45
|
+
mParticleUser = Mockito.spy(realModule);
|
|
46
|
+
doReturn(new MockMap()).when(mParticleUser).getWritableMap();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@Test
|
|
50
|
+
public void testSetUserAttribute() {
|
|
51
|
+
String testKey = "test key";
|
|
52
|
+
String testValue = "test value";
|
|
53
|
+
|
|
54
|
+
final Mutable<String> uaKey = new Mutable<>();
|
|
55
|
+
final Mutable<Object> uaValue = new Mutable<>();
|
|
56
|
+
MParticleUser mockUser = new MockMParticleUser() {
|
|
57
|
+
@Override
|
|
58
|
+
public boolean setUserAttribute(@NonNull String s, @NonNull Object o) {
|
|
59
|
+
uaKey.value = s;
|
|
60
|
+
uaValue.value = o;
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
Mockito.when(MParticle.getInstance().Identity().getUser(Mockito.anyLong())).thenReturn(mockUser);
|
|
65
|
+
|
|
66
|
+
mParticleUser.setUserAttribute("1", testKey, testValue);
|
|
67
|
+
|
|
68
|
+
assertEquals(testKey, uaKey.value);
|
|
69
|
+
assertEquals(testValue, uaValue.value);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@Test
|
|
73
|
+
public void getUserIdentitiesTest() {
|
|
74
|
+
final Map<MParticle.IdentityType, String> identities = new HashMap<>();
|
|
75
|
+
for (MParticle.IdentityType identityType: MParticle.IdentityType.values()) {
|
|
76
|
+
identities.put(identityType, random.nextInt() + "");
|
|
77
|
+
}
|
|
78
|
+
MParticleUser mockUser = new MockMParticleUser() {
|
|
79
|
+
@NonNull
|
|
80
|
+
@Override
|
|
81
|
+
public Map<MParticle.IdentityType, String> getUserIdentities() {
|
|
82
|
+
return identities;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
Mockito.when(MParticle.getInstance().Identity().getUser(Mockito.anyLong())).thenReturn(mockUser);
|
|
87
|
+
|
|
88
|
+
final Mutable<WritableMap> callbackResult = new Mutable<>();
|
|
89
|
+
mParticleUser.getUserIdentities("1", new Callback() {
|
|
90
|
+
@Override
|
|
91
|
+
public void invoke(Object... args) {
|
|
92
|
+
assertEquals(2, args.length);
|
|
93
|
+
assertNull(args[0]);
|
|
94
|
+
callbackResult.value = (WritableMap)args[1];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
assertNotNull(callbackResult.value);
|
|
99
|
+
for (Map.Entry<MParticle.IdentityType, String> entry: identities.entrySet()) {
|
|
100
|
+
assertEquals(entry.getValue(), callbackResult.value.getString(String.valueOf(entry.getKey().getValue())));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@Test
|
|
105
|
+
public void testSetUserTag() {
|
|
106
|
+
final Mutable<String> tag = new Mutable<>();
|
|
107
|
+
String testTag = "testTag";
|
|
108
|
+
|
|
109
|
+
MParticleUser mockUser = new MockMParticleUser() {
|
|
110
|
+
@Override
|
|
111
|
+
public boolean setUserTag(@NonNull String s) {
|
|
112
|
+
tag.value = s;
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
Mockito.when(MParticle.getInstance().Identity().getUser(Mockito.anyLong())).thenReturn(mockUser);
|
|
118
|
+
|
|
119
|
+
mParticleUser.setUserTag("1", testTag);
|
|
120
|
+
|
|
121
|
+
assertEquals(testTag, tag.value);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
@Test
|
|
127
|
+
public void getFirstSeenTime() {
|
|
128
|
+
final Mutable<Boolean> callbackInvoked = new Mutable<>(false);
|
|
129
|
+
|
|
130
|
+
MParticleUser mockUser = new MockMParticleUser() {
|
|
131
|
+
@Override
|
|
132
|
+
public long getFirstSeenTime() {
|
|
133
|
+
return 2;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
Mockito.when(MParticle.getInstance().Identity().getUser(Mockito.anyLong())).thenReturn(mockUser);
|
|
137
|
+
|
|
138
|
+
mParticleUser.getFirstSeen("1", new Callback() {
|
|
139
|
+
@Override
|
|
140
|
+
public void invoke(Object... args) {
|
|
141
|
+
assertEquals(1, args.length);
|
|
142
|
+
assertEquals("2", args[0]);
|
|
143
|
+
callbackInvoked.value = true;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
assertTrue(callbackInvoked.value);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@Test
|
|
151
|
+
public void getLastSeenTime() {
|
|
152
|
+
final Mutable<Boolean> callbackInvoked = new Mutable<>(false);
|
|
153
|
+
|
|
154
|
+
MParticleUser mockUser = new MockMParticleUser() {
|
|
155
|
+
@Override
|
|
156
|
+
public long getLastSeenTime() {
|
|
157
|
+
return 2;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
Mockito.when(MParticle.getInstance().Identity().getUser(Mockito.anyLong())).thenReturn(mockUser);
|
|
161
|
+
|
|
162
|
+
mParticleUser.getLastSeen("1", new Callback() {
|
|
163
|
+
@Override
|
|
164
|
+
public void invoke(Object... args) {
|
|
165
|
+
assertEquals(1, args.length);
|
|
166
|
+
assertEquals("2", args[0]);
|
|
167
|
+
callbackInvoked.value = true;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
assertTrue(callbackInvoked.value);
|
|
172
|
+
}
|
|
173
|
+
}
|