Skip to content

Commit d30eadd

Browse files
committed
feat: add dynamic JMESPath and jq state variable rendering tests to api_test.go and api_suite.yaml
1 parent 22a6674 commit d30eadd

File tree

2 files changed

+119
-1
lines changed

2 files changed

+119
-1
lines changed

core/dbio/api/api_suite.yaml

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,4 +712,68 @@
712712
- id: "2"
713713
name: Item 2
714714
expected_state: {}
715-
expected_next_state: {}
715+
expected_next_state: {}
716+
717+
- id: 14
718+
name: jmespath_with_state_variable_rendering
719+
mock_response:
720+
customers:
721+
- id: 1
722+
name: Alice
723+
email: alice@example.com
724+
- id: 2
725+
name: Bob
726+
email: bob@example.com
727+
spec:
728+
name: test_api
729+
authentication:
730+
type: none
731+
endpoints:
732+
test_endpoint:
733+
name: test_endpoint
734+
state:
735+
endpoint_name: customers
736+
response:
737+
records:
738+
jmespath: "{state.endpoint_name}[]"
739+
expected_records:
740+
- id: "1"
741+
name: Alice
742+
email: alice@example.com
743+
- id: "2"
744+
name: Bob
745+
email: bob@example.com
746+
expected_state:
747+
endpoint_name: customers
748+
749+
- id: 15
750+
name: jq_with_state_variable_rendering
751+
mock_response:
752+
orders:
753+
- id: 101
754+
product: Widget
755+
quantity: 5
756+
- id: 102
757+
product: Gadget
758+
quantity: 3
759+
spec:
760+
name: test_api
761+
authentication:
762+
type: none
763+
endpoints:
764+
test_endpoint:
765+
name: test_endpoint
766+
state:
767+
resource: orders
768+
response:
769+
records:
770+
jq: ".{state.resource}[]"
771+
expected_records:
772+
- id: "101"
773+
product: Widget
774+
quantity: "5"
775+
- id: "102"
776+
product: Gadget
777+
quantity: "3"
778+
expected_state:
779+
resource: orders

core/dbio/api/api_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,60 @@ dynamic_endpoints:
12641264
},
12651265
},
12661266
},
1267+
{
1268+
name: "dynamic_jmespath_with_state_variable",
1269+
specYAML: `
1270+
name: "Test Dynamic JMESPath State Var"
1271+
defaults:
1272+
state:
1273+
base_url: "{base_url}"
1274+
1275+
dynamic_endpoints:
1276+
- iterate: '["customer_type", "order_type"]'
1277+
into: "state.endpoint_name"
1278+
endpoint:
1279+
name: "{state.endpoint_name}"
1280+
request:
1281+
url: "{state.base_url}/{state.endpoint_name}"
1282+
response:
1283+
records:
1284+
jmespath: "{state.endpoint_name}[]"
1285+
`,
1286+
expectedEndpointNames: []string{
1287+
"customer_type",
1288+
"order_type",
1289+
},
1290+
dataResponses: map[string]map[string]any{
1291+
"/customer_type": {
1292+
"customer_type": []map[string]any{
1293+
{"id": 1, "name": "Retail"},
1294+
{"id": 2, "name": "Wholesale"},
1295+
},
1296+
},
1297+
"/order_type": {
1298+
"order_type": []map[string]any{
1299+
{"id": 10, "name": "Standard"},
1300+
{"id": 20, "name": "Express"},
1301+
{"id": 30, "name": "Overnight"},
1302+
},
1303+
},
1304+
},
1305+
expectedRecordCounts: map[string]int{
1306+
"customer_type": 2,
1307+
"order_type": 3,
1308+
},
1309+
expectedRecordValues: map[string][]any{
1310+
"customer_type": {
1311+
map[string]any{"id": float64(1), "name": "Retail"},
1312+
map[string]any{"id": float64(2), "name": "Wholesale"},
1313+
},
1314+
"order_type": {
1315+
map[string]any{"id": float64(10), "name": "Standard"},
1316+
map[string]any{"id": float64(20), "name": "Express"},
1317+
map[string]any{"id": float64(30), "name": "Overnight"},
1318+
},
1319+
},
1320+
},
12671321
}
12681322

12691323
for _, tt := range tests {

0 commit comments

Comments
 (0)