This repository has been archived by the owner on Jan 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from alexstyl/analytics_improvement
Use only alphanumeric characters for Firebase event names
- Loading branch information
Showing
4 changed files
with
91 additions
and
7 deletions.
There are no files selected for viewing
10 changes: 5 additions & 5 deletions
10
mobile/src/main/java/com/alexstyl/specialdates/analytics/Action.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
mobile/src/test/java/com/alexstyl/specialdates/analytics/FirebaseRulesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.alexstyl.specialdates.analytics; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
import static junit.framework.Assert.fail; | ||
|
||
/** | ||
* Class that tests our business logic against all Firebase documentation rules | ||
* | ||
* @see <a href="https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event">FirebaseAnalytics.Event documentation</a> | ||
*/ | ||
@RunWith(MockitoJUnitRunner.class) | ||
public class FirebaseRulesTest { | ||
|
||
private final static int MAX_EVENT_NAME_CHAR_COUNT = 32; | ||
private final static int MAX_EVENTS_COUNT = 500; | ||
|
||
@Mock | ||
private Analytics mockAnalytics; | ||
|
||
@Test | ||
public void actionUpTo32characterlong() { | ||
for (Action action : Action.values()) { | ||
if (action.getName().length() > MAX_EVENT_NAME_CHAR_COUNT) { | ||
failFor(action); | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void actionWithParamsUpTo32CharacterLong() { | ||
List<String> labels = Arrays.asList("enabled", "select", "success", "source"); | ||
List<String> values = Arrays.asList("true", "false", "success", "external", "sms", "call"); | ||
|
||
for (Action action : Action.values()) { | ||
for (String label : labels) { | ||
for (String value : values) { | ||
ActionWithParameters actionWithParameters = new ActionWithParameters(action, label, value); | ||
String event = Firebase.format(actionWithParameters); | ||
if (event.length() > MAX_EVENT_NAME_CHAR_COUNT) { | ||
failFor(actionWithParameters); | ||
} | ||
|
||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void doesNotExceedNumberOfAllowedEvents() { | ||
int numberOfEventsUsed = Action.values().length; | ||
if (numberOfEventsUsed > MAX_EVENTS_COUNT) { | ||
fail("You can only use up to " + MAX_EVENTS_COUNT + " unique Firebase events. Currently using " + numberOfEventsUsed); | ||
} | ||
|
||
} | ||
|
||
private static void failFor(Action action) { | ||
int characterCount = action.getName().length(); | ||
fail(action + " is not a correct action to be used. It contains more than " + MAX_EVENT_NAME_CHAR_COUNT + " characters. Has " + characterCount); | ||
} | ||
|
||
private static void failFor(ActionWithParameters action) { | ||
int characterCount = Firebase.format(action).length(); | ||
String message = action + " is not a correct action to be used. It contains more than " + MAX_EVENT_NAME_CHAR_COUNT + " characters. Has " + characterCount; | ||
fail(message); | ||
} | ||
|
||
} |