354 lines
8.5 KiB
JSON
354 lines
8.5 KiB
JSON
[
|
|
{
|
|
"description": "Multi-Paradigm Declarative Cases",
|
|
"database": {
|
|
"schemas": {
|
|
"parallel_rules": {
|
|
"type": "object",
|
|
"properties": {
|
|
"status": {
|
|
"type": "string"
|
|
},
|
|
"kind": {
|
|
"type": "string"
|
|
}
|
|
},
|
|
"cases": [
|
|
{
|
|
"when": {
|
|
"properties": {
|
|
"status": {
|
|
"const": "unverified"
|
|
}
|
|
},
|
|
"required": [
|
|
"status"
|
|
]
|
|
},
|
|
"then": {
|
|
"properties": {
|
|
"amount_1": {
|
|
"type": "number"
|
|
},
|
|
"amount_2": {
|
|
"type": "number"
|
|
}
|
|
},
|
|
"required": [
|
|
"amount_1",
|
|
"amount_2"
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"when": {
|
|
"properties": {
|
|
"kind": {
|
|
"const": "credit"
|
|
}
|
|
},
|
|
"required": [
|
|
"kind"
|
|
]
|
|
},
|
|
"then": {
|
|
"properties": {
|
|
"cvv": {
|
|
"type": "number"
|
|
}
|
|
},
|
|
"required": [
|
|
"cvv"
|
|
]
|
|
}
|
|
}
|
|
]
|
|
},
|
|
"mutually_exclusive": {
|
|
"type": "object",
|
|
"properties": {
|
|
"type": {
|
|
"type": "string"
|
|
}
|
|
},
|
|
"cases": [
|
|
{
|
|
"when": {
|
|
"properties": {
|
|
"type": {
|
|
"const": "A"
|
|
}
|
|
},
|
|
"required": [
|
|
"type"
|
|
]
|
|
},
|
|
"then": {
|
|
"properties": {
|
|
"field_a": {
|
|
"type": "number"
|
|
}
|
|
},
|
|
"required": [
|
|
"field_a"
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"when": {
|
|
"properties": {
|
|
"type": {
|
|
"const": "B"
|
|
}
|
|
},
|
|
"required": [
|
|
"type"
|
|
]
|
|
},
|
|
"then": {
|
|
"properties": {
|
|
"field_b": {
|
|
"type": "number"
|
|
}
|
|
},
|
|
"required": [
|
|
"field_b"
|
|
]
|
|
},
|
|
"else": {
|
|
"properties": {
|
|
"fallback_b": {
|
|
"type": "number"
|
|
}
|
|
},
|
|
"required": [
|
|
"fallback_b"
|
|
]
|
|
}
|
|
}
|
|
]
|
|
},
|
|
"nested_fallbacks": {
|
|
"type": "object",
|
|
"properties": {
|
|
"tier": {
|
|
"type": "string"
|
|
}
|
|
},
|
|
"cases": [
|
|
{
|
|
"when": {
|
|
"properties": {
|
|
"tier": {
|
|
"const": "1"
|
|
}
|
|
},
|
|
"required": [
|
|
"tier"
|
|
]
|
|
},
|
|
"then": {
|
|
"properties": {
|
|
"basic": {
|
|
"type": "number"
|
|
}
|
|
},
|
|
"required": [
|
|
"basic"
|
|
]
|
|
},
|
|
"else": {
|
|
"cases": [
|
|
{
|
|
"when": {
|
|
"properties": {
|
|
"tier": {
|
|
"const": "2"
|
|
}
|
|
},
|
|
"required": [
|
|
"tier"
|
|
]
|
|
},
|
|
"then": {
|
|
"properties": {
|
|
"standard": {
|
|
"type": "number"
|
|
}
|
|
},
|
|
"required": [
|
|
"standard"
|
|
]
|
|
},
|
|
"else": {
|
|
"properties": {
|
|
"premium": {
|
|
"type": "number"
|
|
}
|
|
},
|
|
"required": [
|
|
"premium"
|
|
]
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
]
|
|
},
|
|
"missing_when": {
|
|
"type": "object",
|
|
"cases": [
|
|
{
|
|
"else": {
|
|
"properties": {
|
|
"unconditional": {
|
|
"type": "number"
|
|
}
|
|
},
|
|
"required": [
|
|
"unconditional"
|
|
]
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
},
|
|
"tests": [
|
|
{
|
|
"description": "Fires only the first rule successfully",
|
|
"data": {
|
|
"status": "unverified",
|
|
"amount_1": 1,
|
|
"amount_2": 2
|
|
},
|
|
"schema_id": "parallel_rules",
|
|
"action": "validate",
|
|
"expect": {
|
|
"success": true
|
|
}
|
|
},
|
|
{
|
|
"description": "Fires both independent parallel rules flawlessly",
|
|
"data": {
|
|
"status": "unverified",
|
|
"kind": "credit",
|
|
"amount_1": 1,
|
|
"amount_2": 2,
|
|
"cvv": 123
|
|
},
|
|
"schema_id": "parallel_rules",
|
|
"action": "validate",
|
|
"expect": {
|
|
"success": true
|
|
}
|
|
},
|
|
{
|
|
"description": "Catches errors triggered concurrently by multiple independent blocked rules",
|
|
"data": {
|
|
"status": "unverified",
|
|
"kind": "credit"
|
|
},
|
|
"schema_id": "parallel_rules",
|
|
"action": "validate",
|
|
"expect": {
|
|
"success": false,
|
|
"errors": [
|
|
{
|
|
"code": "REQUIRED_FIELD_MISSING",
|
|
"details": {
|
|
"path": "amount_1"
|
|
}
|
|
},
|
|
{
|
|
"code": "REQUIRED_FIELD_MISSING",
|
|
"details": {
|
|
"path": "amount_2"
|
|
}
|
|
},
|
|
{
|
|
"code": "REQUIRED_FIELD_MISSING",
|
|
"details": {
|
|
"path": "cvv"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"description": "STRICT_PROPERTY_VIOLATION throws if an un-triggered then property is submitted",
|
|
"data": {
|
|
"status": "verified",
|
|
"cvv": 123
|
|
},
|
|
"schema_id": "parallel_rules",
|
|
"action": "validate",
|
|
"expect": {
|
|
"success": false,
|
|
"errors": [
|
|
{
|
|
"code": "STRICT_PROPERTY_VIOLATION",
|
|
"details": {
|
|
"path": "cvv"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"description": "Successfully routes mutually exclusive properties seamlessly",
|
|
"data": {
|
|
"type": "A",
|
|
"field_a": 1,
|
|
"fallback_b": 2
|
|
},
|
|
"schema_id": "mutually_exclusive",
|
|
"action": "validate",
|
|
"expect": {
|
|
"success": true
|
|
}
|
|
},
|
|
{
|
|
"description": "Nested fallbacks execute seamlessly",
|
|
"data": {
|
|
"tier": "3",
|
|
"premium": 1
|
|
},
|
|
"schema_id": "nested_fallbacks",
|
|
"action": "validate",
|
|
"expect": {
|
|
"success": true
|
|
}
|
|
},
|
|
{
|
|
"description": "A case without a when executes its else indiscriminately",
|
|
"data": {
|
|
"unconditional": 1
|
|
},
|
|
"schema_id": "missing_when",
|
|
"action": "validate",
|
|
"expect": {
|
|
"success": true
|
|
}
|
|
},
|
|
{
|
|
"description": "A case without a when throws if else unconditionally requires field",
|
|
"data": {},
|
|
"schema_id": "missing_when",
|
|
"action": "validate",
|
|
"expect": {
|
|
"success": false,
|
|
"errors": [
|
|
{
|
|
"code": "REQUIRED_FIELD_MISSING",
|
|
"details": {
|
|
"path": "unconditional"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
]
|
|
}
|
|
] |