Skip to content

Commit

Permalink
Allow not like statements with other filters (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewJarrett authored Mar 13, 2024
1 parent e0b1d67 commit b8dc989
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions force-app/repository/Query.cls
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public virtual class Query {
public virtual override String toString() {
if (this.operator == Query.Operator.NOT_LIKE) {
// who knows why this is the format they wanted
return String.format(this.getOperator(), new List<String>{ this.field }) + ' ' + this.predicate;
return String.format(this.getOperator(), new List<String>{ this.field, this.predicate.toString() });
}
return this.field + ' ' + this.getOperator() + ' ' + this.predicate;
}
Expand Down Expand Up @@ -243,7 +243,7 @@ public virtual class Query {
returnVal = 'like';
}
when NOT_LIKE {
returnVal = 'not {0} like';
returnVal = '(not {0} like {1})';
}
}
return returnVal;
Expand Down
19 changes: 17 additions & 2 deletions force-app/repository/QueryTests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private class QueryTests {

Query notLike = Query.notLike(Account.Name, expectedName);

System.assertEquals('not Name like :bindVar0', notLike.toString());
System.assertEquals('(not Name like :bindVar0)', notLike.toString());
System.assertEquals(expectedName, notLike.getBindVars().get('bindVar0'));
}

Expand All @@ -133,10 +133,25 @@ private class QueryTests {

Query notLike = Query.notLike(Account.Name, values);

System.assertEquals('not Name like :bindVar0', notLike.toString());
System.assertEquals('(not Name like :bindVar0)', notLike.toString());
System.assertEquals(values, notLike.getBindVars().get('bindVar0'));
}

@IsTest
static void it_should_allow_multiple_not_like_statements() {
String someName = '%someName%';
String otherName = '%otherName%';

Query multipleNotLike = Query.andQuery(new List<Query> {
Query.notLike(Account.Name, someName),
Query.notLike(Account.Name, otherName)
});

System.assertEquals('((not Name like :bindVar0) AND (not Name like :bindVar1))', multipleNotLike.toString());
System.assertEquals(someName, multipleNotLike.getBindVars().get('bindVar0'));
System.assertEquals(otherName, multipleNotLike.getBindVars().get('bindVar1'));
}

@IsTest
static void it_should_allow_parent_fields_for_filtering() {
Query parentQuery = Query.equals(Group.DeveloperName, 'SOME_CONSTANT.DeveloperName')
Expand Down

0 comments on commit b8dc989

Please sign in to comment.