diff --git a/FormCustom/FormCustom.cs b/FormCustom/FormCustom.cs index a37c9fc..96e27ee 100644 --- a/FormCustom/FormCustom.cs +++ b/FormCustom/FormCustom.cs @@ -9,22 +9,23 @@ namespace raven_integration { public class FormCustom - { - public enum AyaDataType : int { - NoType = 0, - DateTime = 1, - Date = 2, - Time = 3, - Text = 4, - Integer = 5, - Bool = 6, - Decimal = 7, - Currency = 8, - Tags = 9, - Enum = 10 + 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 - } + } /// /// Test create or update @@ -34,9 +35,9 @@ namespace raven_integration { //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"; @@ -47,12 +48,12 @@ namespace raven_integration dt.fld = "UserCustom1"; dt.hide = false; dt.required = true; - dt.type = AyaDataType.Text; + dt.type = AyaUiFieldDataType.Text; dtemplate.Add(dt); dt = new JObject(); - dt.fld = "UserNotes"; + dt.fld = "Notes"; dt.required = true; dtemplate.Add(dt); @@ -60,7 +61,7 @@ namespace raven_integration dt.fld = "UserCustom2"; dt.hide = true; dt.required = false; - dt.type = AyaDataType.Bool; + dt.type = AyaUiFieldDataType.Bool; dtemplate.Add(dt); d.template = dtemplate.ToString();//it expects it to be a json string, not actual json @@ -91,6 +92,97 @@ namespace raven_integration + /// + /// Ensure validation works in FormCustombiz + /// + [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.concurrencyToken = a.ObjectResponse["data"]["concurrencyToken"].Value(); + 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\"}}" + */ + } + + /// /// /// diff --git a/util.cs b/util.cs index 4950bf3..9a02213 100644 --- a/util.cs +++ b/util.cs @@ -411,15 +411,15 @@ namespace raven_integration /// /// /// - public static void ShouldContainValidationError(ApiResponse a, string target, string error, string message = null) + public static void ShouldContainValidationError(ApiResponse a, string target, string error, string shouldContainInMessage = null) { a.ObjectResponse["error"]["details"].Should().NotBeNull("There should be Details on the api call"); - if (message != null) + if (shouldContainInMessage != null) { a.ObjectResponse["error"]["details"].Should().Contain( m => m["target"].Value() == target && m["error"].Value() == error && - m["message"].Value() == message); + m["message"].Value().Contains(shouldContainInMessage)); } else {