This commit is contained in:
2018-09-25 21:58:54 +00:00
parent 859549520a
commit 7d71d7ca33
3 changed files with 84 additions and 58 deletions

View File

@@ -20,20 +20,20 @@ namespace raven_integration
//CREATE A WIDGET
dynamic D = new JObject();
D.name = Util.Uniquify("Search Simple Test WIDGET");
D.name = Util.Uniquify("Search NOTES Test WIDGET");
D.dollarAmount = 1.11m;
D.active = true;
D.roles = 0;
D.notes = "The quick brown and simple fox jumped over the six lazy dogs!";
D.notes = "This record will match in notes: The quick brown and simple 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<long>();
long MatchWidgetInNotesId = a.ObjectResponse["result"]["id"].Value<long>();
//CREATE A USER
//CREATE FIRST TEST USER WITH PHRASE IN NAME
D = new JObject();
D.name = Util.Uniquify("Search simple Test User");
D.notes = "This user has the word dogs in its notes";
D.name = Util.Uniquify("Search NAME DOGS simple Test User");
D.notes = "This user has the match in it's name";
D.ownerId = 1L;
D.active = true;
D.login = Util.Uniquify("LOGIN");
@@ -44,23 +44,39 @@ namespace raven_integration
a = await Util.PostAsync("User", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString());
Util.ValidateDataReturnResponseOk(a);
long MatchUserId = a.ObjectResponse["result"]["id"].Value<long>();
long MatchUserInNameId = a.ObjectResponse["result"]["id"].Value<long>();
//CREATE A SECOND TEST USER WITH PHRASE IN NOTES
D = new JObject();
D.name = Util.Uniquify("Search NOTES Test User");
D.notes = "This user has the match simple 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 MatchUserInNotesId = a.ObjectResponse["result"]["id"].Value<long>();
//CREATE A SECOND WIDGET
D = new JObject();
D.name = Util.Uniquify("Search simple as in dogs SECOND Test WIDGET");
D.name = Util.Uniquify("Search NAME simple as in dogs 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";
D.notes = "This Widget matches in name";
a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString());
Util.ValidateDataReturnResponseOk(a);
long MatchSecondWidgetId = a.ObjectResponse["result"]["id"].Value<long>();
long MatchWidgetInNameId = a.ObjectResponse["result"]["id"].Value<long>();
//CREATE A THIRD WIDGET
D = new JObject();
D.name = Util.Uniquify("Search Simple THIRD Test WIDGET");
D.name = Util.Uniquify("Search NO-MATCH THIRD Test WIDGET");
D.dollarAmount = 1.11m;
D.active = true;
D.roles = 0;
@@ -68,7 +84,7 @@ namespace raven_integration
a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString());
Util.ValidateDataReturnResponseOk(a);
long NoMatchThirdWidgetId = a.ObjectResponse["result"]["id"].Value<long>();
long MatchNothingWidgetId = a.ObjectResponse["result"]["id"].Value<long>();
//Now see if can find those objects with a phrase search
@@ -92,10 +108,11 @@ namespace raven_integration
}
//Ensure the expected items are returned
MatchingIdList.Should().Contain(MatchFirstWidgetId, "ShouldContainFirstWidget");
MatchingIdList.Should().Contain(MatchSecondWidgetId, "ShouldContainSecondWidget");
MatchingIdList.Should().Contain(MatchUserId, "ShouldContainUser");
MatchingIdList.Should().NotContain(NoMatchThirdWidgetId, "ShouldNotContainThirdWidget");
MatchingIdList.Should().Contain(MatchWidgetInNotesId, "ShouldContainFirstWidget");
MatchingIdList.Should().Contain(MatchWidgetInNameId, "ShouldContainSecondWidget");
MatchingIdList.Should().Contain(MatchUserInNotesId, "ShouldContainUserNotesMatch");
MatchingIdList.Should().Contain(MatchUserInNameId, "ShouldContainUserNameMatch");
MatchingIdList.Should().NotContain(MatchNothingWidgetId, "ShouldNotContainThirdWidget");
//Assert the order (roughly, this is kind of a waste of time, either the code is sorting or not, it's not going to change)
//first item must be a widget
@@ -105,12 +122,29 @@ namespace raven_integration
a.ObjectResponse["result"][MatchingIdList.Count - 1]["type"].Value<int>().Should().Be(3);
//TEST THAT RIGHTS ARE WORKING PROPERLY WITH RETURNED RESULTS
//FULL BODY 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 Widget role instead
//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");
//NAME ONLY SEARCH SHOULD WORK WITH NO RIGHTS TO READ FULL RECORD
//IF NO RIGHTS TO FULL READ AND SEARCH IS ON FULL OBJECT AND NOT NAME THEN IT SHOULD NOT RETURN THE RESULTS
//repeat same search but with nameOnly = true and should return at two records at least but not any of the body ones
SearchParameters = new JObject();
SearchParameters.phrase = TEST_SEARCH_PHRASE;
SearchParameters.nameOnly = true;
SearchParameters.typeOnly = 0;//no type
a = await Util.PostAsync("Search", await Util.GetTokenAsync("SubContractorLimited"), SearchParameters.ToString());
Util.ValidateDataReturnResponseOk(a);
((JArray)a.ObjectResponse["result"]).Count.Should().BeGreaterOrEqualTo(2);
//Check that list does *not* include the notes only records
@@ -118,40 +152,31 @@ namespace raven_integration
/*
{{
"result": [
{
"name": "Search simple as in dogs SECOND Test WIDGET1537899693",
"type": 2,
"id": 205
},
{
"name": "Search Simple Test WIDGET1537899693",
"type": 2,
"id": 204
},
{
"name": "Search simple as in dogs SECOND Test WIDGET1537899490",
"type": 2,
"id": 202
},
{
"name": "Search Simple Test WIDGET1537899489",
"type": 2,
"id": 201
},
{
"name": "Search simple Test User1537899693",
"type": 3,
"id": 22
},
{
"name": "Search simple Test User1537899490",
"type": 3,
"id": 21
}
]
}}
{{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
}
]
}}
*/