242 lines
10 KiB
C#
242 lines
10 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
|
|
{
|
|
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 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";
|
|
|
|
dynamic dtemplate = new JArray();
|
|
|
|
dynamic dt = new JObject();
|
|
dt.fld = "UserCustom1";
|
|
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 = "UserCustom2";
|
|
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("FormCustom/User", await Util.GetTokenAsync("BizAdminFull"));
|
|
|
|
//Update
|
|
d.concurrency = a.ObjectResponse["data"]["concurrency"].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"]["concurrency"].Value<uint>();
|
|
//This should return a 304 not modified
|
|
a = await Util.GetAsync($"FormCustom/User?concurrency={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?concurrency={token}", await Util.GetTokenAsync("BizAdminFull"));
|
|
Util.ValidateDataReturnResponseOk(a);
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Ensure validation works in FormCustombiz
|
|
/// </summary>
|
|
[Fact]
|
|
public async void ValidatesProperly()
|
|
{
|
|
|
|
dynamic d = new JObject();
|
|
d.formkey = "User";
|
|
|
|
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 = "UserCustom1";//expected ApiErrorCode.VALIDATION_INVALID_VALUE type missing for custom field
|
|
dt.hide = false;
|
|
dt.required = false;
|
|
dtemplate.Add(dt);
|
|
|
|
dt = new JObject();
|
|
dt.fld = "EmployeeNumber";//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 = "UserCustom2";//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("FormCustom/User", await Util.GetTokenAsync("BizAdminFull"));
|
|
|
|
//Update
|
|
d.concurrency = a.ObjectResponse["data"]["concurrency"].Value<uint>();
|
|
a = await Util.PutAsync("FormCustom/User", await Util.GetTokenAsync("BizAdminFull"), 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 (\"Name\"), \"hide\" property value of \"True\" is not valid, this field is core and cannot be hidden");
|
|
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 3 (\"UserCustom1\"), \"type\" property value is MISSING for custom field, Custom fields MUST have types specified");
|
|
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 4 (\"EmployeeNumber\"), \"type\" property value is not valid, only Custom fields can have types specified");
|
|
Util.ShouldContainValidationError(a, "Template", "2203", "Template array item 5 (\"UserCustom2\"), \"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 (\\\"Name\\\"), \\\"hide\\\" property value of \\\"True\\\" is not valid, this field is core and cannot be hidden\",\"target\":\"Template\",\"error\":\"2203\"},
|
|
{\"message\":\"Template array item 3 (\\\"UserCustom1\\\"), \\\"type\\\" property value is MISSING for custom filed, Custom fields MUST have types specified\",\"target\":\"Template\",\"error\":\"2203\"},
|
|
{\"message\":\"Template array item 4 (\\\"EmployeeNumber\\\"), \\\"type\\\" property value is not valid, only Custom fields can have types specified\",\"target\":\"Template\",\"error\":\"2203\"},
|
|
{\"message\":\"Template array item 5 (\\\"UserCustom2\\\"), \\\"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\":\"Object did not pass validation\"}}"
|
|
*/
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Fact]
|
|
public async void InvalidObjectFieldsFormKeyShouldFail()
|
|
{
|
|
ApiResponse a = await Util.GetAsync("FormFieldsDefinitions/nonexistent", await Util.GetTokenAsync("BizAdminFull"));
|
|
Util.ValidateErrorCodeResponse(a, 2010, 404);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Fact]
|
|
public async void ObjectFieldsWorks()
|
|
{
|
|
ApiResponse a = await Util.GetAsync("FormFieldsDefinitions/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
|