oxidite_testing/
response.rs

1use serde::de::DeserializeOwned;
2use http::StatusCode;
3
4/// Test response wrapper
5pub struct TestResponse {
6    status: StatusCode,
7    body: Vec<u8>,
8}
9
10impl TestResponse {
11    /// Create a new test response
12    pub fn new(status: StatusCode, body: Vec<u8>) -> Self {
13        Self { status, body }
14    }
15
16    /// Get status code
17    pub fn status(&self) -> StatusCode {
18        self.status
19    }
20
21    /// Get body as bytes
22    pub fn body(&self) -> &[u8] {
23        &self.body
24    }
25
26    /// Get body as string
27    pub fn text(&self) -> Result<String, std::string::FromUtf8Error> {
28        String::from_utf8(self.body.clone())
29    }
30
31    /// Deserialize JSON body
32    pub fn json<T: DeserializeOwned>(&self) -> Result<T, serde_json::Error> {
33        serde_json::from_slice(&self.body)
34    }
35
36    /// Check if response is successful (2xx)
37    pub fn is_success(&self) -> bool {
38        self.status.is_success()
39    }
40}