Skip to content

Commit

Permalink
SOSL_Test
Browse files Browse the repository at this point in the history
  • Loading branch information
pgajek2 committed Sep 12, 2023
1 parent 8534d9b commit e742c57
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 20 deletions.
4 changes: 2 additions & 2 deletions force-app/main/default/classes/SOSL.cls
Original file line number Diff line number Diff line change
Expand Up @@ -1010,15 +1010,15 @@ public inherited sharing class SOSL implements ISearchable {
}

public IFilter isIn(List<String> iterable) {
return set('IN', '(\'' + String.join(iterable, '\'') + '\')');
return set('IN', iterable);
}

public IFilter notIn(Iterable<Object> iterable) {
return set('NOT IN', iterable);
}

public IFilter notIn(List<String> iterable) {
return set('NOT IN', '(\'' + String.join(iterable, '\'') + '\')');
return set('NOT IN', iterable);
}

public IFilter includesAll(Iterable<String> iterable) {
Expand Down
61 changes: 43 additions & 18 deletions force-app/main/default/classes/SOSL_Test.cls
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ private class SOSL_Test {
);

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

@IsTest
Expand Down Expand Up @@ -313,7 +314,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 All @@ -328,7 +330,8 @@ private class SOSL_Test {
);

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

@IsTest
Expand All @@ -343,7 +346,8 @@ private class SOSL_Test {
);

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

@IsTest
Expand Down Expand Up @@ -422,7 +426,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 @@ -437,7 +442,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 @@ -452,7 +458,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 @@ -467,7 +474,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 Down Expand Up @@ -548,57 +556,69 @@ private class SOSL_Test {
.returning(
SOSL.Returning(Account.SObjectType)
.with(Account.Id, Account.Name)
.whereAre(SOSL.Filter.with(Account.Industry).isIn(new List<String>{ 'IT' }))
.whereAre(SOSL.Filter.with(Account.Industry).isIn(industries))
);

// Verify
Assert.areEqual('FIND \'SearchText\' IN ALL FIELDS RETURNING Account(Id, Name WHERE Industry IN :binded0', 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
static void filterIsInListOfIntegers() {
// Setup
List<Integer> numberOfEmployees = new List<Integer>{ 10, 20, 30 };

// Test
SOSL sosl = SOSL.find(SEARCH_TEXT)
.inAllFields()
.returning(
SOSL.Returning(Account.SObjectType)
.with(Account.Id, Account.Name)
.whereAre(SOSL.Filter.with(Account.NumberOfEmployees).isIn(new List<Integer>{ 10, 20, 30 }))
.whereAre(SOSL.Filter.with(Account.NumberOfEmployees).isIn(numberOfEmployees))
);

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

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

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

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

@IsTest
static void filterIsNotInListOfIntegers() {
// Setup
List<Integer> numberOfEmployees = new List<Integer>{ 10, 20, 30 };

// Test
SOSL sosl = SOSL.find(SEARCH_TEXT)
.inAllFields()
.returning(
SOSL.Returning(Account.SObjectType)
.with(Account.Id, Account.Name)
.whereAre(SOSL.Filter.with(Account.NumberOfEmployees).notIn(new List<Integer>{ 10, 20, 30 }))
.whereAre(SOSL.Filter.with(Account.NumberOfEmployees).notIn(numberOfEmployees))
);

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

@IsTest
Expand Down Expand Up @@ -679,7 +699,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 Down Expand Up @@ -789,7 +810,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 Down

0 comments on commit e742c57

Please sign in to comment.