#![allow(clippy::field_reassign_with_default, dead_code)]
#[test]
fn test_open_component_access_token_serde() {
let json_str = r#"{
"component_access_token": "COMP_TOKEN001",
"expires_in": 7200
}"#;
let value: serde_json::Value = serde_json::from_str(json_str).expect("解析 JSON");
assert_eq!(value["component_access_token"], "COMP_TOKEN001");
assert_eq!(value["expires_in"], 7200);
}
#[test]
fn test_open_pre_auth_code_serde() {
let json_str = r#"{
"errcode": 0,
"errmsg": "ok",
"pre_auth_code": "PRE_AUTH_CODE001",
"expires_in": 1800
}"#;
let value: serde_json::Value = serde_json::from_str(json_str).expect("解析 JSON");
assert_eq!(value["pre_auth_code"], "PRE_AUTH_CODE001");
}
#[test]
fn test_open_query_auth_serde() {
let json_str = r#"{
"errcode": 0,
"errmsg": "ok",
"authorization_info": {
"authorizer_appid": "APP001",
"authorizer_access_token": "AUTH_TOKEN001",
"expires_in": 7200,
"authorizer_refresh_token": "REFRESH_TOKEN001"
}
}"#;
let value: serde_json::Value = serde_json::from_str(json_str).expect("解析 JSON");
assert_eq!(value["authorization_info"]["authorizer_appid"], "APP001");
}
#[test]
fn test_open_oauth2_url_build() {
let app_id = "APP001";
let redirect_uri = "http://example.com/callback";
let url = format!(
"https://open.weixin.qq.com/connect/oauth2/authorize?appid={}&redirect_uri={}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect",
app_id, redirect_uri
);
assert!(url.contains("appid=APP001"));
assert!(url.contains("response_type=code"));
}
#[test]
fn test_open_access_token_serde() {
let json_str = r#"{
"access_token": "ACCESS_TOKEN001",
"expires_in": 7200,
"refresh_token": "REFRESH_TOKEN001",
"openid": "OPENID001",
"scope": "snsapi_userinfo"
}"#;
let value: serde_json::Value = serde_json::from_str(json_str).expect("解析 JSON");
assert_eq!(value["access_token"], "ACCESS_TOKEN001");
assert_eq!(value["openid"], "OPENID001");
}
#[test]
fn test_open_mp_oauth2_url_build() {
let app_id = "MP_APP001";
let redirect_uri = "http://example.com/callback";
let url = format!(
"https://open.weixin.qq.com/connect/qrconnect?appid={}&redirect_uri={}&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect",
app_id, redirect_uri
);
assert!(url.contains("appid=MP_APP001"));
assert!(url.contains("scope=snsapi_login"));
}
#[test]
fn test_open_mp_user_info_serde() {
let json_str = r#"{
"openid": "OPENID001",
"nickname": "测试用户",
"sex": 1,
"province": "广东",
"city": "深圳",
"country": "中国",
"headimgurl": "http://example.com/avatar.jpg"
}"#;
let value: serde_json::Value = serde_json::from_str(json_str).expect("解析 JSON");
assert_eq!(value["openid"], "OPENID001");
}
#[test]
fn test_open_gson_builder_serde() {
let json_str = r#"{
"errcode": 0,
"errmsg": "ok",
"data": {"key": "value"}
}"#;
let value: serde_json::Value = serde_json::from_str(json_str).expect("解析 JSON");
assert_eq!(value["errcode"], 0);
}
#[test]
fn test_open_crypt_decrypt_format() {
let xml = "<xml><ToUserName><![CDATA[gh_test]]></ToUserName></xml>";
assert!(xml.contains("ToUserName"));
}
#[test]
fn test_open_crypt_encrypt_format() {
let encrypted = String::from("ENCRYPTED_CONTENT");
assert!(!encrypted.is_empty());
}
#[test]
fn test_open_redisson_config_storage_body() {
let body = serde_json::json!({
"component_appid": "COMP_APP001",
"component_appsecret": "COMP_SECRET001",
"component_token": "COMP_TOKEN001",
"component_aes_key": "COMP_AES_KEY001"
});
assert_eq!(body["component_appid"], "COMP_APP001");
}