mirror of
https://github.com/System-End/slack-morphism-rust.git
synced 2026-04-19 19:45:13 +00:00
fix: Fix emoji_list response deserialization (#314)
This commit is contained in:
parent
a33155f0f4
commit
9d542e98fd
3 changed files with 52 additions and 4 deletions
|
|
@ -36,3 +36,29 @@ where
|
|||
pub struct SlackApiEmojiListResponse {
|
||||
pub emoji: HashMap<SlackEmojiName, SlackEmojiRef>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_slack_api_emoji_list_response() {
|
||||
let payload = include_str!("./fixtures/slack_api_emoji_list_response.json");
|
||||
let model: SlackApiEmojiListResponse = serde_json::from_str(payload).unwrap();
|
||||
|
||||
assert_eq!(model.emoji.len(), 1);
|
||||
assert!(model
|
||||
.emoji
|
||||
.contains_key(&SlackEmojiName::new("test".to_string())));
|
||||
let test_emoji = model
|
||||
.emoji
|
||||
.get(&SlackEmojiName::new("test".to_string()))
|
||||
.unwrap();
|
||||
match test_emoji {
|
||||
SlackEmojiRef::Url(url) => {
|
||||
assert_eq!(url.as_str(), "https://emoji.slack-edge.com/test_emoji.png")
|
||||
}
|
||||
_ => panic!("unexpected emoji type"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
7
src/api/fixtures/slack_api_emoji_list_response.json
Normal file
7
src/api/fixtures/slack_api_emoji_list_response.json
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"ok": true,
|
||||
"emoji": {
|
||||
"test": "https:\/\/emoji.slack-edge.com\/test_emoji.png"
|
||||
},
|
||||
"cache_ts": "1742309006.064153"
|
||||
}
|
||||
|
|
@ -48,7 +48,7 @@ impl<'de> Visitor<'de> for SlackEmojiRefVisitor {
|
|||
formatter.write_str("a Slack custom emoji URL or alias in the form of 'alias:<name>'")
|
||||
}
|
||||
|
||||
fn visit_borrowed_str<E>(self, v: &'de str) -> Result<Self::Value, E>
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: serde::de::Error,
|
||||
{
|
||||
|
|
@ -61,8 +61,10 @@ impl<'de> Visitor<'de> for SlackEmojiRefVisitor {
|
|||
}
|
||||
}
|
||||
|
||||
let emoji_url: Url = v.parse().unwrap();
|
||||
Ok(SlackEmojiRef::Url(emoji_url))
|
||||
match Url::parse(v) {
|
||||
Ok(url) => Ok(SlackEmojiRef::Url(url)),
|
||||
Err(err) => Err(E::custom(format!("Failed to parse URL '{}': {}", v, err))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -113,7 +115,20 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_serialize_emoji_alias() {
|
||||
fn test_deserialize_emoji_url_with_escaped_slashes() {
|
||||
let emoji_url = r#""https:\/\/emoji.slack-edge.com\/test_emoji.png""#;
|
||||
|
||||
let r = serde_json::from_str::<SlackEmojiRef>(&emoji_url).unwrap();
|
||||
assert_eq!(
|
||||
r,
|
||||
SlackEmojiRef::Url(
|
||||
Url::parse("https://emoji.slack-edge.com/test_emoji.png").unwrap()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_deserialize_emoji_alias() {
|
||||
assert_eq!(
|
||||
serde_json::from_str::<SlackEmojiRef>("\"alias:smile\"").unwrap(),
|
||||
SlackEmojiRef::Alias(SlackEmojiName::new("smile".to_string()))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue