diff --git a/server/AyaNova/biz/FilterSqlCriteriaBuilder.cs b/server/AyaNova/biz/FilterSqlCriteriaBuilder.cs index 2fe9e7cb..4598bf51 100644 --- a/server/AyaNova/biz/FilterSqlCriteriaBuilder.cs +++ b/server/AyaNova/biz/FilterSqlCriteriaBuilder.cs @@ -132,7 +132,7 @@ namespace AyaNova.Biz #region Build for specific type switch (sDataType) - { + { case AyDataType.Text: //escape any pre-existing apostrophes //i.e. "O'Flaherty's pub" would cause fits @@ -761,12 +761,7 @@ namespace AyaNova.Biz case FilterComparisonOperator.LessThanOrEqualTo: sb.Append("<="); sb.Append(sValue); - break; - // case "Like": - // sb.Append("Like N'"); - // sb.Append(sValue); - // sb.Append("%'"); - // break; + break; case FilterComparisonOperator.NotEqual: sb.Append("<>"); sb.Append(sValue); diff --git a/server/AyaNova/models/Widget.cs b/server/AyaNova/models/Widget.cs index e48a817c..3d8a3d1c 100644 --- a/server/AyaNova/models/Widget.cs +++ b/server/AyaNova/models/Widget.cs @@ -23,6 +23,7 @@ namespace AyaNova.Models public DateTime? StartDate { get; set; } public DateTime? EndDate { get; set; } public string Notes { get; set; } + public int Count {get;set;} } diff --git a/server/AyaNova/util/AySchema.cs b/server/AyaNova/util/AySchema.cs index 3e59f913..6c88a41c 100644 --- a/server/AyaNova/util/AySchema.cs +++ b/server/AyaNova/util/AySchema.cs @@ -205,7 +205,7 @@ namespace AyaNova.Util //Add widget table //id, text, longtext, boolean, currency, exec("CREATE TABLE awidget (id BIGSERIAL PRIMARY KEY, ownerid bigint not null, name varchar(255) not null, serial bigint not null," + - "startdate timestamp, enddate timestamp, dollaramount decimal(19,5), active bool, roles int4, notes text)"); + "startdate timestamp, enddate timestamp, dollaramount decimal(19,5), active bool, roles int4, count integer, notes text)"); //TEST TEST TEST ONLY FOR DEVELOPMENT TESTING TO ENSURE UNIQUENESS //exec("CREATE UNIQUE INDEX awidget_serial_idx ON awidget (serial);"); diff --git a/test/raven-integration/DataFilter/DataFilterFilteringLists.cs b/test/raven-integration/DataFilter/DataFilterFilteringLists.cs index c4ccd43b..96485893 100644 --- a/test/raven-integration/DataFilter/DataFilterFilteringLists.cs +++ b/test/raven-integration/DataFilter/DataFilterFilteringLists.cs @@ -52,9 +52,154 @@ namespace raven_integration //TODO: Specifically test a string with an apostrophe in it (for inclusive, finding ti) //TODO: specifically test a string with an ampersand character in it for inclusive (finding it) + /////////////////////// //INT // + /** + + case FilterComparisonOperator.Equality: + sb.Append("="); + sb.Append(sValue); + break; + case FilterComparisonOperator.GreaterThan: + sb.Append(">"); + sb.Append(sValue); + break; + case FilterComparisonOperator.GreaterThanOrEqualTo: + sb.Append(">="); + sb.Append(sValue); + break; + case FilterComparisonOperator.LessThan: + sb.Append("<"); + sb.Append(sValue); + break; + case FilterComparisonOperator.LessThanOrEqualTo: + sb.Append("<="); + sb.Append(sValue); + break; + case FilterComparisonOperator.NotEqual: + */ + + /// + /// + /// + [Fact] + public async void IntegerOpEqualityFilterWorks() + { + + //OPS: equal to, not equal to + //values: true, false + + var WidgetNameStart = "IntegerDataFilterTest"; + + long IncludedWidgetId = 0; + long ExcludedWidgetId = 0; + + //CREATE TEST WIDGETS + + + //included widget + dynamic w = new JObject(); + w.name = Util.Uniquify(WidgetNameStart); + w.active = true; + w.roles = 0; + w.count = 555; + + ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString()); + Util.ValidateDataReturnResponseOk(a); + IncludedWidgetId = a.ObjectResponse["data"]["id"].Value(); + + //Excluded widget + w.name = Util.Uniquify(WidgetNameStart); + w.count = 333; + a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString()); + Util.ValidateDataReturnResponseOk(a); + ExcludedWidgetId = a.ObjectResponse["data"]["id"].Value(); + + + + + //CREATE FILTER + dynamic d = new JObject(); + d.name = Util.Uniquify("Test INT 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); + + //inclusive test filter + + HERE + + dynamic DataFilterActive = new JObject(); + DataFilterActive.fld = "active"; + DataFilterActive.op = OpEquality; + 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?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++; + } + + nActiveMatches.Should().Be(ActiveWidgetIdList.Count); + nInactiveMatches.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); + + } + + + + + + + /////////////////////// //BOOL