From c0b6fd6ccba1af0f12664553385e89177b7c9478 Mon Sep 17 00:00:00 2001 From: Abdul Khan Date: Tue, 2 Jun 2026 19:04:02 -0400 Subject: [PATCH] Fix serialize missing ID response --- src/web/api.rs | 2 +- tests/rojo_test/serve_util.rs | 14 +++++++++++--- tests/tests/serve.rs | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/web/api.rs b/src/web/api.rs index 38163bb9..b1edc9d0 100644 --- a/src/web/api.rs +++ b/src/web/api.rs @@ -267,7 +267,7 @@ impl ApiService { response_dom.transfer_within(child_ref, object_value); } else { - msgpack( + return msgpack( ErrorResponse::bad_request(format!("provided id {id} is not in the tree")), StatusCode::BAD_REQUEST, ); diff --git a/tests/rojo_test/serve_util.rs b/tests/rojo_test/serve_util.rs index 4b67a883..40274314 100644 --- a/tests/rojo_test/serve_util.rs +++ b/tests/rojo_test/serve_util.rs @@ -229,6 +229,16 @@ impl TestServeSession { ids: &[Ref], session_id: SessionId, ) -> Result { + let body = self.post_api_serialize(ids, session_id)?.bytes()?; + + Ok(deserialize_msgpack(&body).expect("Server returned malformed response")) + } + + pub fn post_api_serialize( + &self, + ids: &[Ref], + session_id: SessionId, + ) -> Result { let client = reqwest::blocking::Client::new(); let url = format!("http://localhost:{}/api/serialize", self.port); let body = serialize_msgpack(&SerializeRequest { @@ -237,9 +247,7 @@ impl TestServeSession { }) .unwrap(); - let body = client.post(url).body(body).send()?.bytes()?; - - Ok(deserialize_msgpack(&body).expect("Server returned malformed response")) + client.post(url).body(body).send() } } diff --git a/tests/tests/serve.rs b/tests/tests/serve.rs index 748f1687..a51df864 100644 --- a/tests/tests/serve.rs +++ b/tests/tests/serve.rs @@ -1,6 +1,8 @@ use std::fs; use insta::{assert_snapshot, assert_yaml_snapshot, with_settings}; +use rbx_dom_weak::types::Ref; +use reqwest::StatusCode; use tempfile::tempdir; use crate::rojo_test::{ @@ -659,6 +661,20 @@ fn meshpart_with_id() { }); } +#[test] +fn serialize_missing_id() { + run_serve_test("empty", |session, _| { + let info = session.get_api_rojo().unwrap(); + let missing_id = Ref::new(); + + let response = session + .post_api_serialize(&[missing_id], info.session_id) + .unwrap(); + + assert_eq!(response.status(), StatusCode::BAD_REQUEST); + }); +} + #[test] fn forced_parent() { run_serve_test("forced_parent", |session, mut redactions| {