This commit is contained in:
196
test/raven-integration/DataFilter/DataFilterFilteringLists.cs
Normal file
196
test/raven-integration/DataFilter/DataFilterFilteringLists.cs
Normal file
@@ -0,0 +1,196 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace raven_integration
|
||||
{
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Using the widget object test all filtering options
|
||||
for all data types, all operation types
|
||||
|
||||
This is the supertest to always confirm the filtering code is working as expected.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
public class DataFilterFilteringLists
|
||||
{
|
||||
public const string OpEquality = "=";
|
||||
public const string OpGreaterThan = ">";
|
||||
public const string OpGreaterThanOrEqualTo = ">=";
|
||||
public const string OpLessThan = "<";
|
||||
public const string OpLessThanOrEqualTo = "<=";
|
||||
public const string OpNotEqual = "!=";
|
||||
public const string OpNotLike = "!%";
|
||||
public const string OpStartsWith = "%-";
|
||||
public const string OpEndsWith = "-%";
|
||||
public const string OpContains = "-%-";
|
||||
public const string OpNotContains = "!-%-";
|
||||
|
||||
// public const string AyDataTypeDate = "date";
|
||||
// public const string AyDataTypeText = "text";
|
||||
// public const string AyDataTypeInteger = "int";
|
||||
// public const string AyDataTypeBool = "bool";
|
||||
// public const string AyDataTypeDecimal = "decimal";
|
||||
|
||||
|
||||
|
||||
///////////////////////
|
||||
//DATE
|
||||
//
|
||||
|
||||
///////////////////////
|
||||
//TEXT
|
||||
//
|
||||
|
||||
///////////////////////
|
||||
//INT
|
||||
//
|
||||
|
||||
///////////////////////
|
||||
//BOOL
|
||||
//
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BoolFiltersWork()
|
||||
{
|
||||
|
||||
//OPS: equal to, not equal to
|
||||
//values: true, false
|
||||
|
||||
var WidgetNameStart = "BoolDataFilterTest";
|
||||
|
||||
List<long> ActiveWidgetIdList = new List<long>();
|
||||
List<long> NotActiveWidgetIdList = new List<long>();
|
||||
|
||||
//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<long>());
|
||||
|
||||
//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<long>());
|
||||
|
||||
|
||||
//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<long>());
|
||||
|
||||
//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<long>());
|
||||
|
||||
|
||||
//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 = 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<long>();
|
||||
|
||||
//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 aAll contains exactly two records
|
||||
((JArray)a.ObjectResponse["data"]).Count.Should().Be(2);
|
||||
|
||||
//TODO: ensure the results match the appropriate matching widgetIDList made earlier
|
||||
|
||||
|
||||
|
||||
// //UPDATE FILTER TO LIMIT TO INACTIVE
|
||||
|
||||
// //PUT, make private
|
||||
// d["public"] = false;
|
||||
// d.name = Util.Uniquify("Put - Test DataFilter (privatized)");
|
||||
// d.concurrencyToken = a.ObjectResponse["data"]["concurrencyToken"].Value<uint>();
|
||||
// a = await Util.PutAsync("DataFilter/" + DataFilterId.ToString(), await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
||||
// Util.ValidateHTTPStatusCode(a, 200);
|
||||
|
||||
// //check PUT worked
|
||||
// a = await Util.GetAsync("DataFilter/" + DataFilterId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
// Util.ValidateNoErrorInResponse(a);
|
||||
// a.ObjectResponse["data"]["name"].Value<string>().Should().Be(d.name.ToString());
|
||||
|
||||
|
||||
// //FETCH DISALLOWED
|
||||
// //Get as alternate user should fail for private filter
|
||||
// a = await Util.GetAsync("DataFilter/" + DataFilterId.ToString(), await Util.GetTokenAsync("SubContractorLimited"));
|
||||
// Util.ValidateResponseNotFound(a);
|
||||
|
||||
// // //DELETE
|
||||
// ApiResponse DELETETestResponse = await Util.DeleteAsync("DataFilter/" + DataFilterId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
||||
// Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////
|
||||
//DECIMAL
|
||||
//
|
||||
|
||||
///////////////////////
|
||||
//TAGS
|
||||
//
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
Reference in New Issue
Block a user