This commit is contained in:
2018-09-25 22:19:27 +00:00
parent 21d5ec77d1
commit 541cf6d373
2 changed files with 124 additions and 43 deletions

View File

@@ -157,11 +157,11 @@ namespace AyaNova.Biz
//Contains?
if (WildCardSearchTerm.StartsWith("%") && WildCardSearchTerm.EndsWith("%"))
{
DictionaryMatches.AddRange(await ct.SearchDictionary.Where(m => m.Word.EndsWith(WildCardSearchTerm.Replace("%", ""))).Select(m => m.Id).ToListAsync());
DictionaryMatches.AddRange(await ct.SearchDictionary.Where(m => m.Word.Contains(WildCardSearchTerm.Replace("%", ""))).Select(m => m.Id).ToListAsync());
}
else if (WildCardSearchTerm.EndsWith("%")) //STARTS WITH?
{
DictionaryMatches.AddRange(await ct.SearchDictionary.Where(m => m.Word.EndsWith(WildCardSearchTerm.Replace("%", ""))).Select(m => m.Id).ToListAsync());
DictionaryMatches.AddRange(await ct.SearchDictionary.Where(m => m.Word.StartsWith(WildCardSearchTerm.Replace("%", ""))).Select(m => m.Id).ToListAsync());
}
else if (WildCardSearchTerm.StartsWith("%"))//ENDS WITH?
{

View File

@@ -10,9 +10,7 @@ namespace raven_integration
public class SearchOps
{
/// <summary>
/// Test simple phrase only search is fundamentally working
/// </summary>
[Fact]
public async void PhraseOnlySearchShouldReturnCorrectResultsInOrder()
{
@@ -129,7 +127,6 @@ namespace raven_integration
//Only BizAdmin* roles can read a full user record but anyone should be able to see names
//This search should return zero items
a = await Util.PostAsync("Search", await Util.GetTokenAsync("SubContractorLimited"), SearchParameters.ToString());
Util.ValidateDataReturnResponseOk(a);
((JArray)a.ObjectResponse["result"]).Count.Should().Be(0, "User with no rights should not see any results in body search");
@@ -157,52 +154,136 @@ namespace raven_integration
MatchingIdList.Should().Contain(MatchUserInNameId, "ShouldContainMatchUserInNameId");
MatchingIdList.Should().NotContain(MatchNothingWidgetId, "ShouldNotContainThirdWidget");
}//eot
//TODO: WILDCARD SEARCH TEST
//TODO: WILDCARD PLUS NON WILDCARD SEARCH TEST
[Fact]
public async void WildCardStartsWithSearchShouldWork()
{
const string TEST_SEARCH_PHRASE = "hap* goose";
//CREATE A WIDGET
dynamic D = new JObject();
D.name = Util.Uniquify("Wildcard startswith search test WIDGET");
D.dollarAmount = 1.11m;
D.active = true;
D.roles = 0;
D.notes = "This record will match in notes: The quick brown and hapless goose";
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString());
Util.ValidateDataReturnResponseOk(a);
long MatchWidgetInNotesId = a.ObjectResponse["result"]["id"].Value<long>();
//CREATE FIRST TEST USER WITH PHRASE IN NAME
D = new JObject();
D.name = Util.Uniquify("Wildcard startswith search NAME happy goose Test User");
D.notes = "This user has the match in it's name";
D.ownerId = 1L;
D.active = true;
D.login = Util.Uniquify("LOGIN");
D.password = Util.Uniquify("PASSWORD");
D.roles = 0;//norole
D.localeId = 1;//random locale
D.userType = 3;//non scheduleable
a = await Util.PostAsync("User", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString());
Util.ValidateDataReturnResponseOk(a);
long MatchUserInNameId = a.ObjectResponse["result"]["id"].Value<long>();
//Now see if can find those objects with a phrase search
dynamic SearchParameters = new JObject();
SearchParameters.phrase = TEST_SEARCH_PHRASE;
SearchParameters.nameOnly = false;
SearchParameters.typeOnly = 0;//no type
a = await Util.PostAsync("Search", await Util.GetTokenAsync("manager", "l3tm3in"), SearchParameters.ToString());
Util.ValidateDataReturnResponseOk(a);
//Now validate the return list
((JArray)a.ObjectResponse["result"]).Count.Should().BeGreaterOrEqualTo(2);
//Turn the list into an array of id's
var v = ((JArray)a.ObjectResponse["result"]);
List<long> MatchingIdList = new List<long>();
foreach (JObject j in v)
{
MatchingIdList.Add(j["id"].Value<long>());
}
//Ensure the expected items are returned
MatchingIdList.Should().Contain(MatchWidgetInNotesId, "ShouldContainMatchWidgetInNotesId");
MatchingIdList.Should().Contain(MatchUserInNameId, "ShouldContainMatchUserInNameId");
}//eot
/*
{{Initial search results: borked!
{{
"result": [
{
"name": "Search NAME simple as in dogs Test WIDGET1537911374",
"type": 2,
"id": 202
},
{
"name": "Search NOTES Test WIDGET1537911373",
"type": 2,
"id": 201
},
{
"name": "Search NOTES Test User1537911374",
"type": 3,
"id": 22
},
{
"name": "Search NAME DOGS simple Test User1537911374",
"type": 3,
"id": 21
}
]
}}
*/
[Fact]
public async void WildCardEndsWithSearchShouldWork()
{
const string TEST_SEARCH_PHRASE = "goose *act";
//CREATE A WIDGET
dynamic D = new JObject();
D.name = Util.Uniquify("Wildcard endswith search test WIDGET");
D.dollarAmount = 1.11m;
D.active = true;
D.roles = 0;
D.notes = "This record will match in notes: react to the goose";
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString());
Util.ValidateDataReturnResponseOk(a);
long MatchWidgetInNotesId = a.ObjectResponse["result"]["id"].Value<long>();
//CREATE FIRST TEST USER WITH PHRASE IN NAME
D = new JObject();
D.name = Util.Uniquify("Wildcard endswith search NAME goose exact Test User");
D.notes = "This user has the match in it's name";
D.ownerId = 1L;
D.active = true;
D.login = Util.Uniquify("LOGIN");
D.password = Util.Uniquify("PASSWORD");
D.roles = 0;//norole
D.localeId = 1;//random locale
D.userType = 3;//non scheduleable
a = await Util.PostAsync("User", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString());
Util.ValidateDataReturnResponseOk(a);
long MatchUserInNameId = a.ObjectResponse["result"]["id"].Value<long>();
//Now see if can find those objects with a phrase search
dynamic SearchParameters = new JObject();
SearchParameters.phrase = TEST_SEARCH_PHRASE;
SearchParameters.nameOnly = false;
SearchParameters.typeOnly = 0;//no type
a = await Util.PostAsync("Search", await Util.GetTokenAsync("manager", "l3tm3in"), SearchParameters.ToString());
Util.ValidateDataReturnResponseOk(a);
//Now validate the return list
((JArray)a.ObjectResponse["result"]).Count.Should().BeGreaterOrEqualTo(2);
//Turn the list into an array of id's
var v = ((JArray)a.ObjectResponse["result"]);
List<long> MatchingIdList = new List<long>();
foreach (JObject j in v)
{
MatchingIdList.Add(j["id"].Value<long>());
}
//Ensure the expected items are returned
MatchingIdList.Should().Contain(MatchWidgetInNotesId, "ShouldContainMatchWidgetInNotesId");
MatchingIdList.Should().Contain(MatchUserInNameId, "ShouldContainMatchUserInNameId");
}//eot
//TODO: TEST THAT NAME ONLY WORKS AS EXPECTED
//TODO: TEST THAT NAME ONLY WORKS EVEN WITH NON-READ RIGHTS TO FULL OBJECT
//TODO: WILDCARD SEARCH TEST
//TODO: WILDCARD PLUS NON WILDCARD SEARCH TEST
//TODO: TAG SEARCH ALONE TEST
//TODO: TAG PLUS SEARCH PHRASE TEST