181 lines
6.8 KiB
C#
181 lines
6.8 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 FormCustom
|
|
{
|
|
|
|
/// <summary>
|
|
/// Test create or update
|
|
/// </summary>
|
|
[Fact]
|
|
public async void FormCustomUpdate()
|
|
{
|
|
|
|
//This is a special case, you can PUT a formcustom, but you can't delete one and you can't create one
|
|
|
|
|
|
dynamic d = new JObject();
|
|
d.formkey = "user";
|
|
|
|
/*
|
|
|
|
|
|
As sending from client now with fail:
|
|
{
|
|
"formKey":"widget",
|
|
"concurrencyToken":3798757,
|
|
"template":[
|
|
{"fld":"WidgetName","required":true,"hide":false},{"fld":"WidgetStartDate","required":true,"hide":false},{"fld":"WidgetEndDate","required":true,"hide":false},{"fld":"WidgetNotes","required":true,"hide":false},{"fld":"WidgetCustom1","required":false,"type":"datetime"},{"fld":"WidgetCustom2","required":true,"type":"text"},{"fld":"WidgetCustom3","required":false,"type":"number"},{"fld":"WidgetCustom4","required":false,"type":"bool"},{"fld":"WidgetCustom5","required":false,"type":"currency"},{"fld":"WidgetCustom6","required":false,"type":"date"},{"fld":"WidgetCustom7","required":false,"type":"time"}
|
|
]
|
|
}
|
|
|
|
//As it appears in this unit test to string
|
|
"{\r\n \"formkey\": \"user\",\r\n \"template\": \"[\\r\\n {\\r\\n \\\"fld\\\": \\\"UserCustom1\\\",\\r\\n \\\"hide\\\": false,\\r\\n \\\"required\\\": true,\\r\\n \\\"type\\\": \\\"text\\\"\\r\\n },
|
|
\\r\\n {\\r\\n \\\"fld\\\": \\\"UserNotes\\\",\\r\\n \\\"required\\\": true\\r\\n },\\r\\n
|
|
{\\r\\n \\\"fld\\\": \\\"UserCustom2\\\",\\r\\n \\\"hide\\\": true,\\r\\n \\\"required\\\": false,\\r\\n \\\"type\\\": \\\"bool\\\"\\r\\n }\\r\\n]\",
|
|
\r\n \"concurrencyToken\": 3802346\r\n}"
|
|
|
|
//cleaned up unit test string from immediately above here
|
|
"{"formkey":"user","template":"[{"fld":"UserCustom1","hide":false,"required":true,"type":"text"},
|
|
{"fld":"UserNotes","required":true},
|
|
{"fld":"UserCustom2","hide":true,"required":false,"type":"bool"}]",
|
|
"concurrencyToken":3802346}"
|
|
|
|
|
|
//As it fetches off the server now
|
|
{
|
|
"data": {
|
|
"id": 1,
|
|
"concurrencyToken": 3798757,
|
|
"formKey": "widget",
|
|
"template": "[{\"fld\":\"WidgetNotes\",\"required\":true},{\"fld\":\"WidgetCustom1\",\"required\":false,\"type\":\"datetime\"},{\"fld\":\"WidgetCustom2\",\"required\":true,\"type\":\"text\"},
|
|
{\"fld\":\"WidgetCustom3\",\"required\":false,\"type\":\"number\"},{\"fld\":\"WidgetCustom4\",\"required\":false,\"type\":\"bool\"},{\"fld\":\"WidgetCustom5\",\"required\":false,\"type\":\"currency\"},
|
|
{\"fld\":\"WidgetCustom6\",\"required\":false,\"type\":\"date\"},{\"fld\":\"WidgetCustom7\",\"required\":false,\"type\":\"time\"}]"
|
|
}
|
|
}
|
|
|
|
OK, it appears the quotes need to be escaped for some reason?, this works:
|
|
{"concurrencyToken": 3802346,
|
|
"formKey": "user",
|
|
"template": "[{\"fld\":\"UserCustom1\",\"hide\":false,\"required\":true,\"type\":\"text\"},{\"fld\":\"UserNotes\",\"required\":true},{\"fld\":\"UserCustom2\",\"hide\":true,\"required\":false,\"type\":\"bool\"}]"}
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
dynamic dtemplate = new JArray();
|
|
|
|
dynamic dt = new JObject();
|
|
dt.fld = "UserCustom1";
|
|
dt.hide = false;
|
|
dt.required = true;
|
|
dt.type = "text";
|
|
dtemplate.Add(dt);
|
|
|
|
|
|
dt = new JObject();
|
|
dt.fld = "UserNotes";
|
|
dt.required = true;
|
|
dtemplate.Add(dt);
|
|
|
|
dt = new JObject();
|
|
dt.fld = "UserCustom2";
|
|
dt.hide = true;
|
|
dt.required = false;
|
|
dt.type = "bool";
|
|
dtemplate.Add(dt);
|
|
|
|
d.template = dtemplate.ToString();//it expects it to be a json string, not actual json
|
|
|
|
|
|
//RETRIEVE
|
|
//Get the current one (server will create if non-existent)
|
|
ApiResponse a = await Util.GetAsync("FormCustom/user", await Util.GetTokenAsync("BizAdminFull"));
|
|
|
|
//Update
|
|
d.concurrencyToken = a.ObjectResponse["data"]["concurrencyToken"].Value<uint>();
|
|
a = await Util.PutAsync("FormCustom/user", await Util.GetTokenAsync("BizAdminFull"), d.ToString());
|
|
Util.ValidateHTTPStatusCode(a, 200);
|
|
|
|
//check the concurrency token cache scheme
|
|
uint token = a.ObjectResponse["data"]["concurrencyToken"].Value<uint>();
|
|
//This should return a 304 not modified
|
|
a = await Util.GetAsync($"FormCustom/user?concurrencyToken={token}", await Util.GetTokenAsync("BizAdminFull"));
|
|
Util.ValidateHTTPStatusCode(a, 304);
|
|
|
|
//and this should return the whole object
|
|
token--;//make the token not match
|
|
//This should return a 200 and the whole object
|
|
a = await Util.GetAsync($"FormCustom/user?concurrencyToken={token}", await Util.GetTokenAsync("BizAdminFull"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Fact]
|
|
public async void InvalidAvailableFieldsFormKeyShouldFail()
|
|
{
|
|
ApiResponse a = await Util.GetAsync("FormCustom/AvailableFields/nonexistent", await Util.GetTokenAsync("BizAdminFull"));
|
|
Util.ValidateErrorCodeResponse(a, 2010, 404);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Fact]
|
|
public async void AvailableFieldsWorks()
|
|
{
|
|
ApiResponse a = await Util.GetAsync("FormCustom/AvailableFields/widget", await Util.GetTokenAsync("BizAdminFull"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(25);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Fact]
|
|
public async void AvailableCustomizableFormKeysWorks()
|
|
{
|
|
ApiResponse a = await Util.GetAsync("FormCustom/AvailableCustomizableFormKeys", await Util.GetTokenAsync("BizAdminFull"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(1);//is 2 as of writing (widget,user)
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Fact]
|
|
public async void AvailableCustomTypesWorks()
|
|
{
|
|
ApiResponse a = await Util.GetAsync("FormCustom/AvailableCustomTypes", await Util.GetTokenAsync("BizAdminFull"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(4);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//==================================================
|
|
|
|
}//eoc
|
|
}//eons
|