82 lines
2.2 KiB
Rego
82 lines
2.2 KiB
Rego
|
|
package proofedmesh.transformations.per_diem_test
|
||
|
|
|
||
|
|
import data.proofedmesh.transformations.per_diem as pdc
|
||
|
|
import rego.v1
|
||
|
|
|
||
|
|
good_output := {"expense_items": [
|
||
|
|
{
|
||
|
|
"type": "PER_DIEM_ARRIVAL",
|
||
|
|
"amount": "14.00",
|
||
|
|
"incurred_on": "2026-10-01",
|
||
|
|
"computed_from": {"transform_attestation_ref": "sha256:aa", "rate_id": "PDR-42"},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"type": "PER_DIEM_FULL",
|
||
|
|
"amount": "28.00",
|
||
|
|
"incurred_on": "2026-10-02",
|
||
|
|
"computed_from": {"transform_attestation_ref": "sha256:aa", "rate_id": "PDR-42"},
|
||
|
|
},
|
||
|
|
]}
|
||
|
|
|
||
|
|
base := {
|
||
|
|
"agent_id": "agent-per-diem-calculator",
|
||
|
|
"operation": "expense.compute_per_diem",
|
||
|
|
"output_schema": {"name": "expense.canonical", "version": "1.2.0"},
|
||
|
|
"output_payload": good_output,
|
||
|
|
}
|
||
|
|
|
||
|
|
test_allow_normal_compute if {
|
||
|
|
pdc.allow with input as base
|
||
|
|
}
|
||
|
|
|
||
|
|
test_deny_wrong_agent if {
|
||
|
|
not pdc.allow with input as object.union(base, {"agent_id": "agent-travel"})
|
||
|
|
}
|
||
|
|
|
||
|
|
test_deny_wrong_operation if {
|
||
|
|
not pdc.allow with input as object.union(base, {"operation": "expense.normalize"})
|
||
|
|
}
|
||
|
|
|
||
|
|
test_deny_wrong_output_schema_version if {
|
||
|
|
not pdc.allow with input as object.union(base, {"output_schema": {"name": "expense.canonical", "version": "1.1.0"}})
|
||
|
|
}
|
||
|
|
|
||
|
|
test_deny_non_per_diem_item if {
|
||
|
|
bad := {"expense_items": [{
|
||
|
|
"type": "HOTEL",
|
||
|
|
"amount": "100.00",
|
||
|
|
"incurred_on": "2026-10-01",
|
||
|
|
"computed_from": {"transform_attestation_ref": "sha256:aa"},
|
||
|
|
}]}
|
||
|
|
not pdc.allow with input as object.union(base, {"output_payload": bad})
|
||
|
|
}
|
||
|
|
|
||
|
|
test_deny_missing_computed_from if {
|
||
|
|
bad := {"expense_items": [{
|
||
|
|
"type": "PER_DIEM_FULL",
|
||
|
|
"amount": "28.00",
|
||
|
|
"incurred_on": "2026-10-02",
|
||
|
|
}]}
|
||
|
|
not pdc.allow with input as object.union(base, {"output_payload": bad})
|
||
|
|
}
|
||
|
|
|
||
|
|
test_deny_zero_amount if {
|
||
|
|
bad := {"expense_items": [{
|
||
|
|
"type": "PER_DIEM_FULL",
|
||
|
|
"amount": "0.00",
|
||
|
|
"incurred_on": "2026-10-02",
|
||
|
|
"computed_from": {"transform_attestation_ref": "sha256:aa"},
|
||
|
|
}]}
|
||
|
|
not pdc.allow with input as object.union(base, {"output_payload": bad})
|
||
|
|
}
|
||
|
|
|
||
|
|
test_deny_negative_amount if {
|
||
|
|
bad := {"expense_items": [{
|
||
|
|
"type": "PER_DIEM_FULL",
|
||
|
|
"amount": "-5.00",
|
||
|
|
"incurred_on": "2026-10-02",
|
||
|
|
"computed_from": {"transform_attestation_ref": "sha256:aa"},
|
||
|
|
}]}
|
||
|
|
not pdc.allow with input as object.union(base, {"output_payload": bad})
|
||
|
|
}
|