Skip to content

Commit

Permalink
release: SDK 1.17.1
Browse files Browse the repository at this point in the history
  • Loading branch information
abarisain committed Apr 7, 2021
1 parent 9fc9ab4 commit af04acf
Show file tree
Hide file tree
Showing 14 changed files with 17,547 additions and 115 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ If you think you've discovered a bug in our SDK, our support team is available a
- Describe your environment
- Provide detailed reproduction steps
- Provide a minimal reproduction project: this isn’t compulsory but will reduce greatly the resolution time
- Include detailed logs: Please don’t try filter the logs here, it’s best to provide here the rawest logs as possible
- Include detailed logs: It’s best to provide the rawest logs possible, please don’t try filter them
- Includes a Stack Trace: If your issue involves a crash, this is absolutely compulsory, and should be as raw as possible

You can also open an issue for it, using the appropriate template and respecting the same rules. However, we do have a longer response time here than by email or the Live Chat.
Expand Down
4 changes: 2 additions & 2 deletions Sources/sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ android {
minSdkVersion 15
targetSdkVersion 30
versionCode 1
versionName "1.17.0"
versionName "1.17.1"
buildConfigField "String", SDK_VERSION, "\"$versionName\""
buildConfigField "Integer", API_LEVEL, '34'
buildConfigField "Integer", API_LEVEL, '35'
buildConfigField "Integer", MESSAGING_API_LEVEL, '10'
buildConfigField "String", WS_DOMAIN, '"ws.batch.com"'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void performAction(@Nullable Context context,
return;
}

String label = json.getString("l");
String label = json.reallyOptString("l", null);

BatchEventData data = new BatchEventData();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ private static class BroadcastRecord

public LocalBroadcastManager(Context context)
{
mAppContext = context;
mHandler = new Handler(context.getMainLooper())
mAppContext = context.getApplicationContext();
mHandler = new Handler(mAppContext.getMainLooper())
{

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ public WebFormatView(@NonNull Context context,
webSettings.setDefaultTextEncodingName("utf-8");
webSettings.setSupportMultipleWindows(true);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
// Work around an issue where android could show "ERR_CACHE_MISS"
// In a perfect world we would like to make use of the browser cache
// but as those messages are usually one shot, it doesn't really matter.
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
}

webView.addJavascriptInterface(jsInterface, "_batchAndroidBridge");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public void trackPublicEvent(String event, String label, JSONObject data)
if (label.length() > 200) {
Logger.internal(TAG,
"Event label is longer than 200 characters and has been removed from the event");
} else {
} else if (label.length() > 0) {
params.put(PARAMETER_KEY_LABEL, label);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.batch.android.module;
package com.batch.android.actions;

import android.content.ClipData;
import android.content.ClipboardManager;
Expand All @@ -21,6 +21,8 @@
import com.batch.android.di.providers.RuntimeManagerProvider;
import com.batch.android.json.JSONException;
import com.batch.android.json.JSONObject;
import com.batch.android.module.ActionModule;
import com.batch.android.module.UserModule;

import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -206,112 +208,6 @@ public void testClipboardAction() throws JSONException
assertEquals("best text ever", text.getItemAt(0).getText().toString());
}

@Test
public void testTrackEventAction() throws JSONException
{
ActionModule actionModule = new ActionModule();
UserModule userModule = DITestUtils.mockSingletonDependency(UserModule.class, null);

PowerMockito.doAnswer(new Answer<Object>()
{
@Override
public Object answer(InvocationOnMock invocation) throws Throwable
{
String event = invocation.getArgument(0, String.class);
String label = invocation.getArgument(1, String.class);
JSONObject data = invocation.getArgument(2, JSONObject.class);

Assert.assertEquals("event_test", event);
Assert.assertEquals("label_test", label);
Assert.assertNotNull(data);
Assert.assertNotNull(data.getJSONObject("attributes"));
Assert.assertTrue(data.getJSONObject("attributes").keySet().isEmpty());
Assert.assertNotNull(data.getJSONArray("tags"));
Assert.assertEquals(0, data.getJSONArray("tags").length());
return null;
}
}).when(userModule).trackPublicEvent(Mockito.anyString(),
Mockito.anyString(),
Mockito.any(JSONObject.class));
String eventJSON = "{'e':'event_test', 'l':'label_test'}";
actionModule.performAction(context, "batch.user.event", new JSONObject(eventJSON), null);
}

@Test
public void testTrackEventWithTagsAction() throws JSONException
{
ActionModule actionModule = new ActionModule();
UserModule userModule = DITestUtils.mockSingletonDependency(UserModule.class, null);

PowerMockito.doAnswer(new Answer<Object>()
{
@Override
public Object answer(InvocationOnMock invocation) throws Throwable
{
String event = invocation.getArgument(0, String.class);
String label = invocation.getArgument(1, String.class);
JSONObject data = invocation.getArgument(2, JSONObject.class);

Assert.assertEquals("event_test", event);
Assert.assertEquals("label_test", label);
Assert.assertNotNull(data);
Assert.assertNotNull(data.getJSONObject("attributes"));
Assert.assertTrue(data.getJSONObject("attributes").keySet().isEmpty());
Assert.assertNotNull(data.getJSONArray("tags"));
Assert.assertEquals(3, data.getJSONArray("tags").length());
Assert.assertEquals("tag1", data.getJSONArray("tags").optString(0));
Assert.assertEquals("tag2", data.getJSONArray("tags").optString(1));
Assert.assertEquals("tag3", data.getJSONArray("tags").optString(2));
return null;
}
}).when(userModule).trackPublicEvent(Mockito.anyString(),
Mockito.anyString(),
Mockito.any(JSONObject.class));
String eventJSON = "{'e':'event_test', 'l':'label_test', 't':['tag1', 'tag2', 'tag3']}";
actionModule.performAction(context, "batch.user.event", new JSONObject(eventJSON), null);
}

@Test
public void testTrackEventWithAttrAction() throws JSONException
{
ActionModule actionModule = new ActionModule();
UserModule userModule = DITestUtils.mockSingletonDependency(UserModule.class, null);

PowerMockito.doAnswer(new Answer<Object>()
{
@Override
public Object answer(InvocationOnMock invocation) throws Throwable
{
String event = invocation.getArgument(0, String.class);
String label = invocation.getArgument(1, String.class);
JSONObject data = invocation.getArgument(2, JSONObject.class);

Assert.assertEquals("event_test", event);
Assert.assertEquals("label_test", label);
Assert.assertNotNull(data);
Assert.assertNotNull(data.getJSONArray("tags"));
Assert.assertEquals(0, data.getJSONArray("tags").length());

Assert.assertNotNull(data.getJSONObject("attributes"));
Assert.assertTrue(data.getJSONObject("attributes").optBoolean("bool.b"));
Assert.assertEquals(64, data.getJSONObject("attributes").optInt("int.i"));
Assert.assertEquals(68987.256,
data.getJSONObject("attributes").optDouble("double.f"),
0);
Assert.assertEquals("tototo",
data.getJSONObject("attributes").optString("string.s"));
Assert.assertEquals(1596975143943L,
data.getJSONObject("attributes").optLong("date.t"));
return null;
}
}).when(userModule).trackPublicEvent(Mockito.anyString(),
Mockito.anyString(),
Mockito.any(JSONObject.class));

String eventJSON = "{'e':'event_test', 'l':'label_test', 'a':{'bool':true, 'int':64, 'double': 68987.256, 'string':'tototo', 'date': '2020-08-09T12:12:23.943Z'}}}";
actionModule.performAction(context, "batch.user.event", new JSONObject(eventJSON), null);
}

private JSONObject generateJSONTestAction(String action) throws JSONException
{
JSONObject json = new JSONObject();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package com.batch.android.actions;

import android.content.Context;

import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.MediumTest;

import com.batch.android.Batch;
import com.batch.android.Config;
import com.batch.android.di.DITestUtils;
import com.batch.android.di.providers.RuntimeManagerProvider;
import com.batch.android.json.JSONException;
import com.batch.android.json.JSONObject;
import com.batch.android.module.ActionModule;
import com.batch.android.module.UserModule;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.rule.PowerMockRule;
import org.robolectric.res.android.Asset;
import org.robolectric.shadows.ShadowLog;

import static org.mockito.ArgumentMatchers.eq;

@RunWith(AndroidJUnit4.class)
@MediumTest
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "android.*", "androidx.*"})
@PrepareForTest({UserModule.class})
public class UserEventActionTest
{

private Context context;

@Rule
public PowerMockRule rule = new PowerMockRule();

@Before
public void setUp()
{
ShadowLog.stream = System.out;

context = ApplicationProvider.getApplicationContext();

RuntimeManagerProvider.get().setContext(context);
}

@Test
public void testTrackEventAction() throws JSONException
{
ActionModule actionModule = new ActionModule();
UserModule userModule = DITestUtils.mockSingletonDependency(UserModule.class, null);

PowerMockito.doNothing().when(userModule).trackPublicEvent(Mockito.anyString(),
Mockito.anyString(),
Mockito.any(JSONObject.class));

ArgumentCaptor<JSONObject> eventDataCaptor = ArgumentCaptor.forClass(JSONObject.class);

String eventJSON = "{'e':'event_test', 'l':'label_test'}";
actionModule.performAction(context, "batch.user.event", new JSONObject(eventJSON), null);
Mockito.verify(userModule).trackPublicEvent(eq("event_test"),
eq("label_test"),
eventDataCaptor.capture());

JSONObject eventData = eventDataCaptor.getValue();
Assert.assertNotNull(eventData);
Assert.assertNotNull(eventData.getJSONObject("attributes"));
Assert.assertTrue(eventData.getJSONObject("attributes").keySet().isEmpty());
Assert.assertNotNull(eventData.getJSONArray("tags"));
Assert.assertEquals(0, eventData.getJSONArray("tags").length());
}

@Test
public void testTrackEventWithoutLabelAction() throws JSONException
{
ActionModule actionModule = new ActionModule();
UserModule userModule = DITestUtils.mockSingletonDependency(UserModule.class, null);

PowerMockito.doNothing().when(userModule).trackPublicEvent(Mockito.anyString(),
Mockito.anyString(),
Mockito.any(JSONObject.class));

ArgumentCaptor<JSONObject> eventDataCaptor = ArgumentCaptor.forClass(JSONObject.class);

String eventJSON = "{'e':'event_test'}";
actionModule.performAction(context, "batch.user.event", new JSONObject(eventJSON), null);
Mockito.verify(userModule).trackPublicEvent(eq("event_test"),
eq(null),
eventDataCaptor.capture());

JSONObject eventData = eventDataCaptor.getValue();
Assert.assertNotNull(eventData);
Assert.assertNotNull(eventData.getJSONObject("attributes"));
Assert.assertTrue(eventData.getJSONObject("attributes").keySet().isEmpty());
Assert.assertNotNull(eventData.getJSONArray("tags"));
Assert.assertEquals(0, eventData.getJSONArray("tags").length());
}

@Test
public void testTrackEventWithTagsAction() throws JSONException
{
ActionModule actionModule = new ActionModule();
UserModule userModule = DITestUtils.mockSingletonDependency(UserModule.class, null);

PowerMockito.doNothing().when(userModule).trackPublicEvent(Mockito.anyString(),
Mockito.anyString(),
Mockito.any(JSONObject.class));

ArgumentCaptor<JSONObject> eventDataCaptor = ArgumentCaptor.forClass(JSONObject.class);

String eventJSON = "{'e':'event_test', 'l':'label_test', 't':['tag1', 'tag2', 'tag3']}";
actionModule.performAction(context, "batch.user.event", new JSONObject(eventJSON), null);
Mockito.verify(userModule).trackPublicEvent(eq("event_test"),
eq("label_test"),
eventDataCaptor.capture());

JSONObject eventData = eventDataCaptor.getValue();
Assert.assertNotNull(eventData);
Assert.assertNotNull(eventData.getJSONObject("attributes"));
Assert.assertTrue(eventData.getJSONObject("attributes").keySet().isEmpty());
Assert.assertNotNull(eventData.getJSONArray("tags"));
Assert.assertEquals(3, eventData.getJSONArray("tags").length());
Assert.assertEquals("tag1", eventData.getJSONArray("tags").optString(0));
Assert.assertEquals("tag2", eventData.getJSONArray("tags").optString(1));
Assert.assertEquals("tag3", eventData.getJSONArray("tags").optString(2));
}

@Test
public void testTrackEventWithAttrAction() throws JSONException
{
ActionModule actionModule = new ActionModule();
UserModule userModule = DITestUtils.mockSingletonDependency(UserModule.class, null);

PowerMockito.doNothing().when(userModule).trackPublicEvent(Mockito.anyString(),
Mockito.anyString(),
Mockito.any(JSONObject.class));

ArgumentCaptor<JSONObject> eventDataCaptor = ArgumentCaptor.forClass(JSONObject.class);

String eventJSON = "{'e':'event_test', 'l':'label_test', 'a':{'bool':true, 'int':64, 'double': 68987.256, 'string':'tototo', 'date': '2020-08-09T12:12:23.943Z'}}}";
actionModule.performAction(context, "batch.user.event", new JSONObject(eventJSON), null);
Mockito.verify(userModule).trackPublicEvent(eq("event_test"),
eq("label_test"),
eventDataCaptor.capture());

JSONObject eventData = eventDataCaptor.getValue();
Assert.assertNotNull(eventData);

Assert.assertNotNull(eventData.getJSONObject("attributes"));
Assert.assertTrue(eventData.getJSONObject("attributes").optBoolean("bool.b"));
Assert.assertEquals(64, eventData.getJSONObject("attributes").optInt("int.i"));
Assert.assertEquals(68987.256,
eventData.getJSONObject("attributes").optDouble("double.f"),
0);
Assert.assertEquals("tototo",
eventData.getJSONObject("attributes").optString("string.s"));
Assert.assertEquals(1596975143943L,
eventData.getJSONObject("attributes").optLong("date.t"));

Assert.assertNotNull(eventData.getJSONArray("tags"));
Assert.assertEquals(0, eventData.getJSONArray("tags").length());
}
}
1 change: 1 addition & 0 deletions proguard-mappings/1.16.4/checksum.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MD5 (public-sdk/Batch.aar) = 2df641af51f6a9a9c8c346c722e09c0b
1 change: 1 addition & 0 deletions proguard-mappings/1.16.4/checksum.sha
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
98afdf3a1b75b97e8b7eb9d86b680c274411b07b public-sdk/Batch.aar
Loading

0 comments on commit af04acf

Please sign in to comment.