544 lines
28 KiB
C#
544 lines
28 KiB
C#
using Xunit;
|
|
using Newtonsoft.Json.Linq;
|
|
using FluentAssertions;
|
|
|
|
namespace raven_integration
|
|
{
|
|
|
|
public class SearchOps
|
|
{
|
|
[Fact]
|
|
public async Task PhraseOnlySearchShouldReturnCorrectResultsInOrder()
|
|
{
|
|
//CREATE A PROJECT phrase in notes
|
|
var projectName = Util.Uniquify("search notes test project should match");
|
|
var dateStarted = DateTime.Now.ToString("o");
|
|
var payload = $$"""
|
|
{"id":0,"concurrency":0,"name":"{{projectName}}","active":true,"notes":"This record will match in notes: The quick brown and simple fox jumped over the six lazy dogs!","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 MatchProjectInNotesId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
//CREATE FIRST TEST USER WITH PHRASE IN NAME
|
|
var userName = Util.Uniquify("search NAME DOGS simple Test User");
|
|
payload = $$"""
|
|
{"id":0,"concurrency":0,"active":true,"allowLogin":true,"name":"{{userName}}","roles":8,"userType":2,"employeeNumber":null,"notes":null,"customerId":null,"headOfficeId":null,"vendorId":null,"wiki":null,"customFields":"{}","tags":[],"lastLogin":null,"password":"{{userName}}","login":"{{userName}}"}
|
|
""";
|
|
a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), payload);
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
long MatchUserInNameId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
//CREATE A SECOND TEST USER WITH PHRASE IN NOTES
|
|
userName = Util.Uniquify("search NOTES 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 simple dogs in its notes","customerId":null,"headOfficeId":null,"vendorId":null,"wiki":null,"customFields":"{}","tags":[],"lastLogin":null,"password":"{{userName}}","login":"{{userName}}"}
|
|
""";
|
|
a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), payload);
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
long MatchUserInNotesId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
//CREATE A SECOND PROJECT
|
|
projectName = Util.Uniquify("search NAME simple as in dogs Test PROJECT");
|
|
payload = $$"""
|
|
{"id":0,"concurrency":0,"name":"{{projectName}}","active":true,"notes":"This Project matches in name","wiki":null,"customFields":"{}","tags":["blue","zebra"],"dateStarted":"{{dateStarted}}","dateCompleted":null,"projectOverseerId":null,"accountNumber":"TestAccountNumber"}
|
|
""";
|
|
a = await Util.PostAsync("project", await Util.GetTokenAsync("superuser", "l3tm3in"), payload);
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
long MatchProjectInNameId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
//CREATE A THIRD PROJECT
|
|
projectName = Util.Uniquify("XXX NO MATCH search simple THIRD Test PROJECT");
|
|
payload = $$"""
|
|
{"id":0,"concurrency":0,"name":"{{projectName}}","active":true,"notes":"This Project should not be returned in the search as it only contains a single keyword in the name not both","wiki":null,"customFields":"{}","tags":["blue","zebra"],"dateStarted":"{{dateStarted}}","dateCompleted":null,"projectOverseerId":null,"accountNumber":"TestAccountNumber"}
|
|
""";
|
|
a = await Util.PostAsync("project", await Util.GetTokenAsync("superuser", "l3tm3in"), payload);
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
long MatchNothingProjectId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
//Now see if can find those objects with a phrase search
|
|
dynamic SearchParameters = new JObject();
|
|
SearchParameters.phrase = "simple dogs";
|
|
SearchParameters.typeOnly = 0;//no type
|
|
SearchParameters.maxResults = 0;
|
|
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(4);
|
|
|
|
//Turn the list into an array of id's
|
|
var v = ((JArray)a.ObjectResponse["data"]["searchResults"]);
|
|
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(MatchProjectInNotesId, "ShouldContainMatchProjectInNotesId");
|
|
MatchingIdList.Should().Contain(MatchProjectInNameId, "ShouldContainMatchProjectInNameId");
|
|
MatchingIdList.Should().Contain(MatchUserInNotesId, "ShouldContainMatchUserInNotesId");
|
|
MatchingIdList.Should().Contain(MatchUserInNameId, "ShouldContainMatchUserInNameId");
|
|
MatchingIdList.Should().NotContain(MatchNothingProjectId, "ShouldNotContainMatchNothingProjectId");
|
|
|
|
//SEARCH RIGHTS
|
|
//First up test a full record search returns no results due to insufficient rights
|
|
//even though the record exists
|
|
//Just re-run the above search exactly but with a no rights to full User or Project role instead
|
|
|
|
//This search should return zero items
|
|
a = await Util.PostAsync("search", await Util.GetTokenAsync("SubContractorRestricted"), SearchParameters.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
((JArray)a.ObjectResponse["data"]["searchResults"]).Count.Should().Be(0, "User with no rights should not see any results in body search");
|
|
|
|
}//eot
|
|
|
|
|
|
|
|
[Fact]
|
|
public async Task WildCardStartsWithSearchShouldWork()
|
|
{
|
|
const string TEST_SEARCH_PHRASE = "hap* goose";
|
|
|
|
//CREATE A PROJECT
|
|
var projectName = Util.Uniquify("Wildcard startswith 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: The quick brown and hapless goose","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 MatchProjectInNotesId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
//CREATE FIRST TEST USER WITH PHRASE IN NAME
|
|
var userName = Util.Uniquify("Wildcard startswith search NAME happy goose 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","customerId":null,"headOfficeId":null,"vendorId":null,"wiki":null,"customFields":"{}","tags":[],"lastLogin":null,"password":"{{userName}}","login":"{{userName}}"}
|
|
""";
|
|
a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), payload);
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
long MatchUserInNameId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
|
|
//Now see if can find those objects with a phrase search
|
|
dynamic SearchParameters = new JObject();
|
|
|
|
SearchParameters.phrase = TEST_SEARCH_PHRASE;
|
|
|
|
SearchParameters.typeOnly = 0;//no type
|
|
SearchParameters.maxResults = 0;
|
|
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(2);
|
|
|
|
//Turn the list into an array of id's
|
|
var v = ((JArray)a.ObjectResponse["data"]["searchResults"]);
|
|
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(MatchProjectInNotesId, "ShouldContainMatchProjectInNotesId");
|
|
MatchingIdList.Should().Contain(MatchUserInNameId, "ShouldContainMatchUserInNameId");
|
|
|
|
}//eot
|
|
|
|
|
|
[Fact]
|
|
public async Task WildCardEndsWithSearchShouldWork()
|
|
{
|
|
const string TEST_SEARCH_PHRASE = "goose *act";
|
|
|
|
//CREATE A PROJECT
|
|
var projectName = Util.Uniquify("Wildcard endswith 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: react to the goose","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 MatchProjectInNotesId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
//CREATE FIRST TEST USER WITH PHRASE IN NAME
|
|
var userName = Util.Uniquify("Wildcard endswith search NAME goose exact 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","customerId":null,"headOfficeId":null,"vendorId":null,"wiki":null,"customFields":"{}","tags":[],"lastLogin":null,"password":"{{userName}}","login":"{{userName}}"}
|
|
""";
|
|
a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), payload);
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
long MatchUserInNameId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
|
|
//Now see if can find those objects with a phrase search
|
|
dynamic SearchParameters = new JObject();
|
|
|
|
SearchParameters.phrase = TEST_SEARCH_PHRASE;
|
|
|
|
SearchParameters.typeOnly = 0;//no type
|
|
SearchParameters.maxResults = 0;
|
|
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(2);
|
|
|
|
//Turn the list into an array of id's
|
|
var v = ((JArray)a.ObjectResponse["data"]["searchResults"]);
|
|
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(MatchProjectInNotesId, "ShouldContainMatchProjectInNotesId");
|
|
MatchingIdList.Should().Contain(MatchUserInNameId, "ShouldContainMatchUserInNameId");
|
|
|
|
}//eot
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
public async Task SearchAndExtractShouldWork()
|
|
{
|
|
const string TEST_SEARCH_PHRASE = "*cast* goose";
|
|
//CREATE A PROJECT
|
|
var projectName = Util.Uniquify("Wildcard contains 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: broadcasting to the goose","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 MatchProjectInNotesId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
//CREATE FIRST TEST USER WITH PHRASE IN NAME
|
|
var userName = Util.Uniquify("Wildcard contains search NAME goose elcastro 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","customerId":null,"headOfficeId":null,"vendorId":null,"wiki":null,"customFields":"{}","tags":[],"lastLogin":null,"password":"{{userName}}","login":"{{userName}}"}
|
|
""";
|
|
a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), payload);
|
|
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
long MatchUserInNameId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
|
|
//Now see if can find those objects with a phrase search
|
|
dynamic SearchParameters = new JObject();
|
|
|
|
SearchParameters.phrase = TEST_SEARCH_PHRASE;
|
|
|
|
SearchParameters.typeOnly = 0;//no type
|
|
SearchParameters.maxResults = 0;
|
|
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(2);
|
|
|
|
//Turn the list into an array of id's
|
|
var v = ((JArray)a.ObjectResponse["data"]["searchResults"]);
|
|
List<long> MatchingIdList = [];
|
|
foreach (JObject j in v)
|
|
{
|
|
MatchingIdList.Add(j["id"].Value<long>());
|
|
}
|
|
|
|
//Ensure the expected items are returned
|
|
MatchingIdList.Should().Contain(MatchProjectInNotesId, "ShouldContainMatchProjectInNotesId");
|
|
MatchingIdList.Should().Contain(MatchUserInNameId, "ShouldContainMatchUserInNameId");
|
|
|
|
|
|
//Ensure excerpt works and contains the search phrase
|
|
// /Search/Info/2/1?phrase=we&max=200
|
|
a = await Util.GetAsync($"search/Info/25/{MatchProjectInNotesId}?phrase={TEST_SEARCH_PHRASE}&max=200", await Util.GetTokenAsync("superuser", "l3tm3in"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
a.ObjectResponse["data"].Value<string>().Should().Contain("broadcasting to the goose");
|
|
a.ObjectResponse["data"].Value<string>().Should().Contain("PROJECT");
|
|
|
|
}//eot
|
|
|
|
|
|
[Fact]
|
|
public async Task TagSearchShouldWork()
|
|
{
|
|
const string TEST_SEARCH_PHRASE = "element* aardvark";
|
|
|
|
// //CREATE A TAG
|
|
// dynamic D = new JObject();
|
|
// D.name = Util.Uniquify("TAGSEARCH");
|
|
// ApiResponse a = await Util.PostAsync("Tag", await Util.GetTokenAsync("superuser", "l3tm3in"), D.ToString());
|
|
// Util.ValidateDataReturnResponseOk(a);
|
|
// long TagId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
|
|
var SearchTagPhrase = Util.Uniquify("TAGSEARCH");
|
|
//Tags
|
|
dynamic TagsArray = new JArray();
|
|
TagsArray.Add(SearchTagPhrase);
|
|
|
|
|
|
//CREATE A PROJECT
|
|
var projectName = Util.Uniquify("TAG search test PROJECT TAG AND PHRASE");
|
|
var dateStarted = DateTime.Now.ToString("o");
|
|
var payload = $$"""
|
|
{"id":0,"concurrency":0,"name":"{{projectName}}","active":true,"notes":"This record will match in notes and tag: elementary my dear aardvark","wiki":null,"customFields":"{}","tags":["{{SearchTagPhrase}}","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 MatchProjectInNotesId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
//CREATE A PROJECT WITH TAG BUT NOT SEARCH PHRASE
|
|
projectName = Util.Uniquify("TAG search test PROJECT TAG ONLY");
|
|
payload = $$"""
|
|
{"id":0,"concurrency":0,"name":"{{projectName}}","active":true,"notes":"This record will match in tag but no search phrase","wiki":null,"customFields":"{}","tags":["{{SearchTagPhrase}}","zebra"],"dateStarted":"{{dateStarted}}","dateCompleted":null,"projectOverseerId":null,"accountNumber":"TestAccountNumber"}
|
|
""";
|
|
a = await Util.PostAsync("project", await Util.GetTokenAsync("superuser", "l3tm3in"), payload);
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
long NoPhraseMatchProjectInTagId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
//CREATE FIRST TEST USER WITH PHRASE IN NAME BUT NO TAG
|
|
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}}"}
|
|
""";
|
|
a = await Util.PostAsync("User", await Util.GetTokenAsync("superuser", "l3tm3in"), payload);
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
long MatchUserInNameId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
|
|
//Now see if can find those objects with a phrase search
|
|
dynamic SearchParameters = new JObject();
|
|
|
|
SearchParameters.phrase = TEST_SEARCH_PHRASE + " " + SearchTagPhrase;
|
|
|
|
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);
|
|
|
|
//Turn the list into an array of id's
|
|
var v = (JArray)a.ObjectResponse["data"]["searchResults"];
|
|
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(MatchProjectInNotesId, "ShouldContainMatchProjectInNotesId");
|
|
MatchingIdList.Should().NotContain(MatchUserInNameId, "ShouldNotContainMatchUserInNameId");
|
|
MatchingIdList.Should().NotContain(NoPhraseMatchProjectInTagId, "ShouldNotContainNoPhraseMatchProjectInTagId");
|
|
|
|
}//eot
|
|
|
|
|
|
|
|
[Fact]
|
|
public async Task ConstrainedBigDataSearchShouldHonourMaxResultsAndBeRelativelyFast()
|
|
{
|
|
//THIS test is a bit different in that it relies partly on the big dataset for testing
|
|
//so it has different paths depending upon if it's testing against the big data or not
|
|
const string TEST_SEARCH_PHRASE = "et*";
|
|
|
|
//Now see if can find those objects with a phrase search
|
|
dynamic SearchParameters = new JObject();
|
|
|
|
SearchParameters.phrase = TEST_SEARCH_PHRASE;
|
|
|
|
SearchParameters.typeOnly = 0;//no type
|
|
SearchParameters.maxResults = 1000;//default is 500
|
|
|
|
var watch = new System.Diagnostics.Stopwatch();
|
|
watch.Start();
|
|
ApiResponse a = await Util.PostAsync("search", await Util.GetTokenAsync("superuser", "l3tm3in"), SearchParameters.ToString());
|
|
watch.Stop();
|
|
|
|
var TimeToSearch = watch.ElapsedMilliseconds;
|
|
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
//Now validate the return list
|
|
var ResultCount = ((JArray)a.ObjectResponse["data"]["searchResults"]).Count;
|
|
//assert it's not unbounded
|
|
ResultCount.Should().BeLessOrEqualTo(1000);
|
|
|
|
if (ResultCount > 999)
|
|
{
|
|
//assert the TotalResultsFound is greater than the results returned
|
|
var TotalResultsFound = a.ObjectResponse["data"]["totalResultsFound"].Value<long>();
|
|
//assert it's not unbounded
|
|
TotalResultsFound.Should().BeGreaterThan(ResultCount);
|
|
}
|
|
//5456 ms is the longest I've seen in initial testing with all 1000 results so setting 10% above
|
|
TimeToSearch.Should().BeLessThan(6000, "Constrained big data search should not be too slow");
|
|
|
|
}//eot
|
|
|
|
|
|
[Fact]
|
|
public async Task UnboundBigDataSearchShouldBeRelativelyFast()
|
|
{
|
|
//THIS test is a bit different in that it relies partly on the big dataset for testing
|
|
//so it has different paths depending upon if it's testing against the big data or not
|
|
const string TEST_SEARCH_PHRASE = "et*";
|
|
|
|
//Now see if can find those objects with a phrase search
|
|
dynamic SearchParameters = new JObject();
|
|
|
|
SearchParameters.phrase = TEST_SEARCH_PHRASE;
|
|
|
|
SearchParameters.typeOnly = 0;//no type
|
|
SearchParameters.maxResults = 0;//0=return all results
|
|
|
|
var watch = new System.Diagnostics.Stopwatch();
|
|
watch.Start();
|
|
ApiResponse a = await Util.PostAsync("search", await Util.GetTokenAsync("superuser", "l3tm3in"), SearchParameters.ToString());
|
|
watch.Stop();
|
|
|
|
var TimeToSearch = watch.ElapsedMilliseconds;
|
|
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
//Now validate the return list
|
|
var ResultCount = ((JArray)a.ObjectResponse["data"]["searchResults"]).Count;
|
|
|
|
|
|
//Set this time based on testing. 52385 Slowest run plus 10%
|
|
TimeToSearch.Should().BeLessThan(57623, "Unconstrained big data search should not be too slow");
|
|
|
|
|
|
}//eot
|
|
|
|
|
|
|
|
[Fact]
|
|
public async Task SearchForSerialFieldShouldWork()
|
|
{
|
|
//just search for workorder number 99 should always be there
|
|
dynamic SearchParameters = new JObject();
|
|
SearchParameters.phrase = "99";
|
|
SearchParameters.typeOnly = 34;//workorder
|
|
SearchParameters.maxResults = 0;
|
|
ApiResponse a = await Util.PostAsync("search", await Util.GetTokenAsync("superuser", "l3tm3in"), SearchParameters.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
//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<long>();
|
|
|
|
|
|
// //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<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(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
|
|
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"];
|
|
|
|
//Now see if can find with a phrase search
|
|
dynamic SearchParameters = new JObject();
|
|
SearchParameters.phrase = TEST_SEARCH_PHRASE;
|
|
SearchParameters.typeOnly = 0;//no type
|
|
SearchParameters.maxResults = 0;
|
|
a = await Util.PostAsync("search", await Util.GetTokenAsync("superuser", "l3tm3in"), SearchParameters.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
//Now validate the return list (should be only one as it's super unique)
|
|
((JArray)a.ObjectResponse["data"]["searchResults"]).Count.Should().Be(1);
|
|
|
|
//Now delete the project and re-run the search
|
|
a = await Util.DeleteAsync("project/" + ProjectId.ToString(), await Util.GetTokenAsync("superuser", "l3tm3in"));
|
|
Util.ValidateHTTPStatusCode(a, 204);
|
|
|
|
a = await Util.PostAsync("search", await Util.GetTokenAsync("superuser", "l3tm3in"), SearchParameters.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
//Now validate the return list (should be only one as it's super unique)
|
|
((JArray)a.ObjectResponse["data"]["searchResults"]).Count.Should().Be(0);
|
|
|
|
|
|
}//eot
|
|
//==================================================
|
|
|
|
}//eoc
|
|
}//eons
|