From e091a4841f6f79384f106aa675c7355569c1e7e2 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 25 Feb 2026 14:21:27 -0800 Subject: [PATCH] 4648 --- Search/SearchOps.cs | 186 +++++++++++++++----------------------------- 1 file changed, 63 insertions(+), 123 deletions(-) diff --git a/Search/SearchOps.cs b/Search/SearchOps.cs index bb47041..11d79d9 100644 --- a/Search/SearchOps.cs +++ b/Search/SearchOps.cs @@ -307,9 +307,9 @@ namespace raven_integration a = await Util.PostAsync("project", await Util.GetTokenAsync("superuser", "l3tm3in"), payload); Util.ValidateDataReturnResponseOk(a); long NoPhraseMatchProjectInTagId = a.ObjectResponse["data"]["id"].Value(); - + //CREATE FIRST TEST USER WITH PHRASE IN NAME BUT NO TAG - var userName = Util.Uniquify("Wildcard contains search NAME elementary aardvark Test User"); + var userName = Util.Uniquify("Wildcard contains search NAME elementary aardvark Test User"); payload = $$""" {"id":0,"concurrency":0,"active":true,"allowLogin":true,"name":"{{userName}}","roles":8,"userType":2,"employeeNumber":null,"notes":"This user has the match in it's name but no tag match","customerId":null,"headOfficeId":null,"vendorId":null,"wiki":null,"customFields":"{}","tags":[],"lastLogin":null,"password":"{{userName}}","login":"{{userName}}"} """; @@ -429,150 +429,90 @@ namespace raven_integration [Fact] public async Task SearchForSerialFieldShouldWork() { - //CREATE A PROJECT - dynamic D = new JObject(); - D.name = Util.Uniquify("Serial search test PROJECT"); - - D.dollarAmount = 1.11m; - D.active = true; - D.usertype = 1; - D.notes = "Test for serial number search"; - - ApiResponse a = await Util.PostAsync("project", await Util.GetTokenAsync("superuser", "l3tm3in"), D.ToString()); - Util.ValidateDataReturnResponseOk(a); - long MatchProjectInSerialId = a.ObjectResponse["data"]["id"].Value(); - var MatchProjectSerial = a.ObjectResponse["data"]["serial"].Value(); - - //TODO: get this from the return object - string SerialSearch = MatchProjectSerial.ToString(); ; - - - //Now see if can find those objects with a phrase search + //just search for workorder number 99 should always be there dynamic SearchParameters = new JObject(); - SearchParameters.phrase = SerialSearch; - - SearchParameters.typeOnly = 0;//no type + SearchParameters.phrase = "99"; + SearchParameters.typeOnly = 34;//workorder SearchParameters.maxResults = 0; - a = await Util.PostAsync("search", await Util.GetTokenAsync("superuser", "l3tm3in"), SearchParameters.ToString()); + ApiResponse a = await Util.PostAsync("search", await Util.GetTokenAsync("superuser", "l3tm3in"), SearchParameters.ToString()); Util.ValidateDataReturnResponseOk(a); - //Now validate the return list - ((JArray)a.ObjectResponse["data"]["searchResults"]).Count.Should().BeGreaterOrEqualTo(1); - - //Turn the list into an array of id's - var v = ((JArray)a.ObjectResponse["data"]["searchResults"]); - List MatchingIdList = new List(); - foreach (JObject j in v) - { - MatchingIdList.Add(j["id"].Value()); - } - - //Ensure the expected items are returned - MatchingIdList.Should().Contain(MatchProjectInSerialId, "ShouldContainMatchProjectInSerialId"); - - - + //Now validate the return list (note should only ever match work order 99 since it's not a wildcard search and it's constrained to wo so 1 result always) + ((JArray)a.ObjectResponse["data"]["searchResults"]).Count.Should().Be(1); }//eot + // [Fact] + // public async Task CustomFieldSearchShouldWork() + // { + // //COMMENTTING THIS ONE OUT AS THERE IS NO CUSTOM FIELD IN SAMPLE DATA FOR NOW + + // //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 PROJECT + // dynamic D = new JObject(); + // D.name = Util.Uniquify("CUSTOMFIELD search test PROJECT"); + // D.customFields = dCustomField.ToString(); + // D.dollarAmount = 1.11m; + // D.active = true; + // D.usertype = 1; + // D.notes = "This record will match in custom field"; + + // ApiResponse a = await Util.PostAsync("project", await Util.GetTokenAsync("superuser", "l3tm3in"), D.ToString()); + // Util.ValidateDataReturnResponseOk(a); + // long MatchingProjectId = a.ObjectResponse["data"]["id"].Value(); + // //Now see if can find this object with a phrase search + // dynamic SearchParameters = new JObject(); - [Fact] - public async Task CustomFieldSearchShouldWork() - { - /* - Failing on huge data test after many hours: - -[xUnit.net 00:00:21.49] raven_integration.SearchOps.CustomFieldSearchShouldWork [FAIL] - X raven_integration.SearchOps.CustomFieldSearchShouldWork [1s 84ms] - Error Message: - Expected MatchingIdList {109274L, 109095L, 108919L, 108740L, 108558L, 108382L, 108201L, 108021L, 107842L, 107663L, 107487L, 107305L, 107126L, 106947L, 106768L, 106589L, 106413L, 106233L, 106052L, 105873L, 105692L, 105510L, 105341L, 105157L, 104978L, 104799L, 104620L, 104441L, 104262L, 104084L, 103906L, 103725L, .468 more.} to contain 195378L because ShouldContainMatchingCustomFieldProjectId. - Stack Trace: - at FluentAssertions.Execution.XUnit2TestFramework.Throw(String message) - at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message) - at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message) - at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc) - at FluentAssertions.Collections.SelfReferencingCollectionAssertions`2.Contain(T expected, String because, Object[] becauseArgs) - at raven_integration.SearchOps.CustomFieldSearchShouldWork() in c:\data\code\raven-test-integration\Search\SearchOps.cs:line 644 - at System.Threading.Tasks.Task.<>c.b__139_0(Object state) - -Likely fix is to force order to most recent or simply to delete after test so they don't build up into a huge list + // SearchParameters.phrase = "beak pelican"; - */ + // SearchParameters.typeOnly = 0;//no type - //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"; + // a = await Util.PostAsync("search", await Util.GetTokenAsync("superuser", "l3tm3in"), SearchParameters.ToString()); + // Util.ValidateDataReturnResponseOk(a); - //CREATE A PROJECT - dynamic D = new JObject(); - D.name = Util.Uniquify("CUSTOMFIELD search test PROJECT"); - D.customFields = dCustomField.ToString(); - D.dollarAmount = 1.11m; - D.active = true; - D.usertype = 1; - D.notes = "This record will match in custom field"; + // //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 - ApiResponse a = await Util.PostAsync("project", await Util.GetTokenAsync("superuser", "l3tm3in"), D.ToString()); - Util.ValidateDataReturnResponseOk(a); - long MatchingProjectId = 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.typeOnly = 0;//no type - - a = await Util.PostAsync("search", await Util.GetTokenAsync("superuser", "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"]); - List MatchingIdList = new List(); - foreach (JObject j in v) - { - MatchingIdList.Add(j["id"].Value()); - } - - //Ensure the expected items are returned - MatchingIdList.Should().Contain(MatchingProjectId, "ShouldContainMatchingCustomFieldProjectId"); - - //Now delete the newly created one so the list doesn't build up and prevent this test from working in big runs... - //DELETE - ApiResponse DELETETestResponse = await Util.DeleteAsync("project/" + MatchingProjectId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); - Util.ValidateHTTPStatusCode(DELETETestResponse, 204); - - - }//eot + // //Turn the list into an array of id's + // var v = ((JArray)a.ObjectResponse["data"]["searchResults"]); + // List MatchingIdList = new List(); + // foreach (JObject j in v) + // { + // MatchingIdList.Add(j["id"].Value()); + // } + + // //Ensure the expected items are returned + // MatchingIdList.Should().Contain(MatchingProjectId, "ShouldContainMatchingCustomFieldProjectId"); + + // //Now delete the newly created one so the list doesn't build up and prevent this test from working in big runs... + // //DELETE + // ApiResponse DELETETestResponse = await Util.DeleteAsync("project/" + MatchingProjectId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in")); + // Util.ValidateHTTPStatusCode(DELETETestResponse, 204); + // }//eot [Fact] public async Task DeletedObjectShouldRemoveKeywords() { string TEST_SEARCH_PHRASE = Util.Uniquify("qqwweerrttyy"); - //CREATE A PROJECT - dynamic d = new JObject(); - d.name = Util.Uniquify("Wildcard endswith search test PROJECT"); - - d.dollarAmount = 1.11m; - d.active = true; - d.usertype = 1; - d.notes = $"This record will match in notes: {TEST_SEARCH_PHRASE} there"; - - ApiResponse a = await Util.PostAsync("project", await Util.GetTokenAsync("superuser", "l3tm3in"), d.ToString()); + var projectName = Util.Uniquify("Delete removes keyword search test PROJECT"); + var dateStarted = DateTime.Now.ToString("o"); + var payload = $$""" + {"id":0,"concurrency":0,"name":"{{projectName}}","active":true,"notes":"This record will match in notes: {{TEST_SEARCH_PHRASE}} there","wiki":null,"customFields":"{}","tags":["blue","zebra"],"dateStarted":"{{dateStarted}}","dateCompleted":null,"projectOverseerId":null,"accountNumber":"TestAccountNumber"} + """; + ApiResponse a = await Util.PostAsync("project", await Util.GetTokenAsync("superuser", "l3tm3in"), payload); Util.ValidateDataReturnResponseOk(a); long ProjectId = (long)a.ObjectResponse["data"]["id"];