use kakao_rs::prelude::*; use std::matches; #[test] fn chatbot_response_test() { let mut result = Template::new(); let description = String::from("현재 날씨는 맑음, 22.5도\n최저기온 7도, 최고기온은 23도\n\n낮, 밤 강수 확률은 0%, 0%\n미세먼지 농도는 보통\n자외선은 보통, 일몰은 19:00\n내일은 8도/23도"); let basic_card = BasicCard::new() .set_title("[수원 영통구 기준]") .set_desc(description) .set_thumbnail("https://raw.githubusercontent.com/Alfex4936/KakaoChatBot-Golang/main/imgs/ico_animation_wt1.png?raw=true") .add_button(Button::link("자세히", "https://m.search.naver.com/search.naver?sm=tab_hty.top&where=nexearch&query=%EB%82%A0%EC%94%A8+%EB%A7%A4%ED%83%843%EB%8F%99&oquery=%EB%82%A0%EC%94%A8")); result.add_output(basic_card.build()); let serialized = r#"{"template":{"outputs":[{"basicCard":{"title":"[수원 영통구 기준]","description":"현재 날씨는 맑음, 22.5도\n최저기온 7도, 최고기온은 23도\n\n낮, 밤 강수 확률은 0%, 0%\n미세먼지 농도는 보통\n자외선은 보통, 일몰은 19:00\n내일은 8도/23도","thumbnail":{"imageUrl":"https://raw.githubusercontent.com/Alfex4936/KakaoChatBot-Golang/main/imgs/ico_animation_wt1.png?raw=true"},"buttons":[{"label":"자세히","action":"webLink","webLinkUrl":"https://m.search.naver.com/search.naver?sm=tab_hty.top&where=nexearch&query=%EB%82%A0%EC%94%A8+%EB%A7%A4%ED%83%843%EB%8F%99&oquery=%EB%82%A0%EC%94%A8"}]}}]},"version":"2.0"}"#; assert_eq!(serialized, serde_json::to_string(&result).expect("Failed")); let deserialized: Template = serde_json::from_str(result.to_string().as_str()).unwrap(); assert!(matches!( deserialized.template.outputs[0], Types::Basic { .. } )); }