Skip to content

Commit

Permalink
test: Add find_from_str test-case (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
m1sk9 authored Oct 9, 2024
1 parent bbff7bf commit c5591b0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jobs:
- name: Run clippy
run: cargo clippy --all-targets --all-features

- name: Run test
run: cargo test --verbose

- name: Run Build
run: cargo build --verbose

31 changes: 31 additions & 0 deletions src/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,34 @@ impl MessagePreviewIDs {
.image(preview.attachment_image_url.unwrap_or_default())
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_find_from_str_valid_url() {
let url =
"https://discord.com/channels/123456789012345678/987654321098765432/123456789012345678";
let result = MessagePreviewIDs::find_from_str(url).unwrap();
assert_eq!(result.guild_id, GuildId::new(123456789012345678));
assert_eq!(result.channel_id, ChannelId::new(987654321098765432));
assert_eq!(result.message_id, MessageId::new(123456789012345678));
}

#[test]
fn test_find_from_str_invalid_url() {
let url =
"https://example.com/channels/123456789012345678/987654321098765432/123456789012345678";
let result = MessagePreviewIDs::find_from_str(url);
assert!(result.is_err());
}

#[test]
fn test_find_from_str_discordapp_domain() {
let url =
"https://discordapp.com/channels/123456789012345678/987654321098765432/123456789012345678";
let result = MessagePreviewIDs::find_from_str(url);
assert!(result.is_err());
}
}

0 comments on commit c5591b0

Please sign in to comment.