feat(executor): expose ctx.request.method to scripts (F4)
The request map exposed path/headers/body/params/query/rest but not the HTTP method, forcing one script per verb (the E2E app needed 7 scripts where ~3 would do). Add a `method` field to ExecRequest (populated from the HTTP method on the sync-execute bypass and the HTTP outbox payload; empty for non-HTTP triggers) and surface it as `ctx.request.method`, uppercased. A single script can now branch GET/POST on one route. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,7 @@ fn req(body: serde_json::Value) -> ExecRequest {
|
||||
script_name: "test".into(),
|
||||
invocation_type: InvocationType::Http,
|
||||
path: "/test".into(),
|
||||
method: String::new(),
|
||||
headers: BTreeMap::new(),
|
||||
body,
|
||||
params: BTreeMap::new(),
|
||||
@@ -103,6 +104,7 @@ fn ctx_exposes_request_data() {
|
||||
";
|
||||
let r = ExecRequest {
|
||||
path: "/payments".into(),
|
||||
method: String::new(),
|
||||
body: json!({ "amount": 1234 }),
|
||||
script_name: "payments".into(),
|
||||
..req(json!(null))
|
||||
@@ -114,6 +116,19 @@ fn ctx_exposes_request_data() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ctx_exposes_request_method() {
|
||||
// A single script can branch on the verb instead of needing one
|
||||
// script per method (E2E report F4).
|
||||
let src = r"#{ statusCode: 200, body: #{ method: ctx.request.method } }";
|
||||
let r = ExecRequest {
|
||||
method: "PATCH".into(),
|
||||
..req(json!(null))
|
||||
};
|
||||
let resp = engine().execute(src, r).unwrap();
|
||||
assert_eq!(resp.body, json!({ "method": "PATCH" }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn captures_log_calls() {
|
||||
let src = r#"
|
||||
|
||||
Reference in New Issue
Block a user