Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow "not like" statements to be used with other filters #32

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading