Skip to content

Commit

Permalink
Fix SOSL_Test
Browse files Browse the repository at this point in the history
  • Loading branch information
pgajek2 committed Sep 12, 2023
1 parent fe83084 commit 8534d9b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 32 deletions.
16 changes: 3 additions & 13 deletions force-app/main/default/classes/SOSL.cls
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ public inherited sharing class SOSL implements ISearchable {
IFilter isTrue();
IFilter isFalse();
IFilter equal(Object value);
IFilter equal(String value);
IFilter notEqual(Object value);
IFilter notEqual(String value);
IFilter lessThan(Object value);
IFilter greaterThan(Object value);
IFilter lessOrEqual(Object value);
Expand Down Expand Up @@ -963,18 +961,10 @@ public inherited sharing class SOSL implements ISearchable {
return set('=', value);
}

public IFilter equal(String value) {
return set('=', quote(value));
}

public IFilter notEqual(Object value) {
return set('!=', value);
}

public IFilter notEqual(String value) {
return set('!=', quote(value));
}

public IFilter lessThan(Object value) {
return set('<', value);
}
Expand All @@ -992,7 +982,7 @@ public inherited sharing class SOSL implements ISearchable {
}

public IFilter containsSome(Iterable<String> values) {
return set('LIKE', '(\'' + String.join(values, '\'') + '\')');
return set('LIKE', values);
}

public IFilter contains(String value) {
Expand All @@ -1008,7 +998,7 @@ public inherited sharing class SOSL implements ISearchable {
}

public IFilter contains(String prefix, String value, String suffix) {
return set('LIKE', quote(prefix + formattedString(value) + suffix));
return set('LIKE', prefix + formattedString(value) + suffix);
}

private String formattedString(String value) {
Expand Down Expand Up @@ -1052,8 +1042,8 @@ public inherited sharing class SOSL implements ISearchable {
}

private IFilter set(String comperator, Object value) {
this.value = value;
this.comperator = comperator;
this.value = value;
return this;
}

Expand Down
73 changes: 54 additions & 19 deletions force-app/main/default/classes/SOSL_Test.cls
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ private class SOSL_Test {
);

// Verify
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE RecordType.DeveloperName = \'Partner\')', sosl.toString());
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE RecordType.DeveloperName = :binded0)', sosl.toString());
Assert.areEqual('Partner', sosl.binding()[0]);
}

@IsTest
Expand All @@ -232,7 +233,8 @@ private class SOSL_Test {
);

// Verify
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name = \'Test\')', sosl.toString());
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name = :binded0)', sosl.toString());
Assert.areEqual('Test', sosl.binding()[0]);
}

@IsTest
Expand All @@ -247,7 +249,8 @@ private class SOSL_Test {
);

// Verify
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Industry = \'IT\')', sosl.toString());
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Industry = :binded0)', sosl.toString());
Assert.areEqual('IT', sosl.binding()[0]);
}

@IsTest
Expand All @@ -262,7 +265,8 @@ private class SOSL_Test {
);

// Verify
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Contact(Id, Name WHERE Account.Industry = \'IT\')', sosl.toString());
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Contact(Id, Name WHERE Account.Industry = :binded0)', sosl.toString());
Assert.areEqual('IT', sosl.binding()[0]);
}

@IsTest
Expand All @@ -277,7 +281,8 @@ private class SOSL_Test {
);

// Verify
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Industry = \'IT\')', sosl.toString());
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Industry = :binded0)', sosl.toString());
Assert.areEqual('IT', sosl.binding()[0]);
}

@IsTest
Expand All @@ -292,7 +297,8 @@ private class SOSL_Test {
);

// Verify
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Industry = null)', sosl.toString());
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Industry = :binded0)', sosl.toString());
Assert.areEqual(null, sosl.binding()[0]);
}

@IsTest
Expand Down Expand Up @@ -352,7 +358,8 @@ private class SOSL_Test {
);

// Verify
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE NumberOfEmployees = 10)', sosl.toString());
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE NumberOfEmployees = :binded0)', sosl.toString());
Assert.areEqual(10, sosl.binding()[0]);
}

@IsTest
Expand All @@ -367,7 +374,8 @@ private class SOSL_Test {
);

// Verify
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name = \'My Account\')', sosl.toString());
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name = :binded0)', sosl.toString());
Assert.areEqual('My Account', sosl.binding()[0]);
}

@IsTest
Expand All @@ -382,7 +390,8 @@ private class SOSL_Test {
);

// Verify
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE NumberOfEmployees != 10)', sosl.toString());
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE NumberOfEmployees != :binded0)', sosl.toString());
Assert.areEqual(10, sosl.binding()[0]);
}

@IsTest
Expand All @@ -397,7 +406,8 @@ private class SOSL_Test {
);

// Verify
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name != \'My Account\')', sosl.toString());
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name != :binded0)', sosl.toString());
Assert.areEqual('My Account', sosl.binding()[0]);
}

@IsTest
Expand Down Expand Up @@ -462,17 +472,21 @@ private class SOSL_Test {

@IsTest
static void filterContainsSome() {
// Setup
List<String> names = new List<String>{ 'Test'};

// Test
SOSL sosl = SOSL.find(SEARCH_TEXT)
.inAllFields()
.returning(
SOSL.Returning(Account.SObjectType)
.with(Account.Id, Account.Name)
.whereAre(SOSL.Filter.with(Account.Name).containsSome(new List<String>{ 'Test'}))
.whereAre(SOSL.Filter.with(Account.Name).containsSome(names))
);

// Verify
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name LIKE (\'Test\'))', sosl.toString());
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name LIKE :binded0)', sosl.toString());
Assert.areEqual(names, sosl.binding()[0]);
}

@IsTest
Expand All @@ -487,7 +501,8 @@ private class SOSL_Test {
);

// Verify
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name LIKE \'%Test%\')', sosl.toString());
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name LIKE :binded0)', sosl.toString());
Assert.areEqual('%Test%', sosl.binding()[0]);
}

@IsTest
Expand All @@ -502,7 +517,8 @@ private class SOSL_Test {
);

// Verify
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name LIKE \'Test%\')', sosl.toString());
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name LIKE :binded0)', sosl.toString());
Assert.areEqual('Test%', sosl.binding()[0]);
}

@IsTest
Expand All @@ -517,11 +533,15 @@ private class SOSL_Test {
);

// Verify
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name LIKE \'%Test\')', sosl.toString());
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Name LIKE :binded0)', sosl.toString());
Assert.areEqual('%Test', sosl.binding()[0]);
}

@IsTest
static void filterIsInListOfStrings() {
// Setup
List<String> industries = new List<String>{ 'IT' };

// Test
SOSL sosl = SOSL.find(SEARCH_TEXT)
.inAllFields()
Expand All @@ -532,7 +552,8 @@ private class SOSL_Test {
);

// Verify
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Industry IN (\'IT\'))', sosl.toString());
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Industry IN :binded0', sosl.toString());
Assert.areEqual(industries, sosl.binding()[0]);
}

@IsTest
Expand Down Expand Up @@ -676,7 +697,11 @@ private class SOSL_Test {
);

// Verify
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE (Name = \'MyAccount\' AND Industry = \'IT\'))', sosl.toString());
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE (Name = :binded0 AND Industry = :binded1))', sosl.toString());

List<Object> bindedValues = sosl.binding();
Assert.areEqual('MyAccount', bindedValues[0]);
Assert.areEqual('IT', bindedValues[1]);
}

@IsTest
Expand All @@ -695,7 +720,11 @@ private class SOSL_Test {
);

// Verify
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE (Name = \'MyAccount\' OR Industry = \'IT\'))', sosl.toString());
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE (Name = :binded0 OR Industry = :binded1))', sosl.toString());

List<Object> bindedValues = sosl.binding();
Assert.areEqual('MyAccount', bindedValues[0]);
Assert.areEqual('IT', bindedValues[1]);
}

@IsTest
Expand All @@ -718,7 +747,13 @@ private class SOSL_Test {
);

// Verify
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE (Name = \'MyAccount\' AND Industry = \'IT\' AND (NumberOfEmployees > 5 OR IsDeleted = false)))', sosl.toString());
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE (Name = :binded0 AND Industry = :binded1 AND (NumberOfEmployees > :binded2 OR IsDeleted = :binded3)))', sosl.toString());

List<Object> bindedValues = sosl.binding();
Assert.areEqual('MyAccount', bindedValues[0]);
Assert.areEqual('IT', bindedValues[1]);
Assert.areEqual(5, bindedValues[2]);
Assert.areEqual(false, bindedValues[3]);
}

@IsTest
Expand Down

0 comments on commit 8534d9b

Please sign in to comment.