278 lines
10 KiB
C#
278 lines
10 KiB
C#
using Xunit;
|
|
using Newtonsoft.Json.Linq;
|
|
using FluentAssertions;
|
|
|
|
namespace raven_integration
|
|
{
|
|
|
|
public class FormCustom
|
|
{
|
|
public enum AyaUiFieldDataType : int
|
|
{
|
|
NoType = 0,
|
|
DateTime = 1,
|
|
Date = 2,
|
|
Time = 3,
|
|
Text = 4,
|
|
Integer = 5,
|
|
Bool = 6,
|
|
Decimal = 7,
|
|
Currency = 8,
|
|
Tags = 9,
|
|
Enum = 10,
|
|
EmailAddress = 11
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test create or update
|
|
/// </summary>
|
|
[Fact]
|
|
public async Task 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 = "Vendor";
|
|
|
|
dynamic dtemplate = new JArray();
|
|
|
|
dynamic dt = new JObject();
|
|
dt.fld = "VendorCustom1";
|
|
dt.hide = false;
|
|
dt.required = true;
|
|
dt.type = AyaUiFieldDataType.Text;
|
|
dtemplate.Add(dt);
|
|
|
|
|
|
dt = new JObject();
|
|
dt.fld = "Notes";
|
|
dt.required = true;
|
|
dtemplate.Add(dt);
|
|
|
|
dt = new JObject();
|
|
dt.fld = "VendorCustom2";
|
|
dt.hide = true;
|
|
dt.required = false;
|
|
dt.type = AyaUiFieldDataType.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("form-custom/Vendor", await Util.GetTokenAsync("BizAdmin"));
|
|
|
|
//Update
|
|
d.concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
|
a = await Util.PutAsync("form-custom/Vendor", await Util.GetTokenAsync("BizAdmin"), d.ToString());
|
|
Util.ValidateHTTPStatusCode(a, 200);
|
|
|
|
//check the concurrency token cache scheme
|
|
uint token = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
|
//This should return a 304 not modified
|
|
a = await Util.GetAsync($"form-custom/Vendor?concurrency={token}", await Util.GetTokenAsync("BizAdmin"));
|
|
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($"form-custom/Vendor?concurrency={token}", await Util.GetTokenAsync("BizAdmin"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Ensure validation works in FormCustombiz
|
|
/// </summary>
|
|
[Fact]
|
|
public async Task ValidatesProperly()
|
|
{
|
|
|
|
dynamic d = new JObject();
|
|
d.formkey = "Vendor";
|
|
|
|
dynamic dtemplate = new JArray();
|
|
|
|
dynamic dt = new JObject();
|
|
dt.fld = string.Empty;//expected ApiErrorCode.VALIDATION_REQUIRED Missing key 2 errors 2201 and 2203
|
|
dt.hide = false;
|
|
dt.required = true;
|
|
dtemplate.Add(dt);
|
|
|
|
|
|
dt = new JObject();
|
|
dt.fld = "ThisFieldKeyDoesNotExist";//expected ApiErrorCode.VALIDATION_INVALID_VALUE Bad key
|
|
dt.required = true;
|
|
dtemplate.Add(dt);
|
|
|
|
dt = new JObject();
|
|
dt.fld = "Name";//expect ApiErrorCode.VALIDATION_INVALID_VALUE required field not hideable
|
|
dt.hide = true;
|
|
dt.required = true;
|
|
dtemplate.Add(dt);
|
|
|
|
dt = new JObject();
|
|
dt.fld = "VendorCustom1";//expected ApiErrorCode.VALIDATION_INVALID_VALUE type missing for custom field
|
|
dt.hide = false;
|
|
dt.required = false;
|
|
dtemplate.Add(dt);
|
|
|
|
dt = new JObject();
|
|
dt.fld = "AccountNumber";//expect ApiErrorCode.VALIDATION_INVALID_VALUE not custom field but type specified anyway
|
|
dt.hide = true;
|
|
dt.required = false;
|
|
dt.type = AyaUiFieldDataType.EmailAddress;//type specified (doesn't matter what type)
|
|
dtemplate.Add(dt);
|
|
|
|
dt = new JObject();
|
|
dt.fld = "VendorCustom2";//expected ApiErrorCode.VALIDATION_INVALID_VALUE type missing for custom field
|
|
dt.hide = false;
|
|
dt.required = false;
|
|
dtemplate.Add(dt);
|
|
dt.type = 999;//not a valid type
|
|
|
|
dt = new JObject();
|
|
dt.fld = "Notes";//expect ApiErrorCode.VALIDATION_REQUIRED required property is always required (no idea why, just designed that way and that's the rule)
|
|
dt.hide = true;
|
|
// dt.required = false; Deliberately not set
|
|
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("form-custom/Vendor", await Util.GetTokenAsync("BizAdmin"));
|
|
|
|
//Update
|
|
d.concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
|
a = await Util.PutAsync("form-custom/Vendor", await Util.GetTokenAsync("BizAdmin"), d.ToString());
|
|
Util.ValidateHTTPStatusCode(a, 400);
|
|
Util.ShouldContainValidationError(a, "Template", "2201", "Template array item 0, \"fld\" property exists but is empty, a value is required");
|
|
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 0, fld property value \"\" is not a valid form field value for formKey specified");
|
|
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 1, fld property value \"ThisFieldKeyDoesNotExist\" is not a valid form field value for formKey specified");
|
|
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 2, fld property value \"Name\" is not a valid form field value for formKey specified");
|
|
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 3 (\"VendorCustom1\"), \"type\" property value is MISSING for custom field, Custom fields MUST have types specified");
|
|
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 4 (\"AccountNumber\"), \"type\" property value is not valid, only Custom fields can have types specified");
|
|
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 5 (\"VendorCustom2\"), \"type\" property value of \"999\" is not a valid custom field type");
|
|
Util.ShouldContainValidationError(a, "Template", "2201", "Template array item 6, object is missing \"required\" property. All items must contain this property.");
|
|
|
|
/*
|
|
|
|
{{
|
|
"error": {
|
|
"code": "2200",
|
|
"details": [
|
|
{
|
|
"message": "Template array item 0, \"fld\" property exists but is empty, a value is required",
|
|
"target": "Template",
|
|
"error": "2201"
|
|
},
|
|
{
|
|
"message": "Template array item 0, fld property value \"\" is not a valid form field value for formKey specified",
|
|
"target": "Template",
|
|
"error": "2203"
|
|
},
|
|
{
|
|
"message": "Template array item 1, fld property value \"ThisFieldKeyDoesNotExist\" is not a valid form field value for formKey specified",
|
|
"target": "Template",
|
|
"error": "2203"
|
|
},
|
|
{
|
|
"message": "Template array item 2, fld property value \"Name\" is not a valid form field value for formKey specified",
|
|
"target": "Template",
|
|
"error": "2203"
|
|
},
|
|
{
|
|
"message": "Template array item 3 (\"VendorCustom1\"), \"type\" property value is MISSING for custom field, Custom fields MUST have types specified",
|
|
"target": "Template",
|
|
"error": "2203"
|
|
},
|
|
{
|
|
"message": "Template array item 4 (\"AccountNumber\"), \"type\" property value is not valid, only Custom fields can have types specified",
|
|
"target": "Template",
|
|
"error": "2203"
|
|
},
|
|
{
|
|
"message": "Template array item 5 (\"VendorCustom2\"), \"type\" property value of \"999\" is not a valid custom field type",
|
|
"target": "Template",
|
|
"error": "2203"
|
|
},
|
|
{
|
|
"message": "Template array item 6, object is missing \"required\" property. All items must contain this property. ",
|
|
"target": "Template",
|
|
"error": "2201"
|
|
}
|
|
],
|
|
"message": "ErrorAPI2200"
|
|
}
|
|
}}
|
|
*/
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Fact]
|
|
public async Task InvalidObjectFieldsFormKeyShouldFail()
|
|
{
|
|
ApiResponse a = await Util.GetAsync("form-field-reference/nonexistent", await Util.GetTokenAsync("BizAdmin"));
|
|
Util.ValidateHTTPStatusCode(a, 404);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Fact]
|
|
public async Task ObjectFieldsWorks()
|
|
{
|
|
ApiResponse a = await Util.GetAsync("form-field-reference/Vendor", await Util.GetTokenAsync("BizAdmin"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(25);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Fact]
|
|
public async Task AvailableCustomizableFormKeysWorks()
|
|
{
|
|
ApiResponse a = await Util.GetAsync("form-custom/availablecustomizableformkeys", await Util.GetTokenAsync("BizAdmin"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(1);//is 2 as of writing (widget,user)
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Fact]
|
|
public async Task AvailableCustomTypesWorks()
|
|
{
|
|
ApiResponse a = await Util.GetAsync("form-custom/availablecustomtypes", await Util.GetTokenAsync("BizAdmin"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(4);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//==================================================
|
|
|
|
}//eoc
|
|
}//eons
|