FastLED 3.9.15
Loading...
Searching...
No Matches

◆ test_json_endpoint()

void test_json_endpoint ( )

Definition at line 74 of file ClientValidationReal.h.

74 {
75 FL_WARN("\n=== Test 1: GET /json (Slideshow Data) ===");
76
77 fl::task::Promise<fl::net::http::Response> promise = fl::net::http::fetch_get("http://localhost:8081/json");
79
80 if (!result.ok()) {
81 FL_WARN("✗ FAILED: " << result.error_message());
83 state = FAILED;
84 return;
85 }
86
87 const fl::net::http::Response& resp = result.value();
88 if (resp.status() != 200) {
89 FL_WARN("✗ FAILED: Status " << resp.status() << " " << resp.status_text());
91 state = FAILED;
92 return;
93 }
94
95 if (!resp.is_json()) {
96 FL_WARN("✗ FAILED: Response is not JSON");
98 state = FAILED;
99 return;
100 }
101
102 fl::json data = resp.json();
103 fl::string author = data["slideshow"]["author"] | fl::string("unknown");
104 fl::string title = data["slideshow"]["title"] | fl::string("untitled");
105 int slide_count = data["slideshow"]["slides"].size();
106
107 if (author == "unknown" || title == "untitled" || slide_count == 0) {
108 FL_WARN("✗ FAILED: Invalid JSON structure");
109 FL_WARN(" Author: " << author);
110 FL_WARN(" Title: " << title);
111 FL_WARN(" Slides: " << slide_count);
112 tests_failed++;
113 state = FAILED;
114 return;
115 }
116
117 FL_WARN("✓ PASSED");
118 FL_WARN(" Author: " << author);
119 FL_WARN(" Title: " << title);
120 FL_WARN(" Slides: " << slide_count);
121 tests_passed++;
122}
fl::UITitle title("Animartrix")
int tests_passed
int tests_failed
TestState state
size_t size() const FL_NOEXCEPT
Definition json.h:633
bool is_json() const
Check if response appears to contain JSON content.
Definition fetch.h:122
const fl::string & status_text() const
HTTP status text (like JavaScript response.statusText)
Definition fetch.h:89
int status() const
HTTP status code (like JavaScript response.status)
Definition fetch.h:86
fl::json json() const
Response body parsed as JSON (JavaScript-like API)
HTTP response class (unified interface)
Definition fetch.h:78
Promise class that provides fluent .then() and .catch_() semantics This is a lightweight wrapper arou...
Definition promise.h:58
Result type for promise operations.
#define FL_WARN(X)
Definition log.h:276
fl::task::Promise< Response > fetch_get(const fl::string &url, const FetchOptions &request)
HTTP GET request.
PromiseResult< T > await_top_level(Promise< T > p)
Synchronously wait for a promise to complete (ONLY safe in top-level contexts)
Definition executor.h:186
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31

References fl::task::await_top_level(), FAILED, fl::net::http::fetch_get(), FL_WARN, fl::net::http::Response::is_json(), fl::net::http::Response::json(), fl::json::size(), state, fl::net::http::Response::status(), fl::net::http::Response::status_text(), tests_failed, tests_passed, and title.

Referenced by loop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: