Expense approval with http.send
An expense needs the approval of the manager of the employee. The policy asks the staff directory for the manager with http.send. The demo answers http.send in memory: alice and bob report to carol, and carol reports to erin. The server does not sign the decision, because http.send is impure.
Bundle expenses, revision 2026-12-03, decision data.expenses.approval.decision
Examples
Input: manager-approves
{ "expense": { "amount": 120, "approver": "carol", "employee": "alice" } }
Files
Show tree shaking for the decision
1# The tests of the policy. They replace `http.send` with `with`, so they do not need the staff directory.
2package expenses.approval_test
3
4import data.expenses.approval
5
6# The response of the staff directory for an employee whose manager is carol.
7carol_manages(_) := {"status_code": 200, "body": {"name": "alice", "manager": "carol"}}
8
9test_manager_approves if {
10 approval.allow with input as {"expense": {"amount": 120, "approver": "carol", "employee": "alice"}}
11 with http.send as carol_manages
12}
13
14test_self_approval_is_denied if {
15 approval.reasons == {"only carol, the manager of alice, can approve"} with input as {"expense": {"amount": 120, "approver": "alice", "employee": "alice"}}
16 with http.send as carol_manages
17}
18
19test_amount_over_the_limit if {
20 "the amount is more than the limit of 1000" in approval.reasons with input as {"expense": {"amount": 5000, "approver": "carol", "employee": "alice"}}
21 with http.send as carol_manages
22}
23
24test_unknown_employee if {
25 approval.reasons == {"the employee is not in the directory"} with input as {"expense": {"amount": 120, "approver": "carol", "employee": "zoe"}}
26 with http.send as {"status_code": 404}
27}
28