diff --git a/server/AyaNova/biz/Search.cs b/server/AyaNova/biz/Search.cs index 2246a26a..07b2f598 100644 --- a/server/AyaNova/biz/Search.cs +++ b/server/AyaNova/biz/Search.cs @@ -313,9 +313,12 @@ namespace AyaNova.Biz MatchingObjects = CanReadMatchingObjects; } + //Sort and group the matching objects list in return order + //Customer.OrderBy(c => c.LastName).ThenBy(c => c.FirstName) + var OrderedMatchingObjects = MatchingObjects.OrderBy(x => x.ObjectType).ThenByDescending(x => x.ObjectId); //Build the return list from the remaining matching objects list - foreach (AyaTypeId i in MatchingObjects) + foreach (AyaTypeId i in OrderedMatchingObjects) { SearchResult SR = new SearchResult(); SR.Name = BizObjectNameFetcher.Name(i, ct); diff --git a/test/raven-integration/Search/SearchOps.cs b/test/raven-integration/Search/SearchOps.cs index afd0b57e..b526556c 100644 --- a/test/raven-integration/Search/SearchOps.cs +++ b/test/raven-integration/Search/SearchOps.cs @@ -30,6 +30,22 @@ namespace raven_integration Util.ValidateDataReturnResponseOk(a); long MatchFirstWidgetId = a.ObjectResponse["result"]["id"].Value(); + //CREATE A USER + D = new JObject(); + D.name = Util.Uniquify("Search simple Test User"); + D.notes = "This user has the word dogs in its notes"; + 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 MatchUserId = a.ObjectResponse["result"]["id"].Value(); + //CREATE A SECOND WIDGET D = new JObject(); D.name = Util.Uniquify("Search simple as in dogs SECOND Test WIDGET"); @@ -55,22 +71,6 @@ namespace raven_integration long NoMatchThirdWidgetId = a.ObjectResponse["result"]["id"].Value(); - //CREATE A USER - D = new JObject(); - D.name = Util.Uniquify("Search simple Test User"); - D.notes = "This user has the word dogs in its notes"; - 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 MatchUserId = a.ObjectResponse["result"]["id"].Value(); - //Now see if can find those objects with a phrase search dynamic SearchParameters = new JObject(); @@ -93,82 +93,17 @@ namespace raven_integration MatchingIdList.Should().Contain(MatchFirstWidgetId, "ShouldContainFirstWidget"); MatchingIdList.Should().Contain(MatchSecondWidgetId, "ShouldContainSecondWidget"); + MatchingIdList.Should().Contain(MatchUserId, "ShouldContainUser"); MatchingIdList.Should().NotContain(NoMatchThirdWidgetId, "ShouldNotContainThirdWidget"); + //Assert the order, the first item should be a lower object type than the last item, the first should be + }//eot - /// - /// Test return grouping and sorting properly - /// - [Fact] - public async void ResultsInCorrectOrderAndGrouping() - { - const string TEST_SEARCH_PHRASE = "mango ducky"; - //CREATE A WIDGET - dynamic D = new JObject(); - D.name = Util.Uniquify("Search mango Test WIDGET"); - D.dollarAmount = 1.11m; - D.active = true; - D.roles = 0; - D.notes = "The quick brown and ducky fox jumped over the six lazy dogs!"; - - ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString()); - Util.ValidateDataReturnResponseOk(a); - long MatchFirstWidgetId = a.ObjectResponse["result"]["id"].Value(); - - //CREATE A SECOND WIDGET - D = new JObject(); - D.name = Util.Uniquify("Search simple as in dogs SECOND Test WIDGET"); - D.dollarAmount = 1.11m; - D.active = true; - D.roles = 0; - D.notes = "This Widget should be returned in the search as it contains both keywords in the name"; - - a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString()); - Util.ValidateDataReturnResponseOk(a); - long MatchSecondWidgetId = a.ObjectResponse["result"]["id"].Value(); - - //CREATE A THIRD WIDGET - D = new JObject(); - D.name = Util.Uniquify("Search Simple THIRD Test WIDGET"); - D.dollarAmount = 1.11m; - D.active = true; - D.roles = 0; - D.notes = "This Widget should not be returned in the search as it only contains a single keyword in the name not both"; - - a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString()); - Util.ValidateDataReturnResponseOk(a); - long NoMatchThirdWidgetId = a.ObjectResponse["result"]["id"].Value(); - - //Now see if can find that widget 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 MatchingIdList = new List(); - foreach (JObject j in v) - { - MatchingIdList.Add(j["id"].Value()); - } - - MatchingIdList.Should().Contain(MatchFirstWidgetId, "ShouldContainFirstWidget"); - MatchingIdList.Should().Contain(MatchSecondWidgetId, "ShouldContainSecondWidget"); - MatchingIdList.Should().NotContain(NoMatchThirdWidgetId, "ShouldNotContainThirdWidget"); - - }//eot // TODO: TEST RESULTS ARE RETURNED GROUPED (together) BY OBJECT TYPE THEN OBJECT ID DESCENDING