From 9443f0e3d2bb0e735948344fc59fa2cd5e106c1c Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 3 Jul 2019 18:50:44 +0000 Subject: [PATCH] --- Search/SearchOps.cs | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/Search/SearchOps.cs b/Search/SearchOps.cs index ebceb4e..77797d4 100644 --- a/Search/SearchOps.cs +++ b/Search/SearchOps.cs @@ -588,6 +588,63 @@ namespace raven_integration }//eot + + + + [Fact] + public async void CustomFieldSearchShouldWork() + { + + //CREATE CUSTOM FIELD DATA TO SEARCH FOR (note must use already defined template so c2 is the text one) + dynamic dCustomField = new JObject(); + dCustomField.c1 = "2019-02-08T06:31:48.0019809Z"; + dCustomField.c2 = "pelican beak nozzle"; + dCustomField.c3 = "747"; + dCustomField.c4 = "true"; + dCustomField.c5 = "23.45"; + + //CREATE A WIDGET + dynamic D = new JObject(); + D.name = Util.Uniquify("CUSTOMFIELD search test WIDGET"); + D.customFields = dCustomField.ToString(); + D.dollarAmount = 1.11m; + D.active = true; + D.roles = 0; + D.notes = "This record will match in custom field"; + + ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString()); + Util.ValidateDataReturnResponseOk(a); + long MatchingWidgetId = a.ObjectResponse["data"]["id"].Value(); + + + //Now see if can find this object with a phrase search + dynamic SearchParameters = new JObject(); + + SearchParameters.phrase = "beak pelican"; + 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["data"]["searchResults"]).Count.Should().BeGreaterOrEqualTo(1);//might be a successive run and still have some left so account for more than one return + + //Turn the list into an array of id's + var v = ((JArray)a.ObjectResponse["data"]["searchResults"]); + // v.Count.Should().Be(1); + // v[0]["id"].Value().Should().Be(MatchingWidgetId); + List MatchingIdList = new List(); + foreach (JObject j in v) + { + MatchingIdList.Add(j["id"].Value()); + } + + //Ensure the expected items are returned + MatchingIdList.Should().Contain(MatchingWidgetId, "ShouldContainMatchingCustomFieldWidgetId"); + + + }//eot //================================================== }//eoc