From 5f337d500bdddcaf51327fa5ff89c9d8ef55a8aa Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 4 Dec 2018 15:46:23 +0000 Subject: [PATCH] --- .../ControllerHelpers/PagingOptions.cs | 4 +- server/AyaNova/Startup.cs | 2 +- .../DataFilter/DataFilterFilteringLists.cs | 130 +++++++++++++++++- 3 files changed, 132 insertions(+), 4 deletions(-) diff --git a/server/AyaNova/ControllerHelpers/PagingOptions.cs b/server/AyaNova/ControllerHelpers/PagingOptions.cs index a5adf334..b04eb80a 100644 --- a/server/AyaNova/ControllerHelpers/PagingOptions.cs +++ b/server/AyaNova/ControllerHelpers/PagingOptions.cs @@ -6,7 +6,7 @@ namespace AyaNova.Api.ControllerHelpers public sealed class PagingOptions { - public const int MaxPageSize = 100; + public const int MaxPageSize = 1000; public const int DefaultOffset = 0; public const int DefaultLimit = 25; @@ -15,7 +15,7 @@ namespace AyaNova.Api.ControllerHelpers public int? Offset { get; set; } [FromQuery] - [Range(1, MaxPageSize, ErrorMessage = "Limit must be greater than 0 and less than 100.")] + [Range(1, MaxPageSize, ErrorMessage = "Limit must be greater than 0 and less than 1000.")] public int? Limit { get; set; } public string Sort { get; set; } diff --git a/server/AyaNova/Startup.cs b/server/AyaNova/Startup.cs index 03b04bb0..736812f4 100644 --- a/server/AyaNova/Startup.cs +++ b/server/AyaNova/Startup.cs @@ -380,7 +380,7 @@ namespace AyaNova // ******************** TESTING WIPE DB ***************************** // //Set this to true to wipe the db and reinstall a trial license and re-seed the data - var TESTING_REFRESH_DB = false;//############################################################################################# + var TESTING_REFRESH_DB = true;//############################################################################################# #if (DEBUG) //TESTING diff --git a/test/raven-integration/DataFilter/DataFilterFilteringLists.cs b/test/raven-integration/DataFilter/DataFilterFilteringLists.cs index e86e72a0..c4ccd43b 100644 --- a/test/raven-integration/DataFilter/DataFilterFilteringLists.cs +++ b/test/raven-integration/DataFilter/DataFilterFilteringLists.cs @@ -66,7 +66,7 @@ namespace raven_integration /// /// [Fact] - public async void BoolFiltersWork() + public async void BoolOpEqualityFilterWorks() { //OPS: equal to, not equal to @@ -185,6 +185,134 @@ namespace raven_integration Util.ValidateHTTPStatusCode(a, 204); } + + + + /// + /// + /// + [Fact] + public async void BoolOpNotEqualFilterWorks() + { + + //OPS: equal to, not equal to + //values: true, false + + var WidgetNameStart = "BoolDataFilterTest"; + + List ActiveWidgetIdList = new List(); + List NotActiveWidgetIdList = new List(); + + //CREATE 4 TEST WIDGETS + //two active and two non active + + //first active widget + dynamic w = new JObject(); + w.name = Util.Uniquify(WidgetNameStart); + w.active = true; + w.roles = 0; + + ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString()); + Util.ValidateDataReturnResponseOk(a); + ActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value()); + + //second active widget + w.name = Util.Uniquify(WidgetNameStart); + + a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString()); + Util.ValidateDataReturnResponseOk(a); + ActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value()); + + + //first NON active widget + w.name = Util.Uniquify(WidgetNameStart); + w.active = false; + + a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString()); + Util.ValidateDataReturnResponseOk(a); + NotActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value()); + + //second NON active widget + w.name = Util.Uniquify(WidgetNameStart); + w.active = false; + + a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString()); + Util.ValidateDataReturnResponseOk(a); + NotActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value()); + + + //CREATE FILTER + dynamic d = new JObject(); + d.name = Util.Uniquify("Test BOOL DataFilter"); + // d.ownerId = 1L; + d["public"] = true; + d.listKey = "widget"; + + dynamic dfilter = new JArray(); + + //name starts with filter to constrict to widgets that this test block created only + dynamic DataFilterNameStart = new JObject(); + DataFilterNameStart.fld = "name"; + DataFilterNameStart.op = OpStartsWith; + DataFilterNameStart.value = WidgetNameStart; + dfilter.Add(DataFilterNameStart); + + //active bool test filter + dynamic DataFilterActive = new JObject(); + DataFilterActive.fld = "active"; + DataFilterActive.op = OpNotEqual; + DataFilterActive.value = true; + dfilter.Add(DataFilterActive); + + d.filter = dfilter.ToString();//it expects it to be a json string, not actual json + + a = await Util.PostAsync("DataFilter", await Util.GetTokenAsync("BizAdminFull"), d.ToString()); + Util.ValidateDataReturnResponseOk(a); + + long DataFilterId = a.ObjectResponse["data"]["id"].Value(); + + //NOW FETCH WIDGET LIST WITH FILTER + a = await Util.GetAsync($"Widget/listwidgets?Offset=0&Limit=999&DataFilterId={DataFilterId.ToString()}", await Util.GetTokenAsync("manager", "l3tm3in")); + Util.ValidateDataReturnResponseOk(a); + Util.ValidateHTTPStatusCode(a, 200); + + //assert contains at least two records + ((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(1); + var v = ((JArray)a.ObjectResponse["data"]); + List IDInResultList = new List(); + int nActiveMatches = 0; + int nInactiveMatches = 0; + foreach (JObject o in v) + { + if (ActiveWidgetIdList.Contains(o["id"].Value())) + nActiveMatches++; + if (NotActiveWidgetIdList.Contains(o["id"].Value())) + nInactiveMatches++; + } + + nInactiveMatches.Should().Be(NotActiveWidgetIdList.Count); + nActiveMatches.Should().Be(0); + + //DELETE WIDGETS + foreach (long l in ActiveWidgetIdList) + { + a = await Util.DeleteAsync("Widget/" + l.ToString(), await Util.GetTokenAsync("BizAdminFull")); + Util.ValidateHTTPStatusCode(a, 204); + } + + foreach (long l in NotActiveWidgetIdList) + { + a = await Util.DeleteAsync("Widget/" + l.ToString(), await Util.GetTokenAsync("BizAdminFull")); + Util.ValidateHTTPStatusCode(a, 204); + } + + //DELETE DATAFILTER + a = await Util.DeleteAsync("DataFilter/" + DataFilterId.ToString(), await Util.GetTokenAsync("BizAdminFull")); + Util.ValidateHTTPStatusCode(a, 204); + + } + + //TODO: Re-run search and compare active v inactive opposite of above //TODO: //UPDATE FILTER TO LIMIT TO INACTIVE BY FLIPPING THE OP TO NOTEQUAL //SAVE AS ANOTHER FILTER (or possibly modify the original one) AND RETEST