test(api): expand live activity feed and telemetry integration unit tests
This commit is contained in:
1 parent
da3700d1d5
commit
b4a95b3e6a
1 file changed
+43
-3
+43
-3
@@ -727,20 +727,57 @@ mod tests {
|
||||
let json_str = String::from_utf8(body_bytes.to_vec()).unwrap();
|
||||
assert_eq!(json_str.trim(), "[]");
|
||||
|
||||
// 2. Record an activity
|
||||
// 2. Record a direct activity
|
||||
app_state.handler.state.record_activity("code_change", "Refactored live activity UI", Some("Added empty state placeholder"));
|
||||
|
||||
// 3. GET /api/activity should now return recorded item
|
||||
// 3. Post terminal telemetry activity
|
||||
let app_term = create_router(app_state.clone());
|
||||
let term_req = Request::builder()
|
||||
.method("POST")
|
||||
.uri("/terminal/telemetry")
|
||||
.header("content-type", "application/json")
|
||||
.body(Body::from(serde_json::json!({
|
||||
"command": "cargo test --workspace",
|
||||
"exit_code": 0,
|
||||
"cwd": "C:\\workspace\\mcp-memory",
|
||||
"os": "windows",
|
||||
"timestamp": 1728130000000u64
|
||||
}).to_string()))
|
||||
.unwrap();
|
||||
let term_resp = app_term.oneshot(term_req).await.unwrap();
|
||||
assert_eq!(term_resp.status(), StatusCode::OK);
|
||||
|
||||
// 4. Post Neovim telemetry activity
|
||||
let app_nvim = create_router(app_state.clone());
|
||||
let nvim_req = Request::builder()
|
||||
.method("POST")
|
||||
.uri("/nvim/telemetry")
|
||||
.header("content-type", "application/json")
|
||||
.body(Body::from(serde_json::json!({
|
||||
"session_id": "test_session_1",
|
||||
"event": "BufWritePost",
|
||||
"file": "server/src/dashboard.ts"
|
||||
}).to_string()))
|
||||
.unwrap();
|
||||
let nvim_resp = app_nvim.oneshot(nvim_req).await.unwrap();
|
||||
assert_eq!(nvim_resp.status(), StatusCode::OK);
|
||||
|
||||
// 5. GET /api/activity should return all recorded items
|
||||
let app_act2 = create_router(app_state.clone());
|
||||
let req_act2 = Request::builder().uri("/api/activity").body(Body::empty()).unwrap();
|
||||
let resp_act2 = app_act2.oneshot(req_act2).await.unwrap();
|
||||
assert_eq!(resp_act2.status(), StatusCode::OK);
|
||||
let body_bytes2 = axum::body::to_bytes(resp_act2.into_body(), usize::MAX).await.unwrap();
|
||||
let json_str2 = String::from_utf8(body_bytes2.to_vec()).unwrap();
|
||||
|
||||
assert!(json_str2.contains("CODE_CHANGE"));
|
||||
assert!(json_str2.contains("Refactored live activity UI"));
|
||||
assert!(json_str2.contains("TERMINAL"));
|
||||
assert!(json_str2.contains("cargo test --workspace"));
|
||||
assert!(json_str2.contains("EDITOR"));
|
||||
assert!(json_str2.contains("server/src/dashboard.ts"));
|
||||
|
||||
// 4. Verify /dashboard.js contains empty state text
|
||||
// 6. Verify /dashboard.js contains empty state text and stream logic
|
||||
let app_js = create_router(app_state.clone());
|
||||
let req_js = Request::builder().uri("/dashboard.js").body(Body::empty()).unwrap();
|
||||
let resp_js = app_js.oneshot(req_js).await.unwrap();
|
||||
@@ -748,6 +785,8 @@ mod tests {
|
||||
let js_bytes = axum::body::to_bytes(resp_js.into_body(), usize::MAX).await.unwrap();
|
||||
let js_str = String::from_utf8(js_bytes.to_vec()).unwrap();
|
||||
assert!(js_str.contains("No recent activity recorded yet."));
|
||||
assert!(js_str.contains("/api/activity/stream"));
|
||||
assert!(js_str.contains("parseActivityPayload"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -755,3 +794,4 @@ mod tests {
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user