Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Commit

Permalink
Additional Event parsing tests (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
codesections authored Apr 29, 2020
1 parent d2b9fbe commit 4de9a94
Show file tree
Hide file tree
Showing 8 changed files with 381 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/response/event/checked_event/status.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod application;
mod attachment;
pub(super) mod attachment;
mod card;
mod poll;

Expand Down
20 changes: 10 additions & 10 deletions src/response/event/checked_event/status/attachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ use serde::{Deserialize, Serialize};
#[serde(deny_unknown_fields)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub(in super::super) struct Attachment {
pub(super) id: String,
pub(super) r#type: AttachmentType,
pub(super) url: String,
pub(super) preview_url: String,
pub(super) remote_url: Option<String>,
pub(super) text_url: Option<String>,
pub(super) meta: Option<serde_json::Value>,
pub(super) description: Option<String>,
pub(super) blurhash: Option<String>,
pub(in super::super) id: String,
pub(in super::super) r#type: AttachmentType,
pub(in super::super) url: String,
pub(in super::super) preview_url: String,
pub(in super::super) remote_url: Option<String>,
pub(in super::super) text_url: Option<String>,
pub(in super::super) meta: Option<serde_json::Value>, // TODO - is this the best type for the API?
pub(in super::super) description: Option<String>,
pub(in super::super) blurhash: Option<String>,
}

#[serde(rename_all = "lowercase", deny_unknown_fields)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub(super) enum AttachmentType {
pub(in super::super) enum AttachmentType {
Unknown,
Image,
Gifv,
Expand Down
19 changes: 18 additions & 1 deletion src/response/event/checked_event/test.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use super::{super::*, *};
use checked_event::{
account::{Account, Field},
status::attachment::{Attachment, AttachmentType::*},
tag::Tag,
visibility::Visibility::*,
CheckedEvent::*,
*,
};
use serde_json::json;
use std::fs;

#[test]
Expand All @@ -21,6 +22,22 @@ fn parse_redis_msg_to_event() -> Result<(), Box<dyn std::error::Error>> {
env!("CARGO_MANIFEST_DIR"),
"/test_data/event_002.rs"
)),
include!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/test_data/event_003.rs"
)),
include!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/test_data/event_004.rs"
)),
include!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/test_data/event_005.rs"
)),
include!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/test_data/event_006.rs"
)),
];

while let (Ok(input), Some(output)) = (
Expand Down
1 change: 0 additions & 1 deletion src/response/redis/msg/test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::*;
use std::fs;
use std::path;

#[test]
fn parse_redis_subscribe() -> Result<(), RedisParseErr> {
Expand Down
99 changes: 99 additions & 0 deletions test_data/event_003.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
Event::TypeSafe(
Update {
payload: Status {
id: Id(
104072557586605107,
),
uri: "https://botsin.space/users/it_was_inevitable/statuses/104072557374505694".to_string(),
created_at: "2020-04-27T21:00:00.000Z".to_string(),
account: Account {
id: Id(
2160,
),
username: "it_was_inevitable".to_string(),
acct: "it_was_inevitable@botsin.space".to_string(),
url: "https://botsin.space/@it_was_inevitable".to_string(),
display_name: "Sentient Dwarf Fortress".to_string(),
note: "<p>It was inevitable.</p><p>Real quotes from Dwarf Fortress dwarves every 5 minutes.</p><p>Too fast? Try <span class=\"h-card\"><a href=\"https://botsin.space/@it_was_inevitable_slow\" class=\"u-url mention\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">@<span>it_was_inevitable_slow</span></a></span>.</p><p><a href=\"https://botsin.space/tags/dwarffortress\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>dwarffortress</span></a></p>".to_string(),
avatar: "https://instance.codesections.com/system/accounts/avatars/000/002/160/original/9d4fb963ee23aaef.gif?1585017843".to_string(),
avatar_static: "https://instance.codesections.com/system/accounts/avatars/000/002/160/static/9d4fb963ee23aaef.png?1585017843".to_string(),
header: "https://instance.codesections.com/system/accounts/headers/000/002/160/original/d52a62c64b18cac0.png?1585017845".to_string(),
header_static: "https://instance.codesections.com/system/accounts/headers/000/002/160/original/d52a62c64b18cac0.png?1585017845".to_string(),
locked: false,
emojis: [].to_vec(),
discoverable: Some(
true,
),
created_at: "2020-03-24T02:44:05.588Z".to_string(),
statuses_count: 171387,
followers_count: 384,
following_count: 4,
moved: None,
fields: Some(
[
Field {
name: "Overseer".to_string(),
value: "<span class=\"h-card\"><a href=\"https://mastodon.lubar.me/@ben\" class=\"u-url mention\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">@<span>ben</span></a></span>".to_string(),
verified_at: None,
},
Field {
name: "Game".to_string(),
value: "<a href=\"http://bay12games.com/dwarves/\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">http://</span><span class=\"\">bay12games.com/dwarves/</span><span class=\"invisible\"></span></a>".to_string(),
verified_at: None,
},
Field {
name: "DFHack".to_string(),
value: "<a href=\"https://dfhack.org/bay12\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">dfhack.org/bay12</span><span class=\"invisible\"></span></a>".to_string(),
verified_at: None,
},
Field {
name: "Code".to_string(),
value: "<a href=\"https://git.io/fNjyH\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">git.io/fNjyH</span><span class=\"invisible\"></span></a>".to_string(),
verified_at: None,
},
].to_vec(),
),
bot: Some(
true,
),
source: None,
group: Some(
false,
),
last_status_at: Some(
"2020-04-27".to_string(),
),
},
content: "<p>I just wish to help somebody. I\'m uneasy.</p><p>— Mörul Zedotmedtob, Cook</p>".to_string(),
visibility: Public,
sensitive: false,
spoiler_text: "".to_string(),
media_attachments: [].to_vec(),
application: None,
mentions: [].to_vec(),
tags: [].to_vec(),
emojis: [].to_vec(),
reblogs_count: 0,
favourites_count: 0,
replies_count: 0,
url: Some(
"https://botsin.space/@it_was_inevitable/104072557374505694".to_string(),
),
in_reply_to_id: None,
in_reply_to_account_id: None,
reblog: None,
poll: None,
card: None,
language: Some(
"en".to_string(),
),
text: None,
favourited: None,
reblogged: None,
muted: None,
bookmarked: None,
pinned: None,
},
queued_at: None,
},
)
5 changes: 5 additions & 0 deletions test_data/event_004.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Event::TypeSafe(
Delete {
payload: "104061222412800865".to_string(),
},
)
143 changes: 143 additions & 0 deletions test_data/event_005.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
Event::TypeSafe(
Update {
payload: Status {
id: Id(
104072561966487967,
),
uri: "https://newsbots.eu/users/telesur_es/statuses/104072561638766292".to_string(),
created_at: "2020-04-27T21:01:05.000Z".to_string(),
account: Account {
id: Id(
720,
),
username: "telesur_es".to_string(),
acct: "telesur_es@newsbots.eu".to_string(),
url: "https://newsbots.eu/@telesur_es".to_string(),
display_name: "teleSUR TV (Extraoficial)".to_string(),
note: "<p>Con más 40 corresponsales en el mundo, alzamos nuestra voz donde otros medios callan. teleSUR es la señal informativa de América Latina</p>".to_string(),
avatar: "https://instance.codesections.com/system/accounts/avatars/000/000/720/original/57b77baa5d424d0c.jpeg?1584097695".to_string(),
avatar_static: "https://instance.codesections.com/system/accounts/avatars/000/000/720/original/57b77baa5d424d0c.jpeg?1584097695".to_string(),
header: "https://instance.codesections.com/headers/original/missing.png".to_string(),
header_static: "https://instance.codesections.com/headers/original/missing.png".to_string(),
locked: false,
emojis: [].to_vec(),
discoverable: Some(
false,
),
created_at: "2020-03-13T11:08:17.249Z".to_string(),
statuses_count: 40648,
followers_count: 898,
following_count: 0,
moved: None,
fields: Some(
[
Field {
name: "Fuente".to_string(),
value: "<a href=\"https://twitter.com/telesurtv\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">twitter.com/telesurtv</span><span class=\"invisible\"></span></a>".to_string(),
verified_at: None,
},
Field {
name: "En inglés".to_string(),
value: "<span class=\"h-card\"><a href=\"https://newsbots.eu/@telesur_en\" class=\"u-url mention\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">@<span>telesur_en</span></a></span>".to_string(),
verified_at: None,
},
Field {
name: "Operador".to_string(),
value: "<span class=\"h-card\"><a href=\"https://radical.town/@felix\" class=\"u-url mention\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">@<span>felix</span></a></span>".to_string(),
verified_at: None,
},
Field {
name: "Codigo".to_string(),
value: "<a href=\"https://yerbamate.dev/nutomic/tootbot\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">yerbamate.dev/nutomic/tootbot</span><span class=\"invisible\"></span></a>".to_string(),
verified_at: None,
},
].to_vec(),
),
bot: Some(
true,
),
source: None,
group: Some(
false,
),
last_status_at: Some(
"2020-04-27".to_string(),
),
},
content: "<p>Autoridades internacionales de la <a href=\"https://newsbots.eu/tags/F%C3%B3rmulaUno\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>FórmulaUno</span></a> decidieron suspender el Gran Premio de <a href=\"https://newsbots.eu/tags/Francia\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>Francia</span></a>, que se celebraría el próximo 28 de junio</p><p>Ante esta decisión, la primera parada del Campeonato del Mundo será el Gran Premio de Austria <a href=\"https://www.telesurtv.net/news/suspendido-gran-premio-francia-formula-uno-covid-20200427-0011.html\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://www.</span><span class=\"ellipsis\">telesurtv.net/news/suspendido-</span><span class=\"invisible\">gran-premio-francia-formula-uno-covid-20200427-0011.html</span></a>&nbsp;</p>".to_string(),
visibility: Public,
sensitive: true,
spoiler_text: "".to_string(),
media_attachments: [
Attachment {
id: "13283".to_string(),
r#type: Image,
url: "https://instance.codesections.com/system/media_attachments/files/000/013/283/original/0d148b189319d632.jpeg?1588021269".to_string(),
preview_url: "https://instance.codesections.com/system/media_attachments/files/000/013/283/small/0d148b189319d632.jpeg?1588021269".to_string(),
remote_url: Some(
"https://newsbots.eu/system/media_attachments/files/000/199/561/original/8f1042130e797306.jpeg".to_string(),
),
text_url: None,
meta: Some(
json!(
{
"original": {
"aspect": 1.7751479289940828,
"height": 338,
"size": "600x338",
"width": 600,
},
"small": {
"aspect": 1.7766666666666666,
"height": 300,
"size": "533x300",
"width": 533,
},
}
),
),
description: None,
blurhash: Some(
"U9Dcs{QU4mTGu2VFWAkpDinl%2%LxZ%Lxuxu".to_string(),
),
},
].to_vec(),
application: None,
mentions: [].to_vec(),
tags: [
Tag {
name: "FórmulaUno".to_string(),
url: "https://instance.codesections.com/tags/F%C3%B3rmulaUno".to_string(),
history: None,
},
Tag {
name: "francia".to_string(),
url: "https://instance.codesections.com/tags/francia".to_string(),
history: None,
},
].to_vec(),
emojis: [].to_vec(),
reblogs_count: 0,
favourites_count: 0,
replies_count: 0,
url: Some(
"https://newsbots.eu/@telesur_es/104072561638766292".to_string(),
),
in_reply_to_id: None,
in_reply_to_account_id: None,
reblog: None,
poll: None,
card: None,
language: Some(
"es".to_string(),
),
text: None,
favourited: None,
reblogged: None,
muted: None,
bookmarked: None,
pinned: None,
},
queued_at: None,
},
)
Loading

0 comments on commit 4de9a94

Please sign in to comment.