450 lines
21 KiB
C#
450 lines
21 KiB
C#
using System;
|
|
using Xunit;
|
|
using Newtonsoft.Json.Linq;
|
|
using FluentAssertions;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Concurrent;
|
|
|
|
namespace raven_integration
|
|
{
|
|
public class PickListAllTests
|
|
{
|
|
//NOTE: in order not to interfere in each other will use Widget picklist to test with standard unmodified picklist template
|
|
//and will use User PickList to test the template functionality
|
|
|
|
/// <summary>
|
|
/// Test all Template editing related routes
|
|
/// </summary>
|
|
[Fact]
|
|
public async void UserPickListTemplatesOps()
|
|
{
|
|
//NOTE: Due to there being only one possible template per type, this test will need to test ALL potential tests in one function
|
|
//and only for the User picklist in order to not step over other potential tests running in parallel
|
|
|
|
//REPLACE USER TEMPLATE
|
|
dynamic d = new JObject();
|
|
d.Id = 3;//User type
|
|
|
|
//custom template, only one field employee number
|
|
dynamic dTemplateArray = new JArray();
|
|
dynamic df = new JObject();
|
|
df.fld = "useremployeenumber";
|
|
dTemplateArray.Add(df);
|
|
d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
|
|
|
|
//replace the User template at the server
|
|
ApiResponse a = await Util.PostAsync("PickList/Template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
|
Util.ValidateHTTPStatusCode(a, 204);
|
|
|
|
|
|
//RETRIEVE
|
|
//Get one
|
|
a = await Util.GetAsync("PickList/Template/3/", await Util.GetTokenAsync("BizAdminFull"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
//assert contains ONE record ONLY and it's the one we set
|
|
var templateArray = JArray.Parse(a.ObjectResponse["data"]["template"].Value<string>());
|
|
templateArray.Count.Should().Be(1);
|
|
templateArray[0]["fld"].Value<string>().Should().Be("useremployeenumber");
|
|
|
|
|
|
//CONFIRM THE CUSTOM PICKLIST TEMPLATE WORKS PROPERLY
|
|
//MAKE THE TEST USERS
|
|
//First make a unique string for this iteration of this test only
|
|
var UniquePhrase = Util.Uniquify("pick").Replace(" ", "");
|
|
d = new JObject();
|
|
d.name = Util.Uniquify("UserPickListTemplatesOps") + UniquePhrase;
|
|
d.active = true;
|
|
d.login = Util.Uniquify("LOGIN");
|
|
d.password = Util.Uniquify("PASSWORD");
|
|
d.roles = 0;//norole
|
|
|
|
d.userType = 3;//non scheduleable
|
|
//Required by form custom rules
|
|
d.notes = "notes";
|
|
d.customFields = Util.UserRequiredCustomFieldsJsonString();
|
|
|
|
a = await Util.PostAsync("User", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
long InNameId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
d = new JObject();
|
|
d.name = Util.Uniquify("UserPickListTemplatesOps");
|
|
d.employeeNumber = UniquePhrase;
|
|
d.login = Util.Uniquify("LOGIN");
|
|
d.password = Util.Uniquify("PASSWORD");
|
|
d.roles = 0;//norole
|
|
d.userType = 3;//non scheduleable
|
|
d.active = true;
|
|
//Required by form custom rules
|
|
d.notes = "notes";
|
|
d.customFields = Util.UserRequiredCustomFieldsJsonString();
|
|
|
|
a = await Util.PostAsync("User", await Util.GetTokenAsync("manager", "l3tm3in"), d.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
long InEmployeeNumberId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
|
|
//GET PICKLIST FOR unique phrase query sb only employee number due to custom template
|
|
a = await Util.GetAsync("PickList/List?ayaType=3&query=" + UniquePhrase, await Util.GetTokenAsync("BizAdminFull"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
var pickList = ((JArray)a.ObjectResponse["data"]);
|
|
pickList.Count.Should().Be(1);
|
|
pickList[0]["id"].Value<long>().Should().Be(InEmployeeNumberId);
|
|
|
|
//custom template, only one field user name
|
|
d = new JObject();
|
|
d.Id = 3;//User type
|
|
dTemplateArray = new JArray();
|
|
df = new JObject();
|
|
df.fld = "username";
|
|
dTemplateArray.Add(df);
|
|
d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
|
|
|
|
//replace the User template at the server
|
|
a = await Util.PostAsync("PickList/Template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
|
Util.ValidateHTTPStatusCode(a, 204);
|
|
|
|
//GET PICKLIST FOR unique phrase query sb only user name field due to custom template
|
|
a = await Util.GetAsync("PickList/List?ayaType=3&query=" + UniquePhrase, await Util.GetTokenAsync("BizAdminFull"));
|
|
//"select auser.id as plId, auser.active as plActive, concat_ws(' ', auser.name) as plname from auser where auser.active = true and ((auser.name like '%pick1584556347748%')) order by auser.name limit 100"
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
pickList = ((JArray)a.ObjectResponse["data"]);
|
|
pickList.Count.Should().Be(1);
|
|
pickList[0]["id"].Value<long>().Should().Be(InNameId);
|
|
|
|
//DELETE TEST USERS NO LONGER NEEDED
|
|
a = await Util.DeleteAsync("User/" + InNameId.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
|
Util.ValidateHTTPStatusCode(a, 204);
|
|
|
|
a = await Util.DeleteAsync("User/" + InEmployeeNumberId.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
|
Util.ValidateHTTPStatusCode(a, 204);
|
|
|
|
|
|
// RESET TEMPLATE TO DEFAULT
|
|
a = await Util.DeleteAsync("PickList/Template/3/", await Util.GetTokenAsync("BizAdminFull"));
|
|
Util.ValidateHTTPStatusCode(a, 204);
|
|
|
|
//RETRIEVE (Confirm it's back to default)
|
|
//Get one
|
|
a = await Util.GetAsync("PickList/Template/3/", await Util.GetTokenAsync("BizAdminFull"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
//assert contains default template record ONLY and it's the one we set
|
|
templateArray = JArray.Parse(a.ObjectResponse["data"]["template"].Value<string>());
|
|
templateArray.Count.Should().Be(3);
|
|
templateArray[0]["fld"].Value<string>().Should().Be("username");
|
|
|
|
|
|
//Now test error conditions....
|
|
//BAD FIELD NAME VALIDATION ERROR
|
|
d = new JObject();
|
|
d.Id = 3;//User type
|
|
//template, simple test, nothing fancy
|
|
dTemplateArray = new JArray();
|
|
df = new JObject();
|
|
df.fld = "DOES_NOT_EXIST";//<-- ERROR BAD FIELD NAME
|
|
dTemplateArray.Add(df);
|
|
d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
|
|
a = await Util.PostAsync("PickList/Template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
|
//"{\"error\":{\"code\":\"2200\",\"details\":[{\"message\":\"Template array item 0, fld property value \\\"DOES_NOT_EXIST\\\" is not a valid value for AyaType specified\",\"target\":\"Template\",\"error\":\"2203\"}],\"message\":\"Object did not pass validation\"}}"
|
|
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
|
Util.ShouldContainValidationError(a, "Template", "2203");
|
|
|
|
//BAD AYATYPE ERROR
|
|
d = new JObject();
|
|
d.Id = 0;//<==ERROR NO_TYPE, INVALID
|
|
//template, simple test, nothing fancy
|
|
dTemplateArray = new JArray();
|
|
df = new JObject();
|
|
df.fld = "useremployeenumber";
|
|
dTemplateArray.Add(df);
|
|
d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
|
|
//replace the User template at the server
|
|
a = await Util.PostAsync("PickList/Template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
|
//"{\"error\":{\"code\":\"2200\",\"details\":[{\"message\":\"Template array item 0, fld property value \\\"DOES_NOT_EXIST\\\" is not a valid value for AyaType specified\",\"target\":\"Template\",\"error\":\"2203\"}],\"message\":\"Object did not pass validation\"}}"
|
|
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
|
Util.ShouldContainValidationError(a, "ayaType", "2203");
|
|
|
|
//RIGHTS ISSUE,
|
|
//currently only bizadminfull can change a picklist template
|
|
d = new JObject();
|
|
d.Id = 3;//User
|
|
//template, simple test, nothing fancy
|
|
dTemplateArray = new JArray();
|
|
df = new JObject();
|
|
df.fld = "useremployeenumber";
|
|
dTemplateArray.Add(df);
|
|
d.Template = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
|
|
//ERROR NO RIGHTS USER
|
|
a = await Util.PostAsync("PickList/Template", await Util.GetTokenAsync("CustomerLimited"), d.ToString(Newtonsoft.Json.Formatting.None));
|
|
//"{\"error\":{\"code\":\"2004\",\"message\":\"User not authorized for this resource operation (insufficient rights)\"}}"
|
|
Util.ValidateErrorCodeResponse(a, 2004, 403);
|
|
|
|
//EMPTY TEMPLATE VALIDATION ERROR
|
|
d = new JObject();
|
|
d.Id = 3;//User
|
|
d.Template = "";//<-- ERROR no template
|
|
a = await Util.PostAsync("PickList/Template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
|
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
|
Util.ShouldContainValidationError(a, "Template", "2201");
|
|
|
|
|
|
//MALFORMED TEMPLATE JSON ERROR
|
|
d = new JObject();
|
|
d.Id = 3;//User type
|
|
dTemplateArray = new JArray();
|
|
df = new JObject();
|
|
df.fld = "useremployeenumber";
|
|
dTemplateArray.Add(df);
|
|
string sTemplate = dTemplateArray.ToString(Newtonsoft.Json.Formatting.None);
|
|
d.Template = sTemplate.Substring(2);//<-- ERROR missing first two characters of json template array
|
|
a = await Util.PostAsync("PickList/Template", await Util.GetTokenAsync("BizAdminFull"), d.ToString(Newtonsoft.Json.Formatting.None));
|
|
//"{\"error\":{\"code\":\"2200\",\"details\":[{\"message\":\"Template is not valid JSON string: Error reading JArray from JsonReader. Current JsonReader item is not an array: String. Path '', line 1, position 5.\",\"target\":\"Template\",\"error\":\"2203\"}],\"message\":\"Object did not pass validation\"}}"
|
|
Util.ValidateErrorCodeResponse(a, 2200, 400);
|
|
Util.ShouldContainValidationError(a, "Template", "2203");
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// test get templates list
|
|
/// </summary>
|
|
[Fact]
|
|
public async void PickListTemplateList()
|
|
{
|
|
//RETRIEVE
|
|
ApiResponse a = await Util.GetAsync("PickList/TemplateList", await Util.GetTokenAsync("BizAdminFull"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
//assert contains at least two records (as we only have two at time of writing this test)
|
|
var templateList = ((JArray)a.ObjectResponse["data"]);
|
|
templateList.Count.Should().BeGreaterThan(1);
|
|
templateList[0]["id"].Value<long>().Should().Be(2);//first one should be a widget
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// test get picklist fields list for widget template
|
|
/// </summary>
|
|
[Fact]
|
|
public async void WidgetPickListTemplateFieldList()
|
|
{
|
|
//RETRIEVE WIDGET PICKLIST FIELDS
|
|
ApiResponse a = await Util.GetAsync("PickList/Template/ListFields/2", await Util.GetTokenAsync("BizAdminFull"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
//assert contains at least two records (as we only have two at time of writing this test)
|
|
var templateList = ((JArray)a.ObjectResponse["data"]);
|
|
templateList.Count.Should().BeGreaterThan(4);
|
|
templateList[0]["fieldKey"].Value<string>().Should().Be("widgetactive");//first one should be a widgetactive field
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// test get picklist for widget without query
|
|
/// </summary>
|
|
[Fact]
|
|
public async void FetchWidgetPickListNoQuery()
|
|
{
|
|
//RETRIEVE WIDGET PICKLIST no filter
|
|
ApiResponse a = await Util.GetAsync("PickList/List?ayaType=2", await Util.GetTokenAsync("BizAdminFull"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
//assert contains 100 records (current picklist maximum count)
|
|
var pickList = ((JArray)a.ObjectResponse["data"]);
|
|
pickList.Count.Should().Be(100);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// test get picklist for widget with basic autocomplete query only
|
|
/// </summary>
|
|
[Fact]
|
|
public async void FetchWidgetPickListAutoComplete()
|
|
{
|
|
|
|
//make key widget
|
|
|
|
var WidgetNameStart = "FetchWidgetPickListAutoComplete_UnIqUe";
|
|
long IncludedWidgetId = 0;
|
|
//CREATE TEST WIDGETS
|
|
//included widget
|
|
dynamic w = new JObject();
|
|
w.name = Util.Uniquify(WidgetNameStart);
|
|
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
|
w.notes = "blah";
|
|
w.active = true;
|
|
w.usertype = 1;
|
|
w.dollarAmount = 555.55;
|
|
|
|
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
IncludedWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
|
|
//RETRIEVE WIDGET PICKLIST with name filter
|
|
a = await Util.GetAsync("PickList/List?ayaType=2&query=IqU", await Util.GetTokenAsync("BizAdminFull"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
var pickList = ((JArray)a.ObjectResponse["data"]);
|
|
pickList.Count.Should().Be(1);
|
|
pickList[0]["id"].Value<long>().Should().Be(IncludedWidgetId);
|
|
|
|
//DELETE WIDGETS
|
|
a = await Util.DeleteAsync("Widget/" + IncludedWidgetId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
|
Util.ValidateHTTPStatusCode(a, 204);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Fact]
|
|
public async void FetchWidgetPickListTags()
|
|
{
|
|
|
|
//make key widget
|
|
var WidgetNameStart = "FetchWidgetPickListTags";
|
|
long IncludedWidgetId = 0;
|
|
//CREATE TEST WIDGETS
|
|
//included widget
|
|
dynamic w = new JObject();
|
|
w.name = Util.Uniquify(WidgetNameStart);
|
|
w.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
|
w.notes = "blah";
|
|
w.active = true;
|
|
w.usertype = 1;
|
|
w.dollarAmount = 555.55;
|
|
//Tags
|
|
dynamic InclusiveTagsArray = new JArray();
|
|
InclusiveTagsArray.Add("plred");
|
|
InclusiveTagsArray.Add("plblue");
|
|
w.tags = InclusiveTagsArray;
|
|
|
|
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString());
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
IncludedWidgetId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
|
|
|
|
//RETRIEVE WIDGET PICKLIST with name filter
|
|
a = await Util.GetAsync("PickList/List?ayaType=2&query=..lblu", await Util.GetTokenAsync("BizAdminFull"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
|
|
var pickList = ((JArray)a.ObjectResponse["data"]);
|
|
pickList.Count.Should().Be(1);
|
|
pickList[0]["id"].Value<long>().Should().Be(IncludedWidgetId);
|
|
|
|
//DELETE WIDGETS
|
|
a = await Util.DeleteAsync("Widget/" + IncludedWidgetId.ToString(), await Util.GetTokenAsync("BizAdminFull"));
|
|
Util.ValidateHTTPStatusCode(a, 204);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// test get picklist for widget with basic autocomplete query only
|
|
/// </summary>
|
|
[Fact]
|
|
public async void FetchWidgetPickListInactiveActive()
|
|
{
|
|
|
|
//make key widget
|
|
|
|
var WidgetNameStart = "FetchWidgetPickListInactiveActive";
|
|
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.customFields = Util.WidgetRequiredCustomFieldsJsonString();
|
|
w.notes = "blah";
|
|
w.active = true;
|
|
w.usertype = 1;
|
|
|
|
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>());
|
|
|
|
|
|
//CONFIRM BOTH INACTIVE AND ACTIVE
|
|
a = await Util.GetAsync("PickList/List?ayaType=2&query=ickListInactiveAct&inactive=true", await Util.GetTokenAsync("BizAdminFull"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
var pickList = ((JArray)a.ObjectResponse["data"]);
|
|
//assert contains at least two records
|
|
pickList.Count.Should().BeGreaterThan(1);
|
|
int nActiveMatches = 0;
|
|
int nInactiveMatches = 0;
|
|
foreach (JObject o in pickList)
|
|
{
|
|
if (ActiveWidgetIdList.Contains(o["id"].Value<long>()))
|
|
nActiveMatches++;
|
|
if (NotActiveWidgetIdList.Contains(o["id"].Value<long>()))
|
|
nInactiveMatches++;
|
|
}
|
|
nActiveMatches.Should().Be(ActiveWidgetIdList.Count);
|
|
nInactiveMatches.Should().Be(NotActiveWidgetIdList.Count);
|
|
|
|
|
|
//CONFIRM ACTIVE ONLY
|
|
a = await Util.GetAsync("PickList/List?ayaType=2&query=ickListInactiveAct", await Util.GetTokenAsync("BizAdminFull"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
pickList = ((JArray)a.ObjectResponse["data"]);
|
|
//assert contains at least two records
|
|
pickList.Count.Should().BeGreaterThan(1);
|
|
nActiveMatches = 0;
|
|
nInactiveMatches = 0;
|
|
foreach (JObject o in pickList)
|
|
{
|
|
if (ActiveWidgetIdList.Contains(o["id"].Value<long>()))
|
|
nActiveMatches++;
|
|
if (NotActiveWidgetIdList.Contains(o["id"].Value<long>()))
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//==================================================
|
|
|
|
}//eoc
|
|
}//eons
|