test: add property type validation tests#5
test: add property type validation tests#5Shubh-Raj wants to merge 1 commit intoaccordproject:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds unit tests to improve test coverage for property type validation in the Concerto validator. The tests validate metamodel definitions with different property configurations including boolean type checking, integer properties, array properties, and optional properties.
Changes:
- Added 4 new unit tests for property type validation scenarios
- Tests cover boolean type mismatch, integer property definitions, array properties, and optional properties
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| fn test_valid_integer_property_definition() { | ||
| // Test that a valid IntegerProperty definition passes validation | ||
| let model_with_integer_property = r#"{ | ||
| "$class": "[email protected]", | ||
| "namespace": "[email protected]", | ||
| "imports": [], | ||
| "declarations": [ | ||
| { | ||
| "$class": "[email protected]", | ||
| "name": "TestConcept", | ||
| "isAbstract": false, | ||
| "properties": [ | ||
| { | ||
| "$class": "[email protected]", | ||
| "name": "count", | ||
| "isArray": false, | ||
| "isOptional": false | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| }"#; | ||
|
|
||
| let result = validate_metamodel(model_with_integer_property); | ||
| assert!( | ||
| result.is_ok(), | ||
| "Valid IntegerProperty definition should pass: {:?}", | ||
| result | ||
| ); | ||
| } |
There was a problem hiding this comment.
This test validates that a valid IntegerProperty definition passes validation, but according to issue #4, the proposed test was test_integer_property_type_mismatch which should fail when a string is passed where an integer is expected. This test doesn't verify the type validation logic of the validate_integer_property function mentioned in the issue (lines 222-228 in model_manager/mod.rs). Consider adding a test that validates type mismatch behavior, for example, by including a property with an IntegerProperty type but providing a string value.
| fn test_array_property_validation() { | ||
| // Test that isArray: true properties are correctly defined | ||
| let model_with_array = r#"{ | ||
| "$class": "[email protected]", | ||
| "namespace": "[email protected]", | ||
| "imports": [], | ||
| "declarations": [ | ||
| { | ||
| "$class": "[email protected]", | ||
| "name": "TestConcept", | ||
| "isAbstract": false, | ||
| "properties": [ | ||
| { | ||
| "$class": "[email protected]", | ||
| "name": "tags", | ||
| "isArray": true, | ||
| "isOptional": false | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| }"#; | ||
|
|
||
| let result = validate_metamodel(model_with_array); | ||
| assert!( | ||
| result.is_ok(), | ||
| "Array property definition should pass validation: {:?}", | ||
| result | ||
| ); | ||
| } |
There was a problem hiding this comment.
This test validates that a property with isArray: true is correctly defined, but according to issue #4, the proposed test was test_array_property_expects_array which should fail when a non-array is passed for an isArray: true property. This doesn't test the array validation logic in validate_property_structure (lines 122-146 in model_manager/mod.rs). Consider adding a test that provides a non-array value (e.g., a single string) for a property defined with isArray: true to verify that validation properly rejects such input.
| fn test_optional_property_validation() { | ||
| // Test that isOptional: true properties are correctly defined | ||
| let model_with_optional = r#"{ | ||
| "$class": "[email protected]", | ||
| "namespace": "[email protected]", | ||
| "imports": [], | ||
| "declarations": [ | ||
| { | ||
| "$class": "[email protected]", | ||
| "name": "TestConcept", | ||
| "isAbstract": false, | ||
| "properties": [ | ||
| { | ||
| "$class": "[email protected]", | ||
| "name": "nickname", | ||
| "isArray": false, | ||
| "isOptional": true | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| }"#; | ||
|
|
||
| let result = validate_metamodel(model_with_optional); | ||
| assert!( | ||
| result.is_ok(), | ||
| "Optional property definition should pass validation: {:?}", | ||
| result | ||
| ); | ||
| } |
There was a problem hiding this comment.
This test validates that a property with isOptional: true is correctly defined, but according to issue #4, the proposed test was test_optional_property_can_be_missing which should verify that optional properties do not cause validation failure when absent. This doesn't test the optional property handling logic in validate_required_properties (lines 96-112 in model_manager/mod.rs). Consider adding a test that omits an optional property from the data to verify that the validation correctly allows missing optional properties.
|
I am working on the copilot suggestions. |
9415772 to
20ebad7
Compare
- test_boolean_property_type_mismatch: fails when string passed where boolean expected - test_integer_property_type_mismatch: fails when string passed for boolean field in IntegerProperty - test_array_property_expects_array: fails when non-array passed for array property - test_optional_property_can_be_missing: passes when optional superType is omitted Fixes accordproject#4 Signed-off-by: Shubh-Raj <[email protected]>
20ebad7 to
5479791
Compare
Fixes #4
Description
Adds unit tests for property type validation to improve test coverage.
Tests Added
test_boolean_property_type_mismatch- Verifies validation fails when string passed where boolean expectedtest_valid_integer_property_definition- Verifies IntegerProperty definitions are correctly validatedtest_array_property_validation- Verifies properties withisArray: trueare correctly validatedtest_optional_property_validation- Verifies properties withisOptional: trueare correctly validated