Skip to content

Commit

Permalink
MOB-9716 - single primitive array bug
Browse files Browse the repository at this point in the history
  • Loading branch information
megha-iterable committed Oct 24, 2024
1 parent 3e6aa4a commit 0469733
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.iterable.iterableapi.util;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import org.json.JSONArray;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class SinglePrimitiveArrayNestedCriteriaMatchTest {

static final String mockDataArrayNested = "{\n" +
" \"count\": 1,\n" +
" \"criteriaSets\": [\n" +
" {\n" +
" \"criteriaId\": \"467\",\n" +
" \"name\": \"Custom event - single primitive\",\n" +
" \"createdAt\": 1728166585122,\n" +
" \"updatedAt\": 1729581351423,\n" +
" \"searchQuery\": {\n" +
" \"combinator\": \"And\",\n" +
" \"searchQueries\": [\n" +
" {\n" +
" \"combinator\": \"And\",\n" +
" \"searchQueries\": [\n" +
" {\n" +
" \"dataType\": \"customEvent\",\n" +
" \"searchCombo\": {\n" +
" \"combinator\": \"And\",\n" +
" \"searchQueries\": [\n" +
" {\n" +
" \"dataType\": \"customEvent\",\n" +
" \"field\": \"eventName\",\n" +
" \"comparatorType\": \"Equals\",\n" +
" \"value\": \"animal_found\",\n" +
" \"fieldType\": \"string\"\n" +
" },\n" +
" {\n" +
" \"dataType\": \"customEvent\",\n" +
" \"field\": \"animal_found.count\",\n" +
" \"comparatorType\": \"DoesNotEqual\",\n" +
" \"value\": \"4\",\n" +
" \"fieldType\": \"string\"\n" +
" }\n" +
" ]\n" +
" }\n" +
" }\n" +
" ]\n" +
" }\n" +
" ]\n" +
" }\n" +
" }\n" +
" ]\n" +
"}";


private CriteriaCompletionChecker evaluator;

@Before
public void setUp() {
evaluator = new CriteriaCompletionChecker();
}

@Test
public void testSinglePrimitiveArrayNestedCriteriaMatchPass() throws Exception {
String jsonString = "[\n" +
" {\n" +
" \"dataFields\": {\n" +
" \"count\": [5,8,9]\n" +
" },\n" +
" \"eventType\": \"customEvent\",\n" +
" \"eventName\": \"animal_found\"\n" +
" }\n" +
"]";
JSONArray jsonArray = new JSONArray(jsonString);
String result = evaluator.getMatchedCriteria(mockDataArrayNested, jsonArray);
assertNotNull(result);
}

@Test
public void testSinglePrimitiveArrayNestedCriteriaMatchFail() throws Exception {
String jsonString = "[\n" +
" {\n" +
" \"dataFields\": {\n" +
" \"count\": [4, 8, 9]\n" +
" },\n" +
" \"eventType\": \"customEvent\",\n" +
" \"eventName\": \"animal_found\"\n" +
" }\n" +
"]";
JSONArray jsonArray = new JSONArray(jsonString);
String result = evaluator.getMatchedCriteria(mockDataArrayNested, jsonArray);
assertNull(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ private boolean evaluateFieldLogic(JSONArray searchQueries, JSONObject eventData
// get the value of the current sub-field
Object subFieldValue = fieldValue.get(subField);
// check if the value is a JSONArray
if (subFieldValue instanceof JSONArray) {
if (subFieldValue instanceof JSONArray && ((JSONArray) subFieldValue).get(0) instanceof JSONObject) {
isSubFieldArray = true;
JSONArray subFieldValueArray = (JSONArray) subFieldValue;
// loop through the JSONArray
Expand Down

0 comments on commit 0469733

Please sign in to comment.