This commit is contained in:
@@ -23,15 +23,22 @@ namespace AyaNova.Biz
|
||||
public const string InTheLast3Months = "{[last3months]}";
|
||||
public const string InTheLast6Months = "{[last6months]}";
|
||||
public const string InTheLastYear = "{[lastcalendaryear]}";
|
||||
public const string AH = "{[ah]}";
|
||||
public const string IP = "{[ip]}";
|
||||
public const string QZ = "{[qz]}";
|
||||
public const string ZeroToThree = "{[03]}";
|
||||
public const string FourToSix = "{[46]}";
|
||||
public const string SevenToNine = "{[79]}";
|
||||
public const string LessThanZero = "{[<0]}";
|
||||
|
||||
|
||||
//These TEXT filter tokens were more for paging purposes than anything else
|
||||
//however paging is done by numeric range now so will not implement for now
|
||||
// public const string AH = "{[ah]}";
|
||||
// public const string IP = "{[ip]}";
|
||||
// public const string QZ = "{[qz]}";
|
||||
// public const string ZeroToThree = "{[03]}";
|
||||
// public const string FourToSix = "{[46]}";
|
||||
// public const string SevenToNine = "{[79]}";
|
||||
|
||||
|
||||
//Don't think I need these
|
||||
//public const string LessThanZero = "{[<0]}";
|
||||
// public const string Zero = "{[0]}";
|
||||
public const string GreaterThanZero = "{[>0]}";
|
||||
//public const string GreaterThanZero = "{[>0]}";
|
||||
|
||||
//https://www.klipfolio.com/resources/articles/kpi-timeframe-comparison-metrics
|
||||
//Quarters: https://www.investopedia.com/terms/q/quarter.asp
|
||||
|
||||
@@ -132,23 +132,19 @@ 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
|
||||
//if this wasn't done
|
||||
//MS-sql and firebird use double apostrophes so
|
||||
//any future db added should consider this
|
||||
|
||||
|
||||
//RAVEN - Removed this because I think postgres would be ok with it, it's not a special character
|
||||
//will have a specific test for this to ensure.
|
||||
//https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-SPECIAL-CHARS
|
||||
// sValue = sValue.Replace("'", "''");
|
||||
//i.e. "O'Flaherty's pub"
|
||||
sValue = sValue.Replace("'", "''");
|
||||
|
||||
//case 1951 - unescape ampersands
|
||||
sValue = sValue.Replace("&", "&");
|
||||
|
||||
//RAVEN NOTE: Decided not to implement TEXT token criteria for now (TTM, probably not useful)
|
||||
//meaning the A-H etc group ranges by alpha bet chunk
|
||||
|
||||
#region Build TEXT OPS criteria
|
||||
switch (sOperator)
|
||||
{
|
||||
case FilterComparisonOperator.Equality:
|
||||
@@ -234,6 +230,7 @@ namespace AyaNova.Biz
|
||||
throw new System.ArgumentOutOfRangeException("OPERATOR_TYPE", sOperator, "GridToSqlCriteria unhandled operator type [" + sOperator + "] IN STRING");
|
||||
|
||||
}
|
||||
#endregion build text ops criteria
|
||||
break;
|
||||
case AyDataType.Bool:
|
||||
{
|
||||
@@ -761,7 +758,7 @@ namespace AyaNova.Biz
|
||||
case FilterComparisonOperator.LessThanOrEqualTo:
|
||||
sb.Append("<=");
|
||||
sb.Append(sValue);
|
||||
break;
|
||||
break;
|
||||
case FilterComparisonOperator.NotEqual:
|
||||
sb.Append("<>");
|
||||
sb.Append(sValue);
|
||||
|
||||
@@ -46,8 +46,6 @@ namespace raven_integration
|
||||
//
|
||||
|
||||
#region STRING FILTER TESTS
|
||||
//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)
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
@@ -171,6 +169,254 @@ namespace raven_integration
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Specifically test a string with an apostrophe in it (for inclusive)
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void TextApostropheOpEqualityFilterWorks()
|
||||
{
|
||||
|
||||
var TestName = "TextApostropheOpEqualityFilterWorks";
|
||||
var WidgetRunNameStart = Util.Uniquify(TestName);
|
||||
|
||||
List<long> InclusiveWidgetIdList = new List<long>();
|
||||
List<long> ExclusiveWidgetIdList = new List<long>();
|
||||
|
||||
//CREATE 4 TEST WIDGETS
|
||||
//two inclusive and two not inclusive
|
||||
|
||||
//first inclusive widget
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetRunNameStart);
|
||||
w.notes = "O'Flaherty's pub";
|
||||
w.roles = 0;
|
||||
|
||||
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
InclusiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>());
|
||||
|
||||
//second inclusive widget
|
||||
w.name = Util.Uniquify(WidgetRunNameStart);
|
||||
|
||||
a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
InclusiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>());
|
||||
|
||||
//first exclusive widget
|
||||
w.name = Util.Uniquify(WidgetRunNameStart);
|
||||
w.notes = "Outback steak house";
|
||||
w.active = false;
|
||||
|
||||
a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
ExclusiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>());
|
||||
|
||||
//second exclusive widget
|
||||
w.name = Util.Uniquify(WidgetRunNameStart);
|
||||
w.active = false;
|
||||
|
||||
a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
ExclusiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>());
|
||||
|
||||
|
||||
//CREATE FILTER
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify(WidgetRunNameStart);
|
||||
// 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 = WidgetRunNameStart;
|
||||
dfilter.Add(DataFilterNameStart);
|
||||
|
||||
//active bool test filter
|
||||
dynamic DataFilterActive = new JObject();
|
||||
DataFilterActive.fld = "notes";
|
||||
DataFilterActive.op = OpEquality;
|
||||
DataFilterActive.value = "O'Flaherty's pub";
|
||||
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<long>();
|
||||
|
||||
//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<long> IDInResultList = new List<long>();
|
||||
int InclusiveMatchCount = 0;
|
||||
int ExclusiveMatchCount = 0;
|
||||
foreach (JObject o in v)
|
||||
{
|
||||
if (InclusiveWidgetIdList.Contains(o["id"].Value<long>()))
|
||||
InclusiveMatchCount++;
|
||||
if (ExclusiveWidgetIdList.Contains(o["id"].Value<long>()))
|
||||
ExclusiveMatchCount++;
|
||||
}
|
||||
|
||||
InclusiveMatchCount.Should().Be(InclusiveWidgetIdList.Count);
|
||||
ExclusiveMatchCount.Should().Be(0);
|
||||
|
||||
//DELETE WIDGETS
|
||||
foreach (long l in InclusiveWidgetIdList)
|
||||
{
|
||||
a = await Util.DeleteAsync("Widget/" + l.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
}
|
||||
|
||||
foreach (long l in ExclusiveWidgetIdList)
|
||||
{
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// specifically test a string with an ampersand character in it for inclusive (finding it)
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void TextAmpersandOpEqualityFilterWorks()
|
||||
{
|
||||
|
||||
var TestName = "TextAmpersandOpEqualityFilterWorks";
|
||||
var WidgetRunNameStart = Util.Uniquify(TestName);
|
||||
|
||||
List<long> InclusiveWidgetIdList = new List<long>();
|
||||
List<long> ExclusiveWidgetIdList = new List<long>();
|
||||
|
||||
//CREATE 4 TEST WIDGETS
|
||||
//two inclusive and two not inclusive
|
||||
|
||||
//first inclusive widget
|
||||
dynamic w = new JObject();
|
||||
w.name = Util.Uniquify(WidgetRunNameStart);
|
||||
w.notes = "Bill & Ted's excellent adventure";
|
||||
w.roles = 0;
|
||||
|
||||
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
InclusiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>());
|
||||
|
||||
//second inclusive widget
|
||||
w.name = Util.Uniquify(WidgetRunNameStart);
|
||||
|
||||
a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
InclusiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>());
|
||||
|
||||
//first exclusive widget
|
||||
w.name = Util.Uniquify(WidgetRunNameStart);
|
||||
w.notes = "Strange things are afoot at the Circle-K";
|
||||
w.active = false;
|
||||
|
||||
a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
ExclusiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>());
|
||||
|
||||
//second exclusive widget
|
||||
w.name = Util.Uniquify(WidgetRunNameStart);
|
||||
w.active = false;
|
||||
|
||||
a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString());
|
||||
Util.ValidateDataReturnResponseOk(a);
|
||||
ExclusiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value<long>());
|
||||
|
||||
|
||||
//CREATE FILTER
|
||||
dynamic d = new JObject();
|
||||
d.name = Util.Uniquify(WidgetRunNameStart);
|
||||
// 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 = WidgetRunNameStart;
|
||||
dfilter.Add(DataFilterNameStart);
|
||||
|
||||
//active bool test filter
|
||||
dynamic DataFilterActive = new JObject();
|
||||
DataFilterActive.fld = "notes";
|
||||
DataFilterActive.op = OpEquality;
|
||||
DataFilterActive.value = "Bill & Ted's excellent adventure";
|
||||
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<long>();
|
||||
|
||||
//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<long> IDInResultList = new List<long>();
|
||||
int InclusiveMatchCount = 0;
|
||||
int ExclusiveMatchCount = 0;
|
||||
foreach (JObject o in v)
|
||||
{
|
||||
if (InclusiveWidgetIdList.Contains(o["id"].Value<long>()))
|
||||
InclusiveMatchCount++;
|
||||
if (ExclusiveWidgetIdList.Contains(o["id"].Value<long>()))
|
||||
ExclusiveMatchCount++;
|
||||
}
|
||||
|
||||
InclusiveMatchCount.Should().Be(InclusiveWidgetIdList.Count);
|
||||
ExclusiveMatchCount.Should().Be(0);
|
||||
|
||||
//DELETE WIDGETS
|
||||
foreach (long l in InclusiveWidgetIdList)
|
||||
{
|
||||
a = await Util.DeleteAsync("Widget/" + l.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
Util.ValidateHTTPStatusCode(a, 204);
|
||||
}
|
||||
|
||||
foreach (long l in ExclusiveWidgetIdList)
|
||||
{
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endregion string filter tests
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user