use serde_json::json; use shared_contracts::runtime::{ AdminUpsertProfileTaskConfigRequest, ProfileTaskConfigAdminResponse, TRACKING_SCOPE_KIND_USER, }; #[test] fn admin_upsert_profile_task_config_keeps_personal_task_scope_user() { let request: AdminUpsertProfileTaskConfigRequest = serde_json::from_value(json!({ "taskId": "daily_login", "title": "每日登录", "description": "", "eventKey": "daily_login", "cycle": "daily", "scopeKind": "user", "threshold": 1, "rewardPoints": 10, "enabled": true, "sortOrder": 10 })) .expect("个人任务配置请求应接受 user scope"); assert_eq!(request.scope_kind, TRACKING_SCOPE_KIND_USER); let value = serde_json::to_value(request).expect("个人任务配置请求应可序列化"); assert_eq!(value["scopeKind"], json!(TRACKING_SCOPE_KIND_USER)); } #[test] fn profile_task_config_admin_response_serializes_scope_kind_as_user() { let response = ProfileTaskConfigAdminResponse { task_id: "daily_login".to_string(), title: "每日登录".to_string(), description: "".to_string(), event_key: "daily_login".to_string(), cycle: "daily".to_string(), scope_kind: TRACKING_SCOPE_KIND_USER.to_string(), threshold: 1, reward_points: 10, enabled: true, sort_order: 10, created_by: "admin".to_string(), created_at: "2026-05-04T00:00:00Z".to_string(), updated_by: "admin".to_string(), updated_at: "2026-05-04T00:00:00Z".to_string(), }; let value = serde_json::to_value(response).expect("个人任务配置响应应可序列化"); assert_eq!(value["scopeKind"], json!(TRACKING_SCOPE_KIND_USER)); assert_eq!(value["taskId"], json!("daily_login")); assert_eq!(value["rewardPoints"], json!(10)); }