Skip to content

Commit

Permalink
test(term): add error handling test case
Browse files Browse the repository at this point in the history
  • Loading branch information
ymgyt committed Jun 17, 2024
1 parent bbc5465 commit 25641b2
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 18 deletions.
14 changes: 10 additions & 4 deletions crates/synd_term/gql/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -824,25 +824,25 @@
"deprecationReason": null,
"description": null,
"isDeprecated": false,
"name": "RSS1"
"name": "JSON"
},
{
"deprecationReason": null,
"description": null,
"isDeprecated": false,
"name": "RSS2"
"name": "RSS0"
},
{
"deprecationReason": null,
"description": null,
"isDeprecated": false,
"name": "RSS0"
"name": "RSS1"
},
{
"deprecationReason": null,
"description": null,
"isDeprecated": false,
"name": "JSON"
"name": "RSS2"
}
],
"fields": null,
Expand Down Expand Up @@ -1345,6 +1345,12 @@
"isDeprecated": false,
"name": "INVALID_FEED_URL"
},
{
"deprecationReason": null,
"description": "The feed server returned a status other than 200",
"isDeprecated": false,
"name": "FEED_UNAVAILABLE"
},
{
"deprecationReason": null,
"description": "Something went wrong",
Expand Down
18 changes: 12 additions & 6 deletions crates/synd_term/src/client/generated/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ pub mod subscribe_feed {
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum FeedType {
ATOM,
JSON,
RSS0,
RSS1,
RSS2,
RSS0,
JSON,
Other(String),
}
impl ::serde::Serialize for FeedType {
fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
ser.serialize_str(match *self {
FeedType::ATOM => "ATOM",
FeedType::JSON => "JSON",
FeedType::RSS0 => "RSS0",
FeedType::RSS1 => "RSS1",
FeedType::RSS2 => "RSS2",
FeedType::RSS0 => "RSS0",
FeedType::JSON => "JSON",
FeedType::Other(ref s) => &s,
})
}
Expand All @@ -44,10 +44,10 @@ pub mod subscribe_feed {
let s: String = ::serde::Deserialize::deserialize(deserializer)?;
match s.as_str() {
"ATOM" => Ok(FeedType::ATOM),
"JSON" => Ok(FeedType::JSON),
"RSS0" => Ok(FeedType::RSS0),
"RSS1" => Ok(FeedType::RSS1),
"RSS2" => Ok(FeedType::RSS2),
"RSS0" => Ok(FeedType::RSS0),
"JSON" => Ok(FeedType::JSON),
_ => Ok(FeedType::Other(s)),
}
}
Expand Down Expand Up @@ -85,6 +85,7 @@ pub mod subscribe_feed {
OK,
UNAUTHORIZED,
INVALID_FEED_URL,
FEED_UNAVAILABLE,
INTERNAL_ERROR,
Other(String),
}
Expand All @@ -94,6 +95,7 @@ pub mod subscribe_feed {
ResponseCode::OK => "OK",
ResponseCode::UNAUTHORIZED => "UNAUTHORIZED",
ResponseCode::INVALID_FEED_URL => "INVALID_FEED_URL",
ResponseCode::FEED_UNAVAILABLE => "FEED_UNAVAILABLE",
ResponseCode::INTERNAL_ERROR => "INTERNAL_ERROR",
ResponseCode::Other(ref s) => &s,
})
Expand All @@ -106,6 +108,7 @@ pub mod subscribe_feed {
"OK" => Ok(ResponseCode::OK),
"UNAUTHORIZED" => Ok(ResponseCode::UNAUTHORIZED),
"INVALID_FEED_URL" => Ok(ResponseCode::INVALID_FEED_URL),
"FEED_UNAVAILABLE" => Ok(ResponseCode::FEED_UNAVAILABLE),
"INTERNAL_ERROR" => Ok(ResponseCode::INTERNAL_ERROR),
_ => Ok(ResponseCode::Other(s)),
}
Expand Down Expand Up @@ -234,6 +237,7 @@ pub mod unsubscribe_feed {
OK,
UNAUTHORIZED,
INVALID_FEED_URL,
FEED_UNAVAILABLE,
INTERNAL_ERROR,
Other(String),
}
Expand All @@ -243,6 +247,7 @@ pub mod unsubscribe_feed {
ResponseCode::OK => "OK",
ResponseCode::UNAUTHORIZED => "UNAUTHORIZED",
ResponseCode::INVALID_FEED_URL => "INVALID_FEED_URL",
ResponseCode::FEED_UNAVAILABLE => "FEED_UNAVAILABLE",
ResponseCode::INTERNAL_ERROR => "INTERNAL_ERROR",
ResponseCode::Other(ref s) => &s,
})
Expand All @@ -255,6 +260,7 @@ pub mod unsubscribe_feed {
"OK" => Ok(ResponseCode::OK),
"UNAUTHORIZED" => Ok(ResponseCode::UNAUTHORIZED),
"INVALID_FEED_URL" => Ok(ResponseCode::INVALID_FEED_URL),
"FEED_UNAVAILABLE" => Ok(ResponseCode::FEED_UNAVAILABLE),
"INTERNAL_ERROR" => Ok(ResponseCode::INTERNAL_ERROR),
_ => Ok(ResponseCode::Other(s)),
}
Expand Down
12 changes: 6 additions & 6 deletions crates/synd_term/src/client/generated/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ pub mod subscription {
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum FeedType {
ATOM,
JSON,
RSS0,
RSS1,
RSS2,
RSS0,
JSON,
Other(String),
}
impl ::serde::Serialize for FeedType {
fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
ser.serialize_str(match *self {
FeedType::ATOM => "ATOM",
FeedType::JSON => "JSON",
FeedType::RSS0 => "RSS0",
FeedType::RSS1 => "RSS1",
FeedType::RSS2 => "RSS2",
FeedType::RSS0 => "RSS0",
FeedType::JSON => "JSON",
FeedType::Other(ref s) => &s,
})
}
Expand All @@ -44,10 +44,10 @@ pub mod subscription {
let s: String = ::serde::Deserialize::deserialize(deserializer)?;
match s.as_str() {
"ATOM" => Ok(FeedType::ATOM),
"JSON" => Ok(FeedType::JSON),
"RSS0" => Ok(FeedType::RSS0),
"RSS1" => Ok(FeedType::RSS1),
"RSS2" => Ok(FeedType::RSS2),
"RSS0" => Ok(FeedType::RSS0),
"JSON" => Ok(FeedType::JSON),
_ => Ok(FeedType::Other(s)),
}
}
Expand Down
8 changes: 8 additions & 0 deletions crates/synd_term/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub mod query;
pub enum SubscribeFeedError {
#[error("invalid feed url: `{feed_url}` ({message})`")]
InvalidFeedUrl { feed_url: FeedUrl, message: String },
#[error("{feed_url} {message}")]
FeedUnavailable { feed_url: FeedUrl, message: String },
}

#[derive(Error, Debug)]
Expand Down Expand Up @@ -121,6 +123,12 @@ impl Client {
message: err.message,
},
)),
ResponseCode::FEED_UNAVAILABLE => Err(SyndApiError::SubscribeFeed(
SubscribeFeedError::FeedUnavailable {
feed_url: url,
message: err.message,
},
)),
err_code => Err(SyndApiError::Internal(anyhow::anyhow!(
"Unexpected subscribe_feed error code: {err_code:?}"
))),
Expand Down
36 changes: 36 additions & 0 deletions crates/synd_term/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ mod test {
}

#[tokio::test(flavor = "multi_thread")]
#[allow(clippy::too_many_lines)]
async fn subscribe_then_unsubscribe() -> anyhow::Result<()> {
helper::init_tracing();

Expand All @@ -166,6 +167,15 @@ mod test {
"must rust http://localhost:{mock_port}/feed/twir_atom",
mock_port = case.mock_port
),
// internal error
format!(
"may rust http://localhost:{mock_port}/feed/error/internal",
mock_port = case.mock_port
),
format!(
"may rust http://localhost:{mock_port}/feed/error/malformed",
mock_port = case.mock_port
),
]
}),
..Default::default()
Expand Down Expand Up @@ -248,6 +258,32 @@ mod test {
});
}

{
// Handle the case that the server of the feed user tried to subscribe to is returning a internal error.
tx.send(key!('a'));
application
.wait_until_jobs_completed(&mut event_stream)
.await;
insta::with_settings!({
description => "handle internal error of the feed server",
},{
insta::assert_debug_snapshot!("subscribe_then_unsubscribe_feed_server_internal_error", application.buffer());
});
}

{
// Handle the case that the server of the feed user tried to subscribe to is returning a internal error.
tx.send(key!('a'));
application
.wait_until_jobs_completed(&mut event_stream)
.await;
insta::with_settings!({
description => "handle malformed xml error ",
},{
insta::assert_debug_snapshot!("subscribe_then_unsubscribe_malformed_xml_error", application.buffer());
});
}

Ok(())
}
#[tokio::test(flavor = "multi_thread")]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
source: crates/synd_term/tests/integration.rs
description: handle internal error of the feed server
expression: application.buffer()
---
Buffer {
area: Rect { x: 0, y: 0, width: 120, height: 30 },
content: [
" Syndicationd 󱉯 Entries 󰑫 Feeds ",
" 󰈶 Filter MAY ",
"  Search ",
" ",
" Updated Feed -/- URL Description Req ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
"────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
"http://localhost:6020/feed/error/internal feed unavailable: HTTP status server error (500 Internal Server Error) for url",
],
styles: [
x: 0, y: 0, fg: Rgb(254, 205, 178), bg: Rgb(43, 41, 45), underline: Reset, modifier: NONE,
x: 2, y: 0, fg: Rgb(254, 205, 178), bg: Rgb(43, 41, 45), underline: Reset, modifier: BOLD,
x: 14, y: 0, fg: Rgb(254, 205, 178), bg: Rgb(43, 41, 45), underline: Reset, modifier: NONE,
x: 112, y: 0, fg: Rgb(255, 160, 122), bg: Rgb(43, 41, 45), underline: Reset, modifier: BOLD,
x: 119, y: 0, fg: Rgb(254, 205, 178), bg: Rgb(43, 41, 45), underline: Reset, modifier: NONE,
x: 2, y: 1, fg: Rgb(254, 205, 178), bg: Rgb(43, 41, 45), underline: Reset, modifier: DIM,
x: 10, y: 1, fg: Rgb(254, 205, 178), bg: Rgb(43, 41, 45), underline: Reset, modifier: NONE,
x: 14, y: 1, fg: Rgb(254, 205, 178), bg: Rgb(43, 41, 45), underline: Reset, modifier: DIM,
x: 17, y: 1, fg: Rgb(254, 205, 178), bg: Rgb(43, 41, 45), underline: Reset, modifier: NONE,
x: 2, y: 2, fg: Rgb(254, 205, 178), bg: Rgb(43, 41, 45), underline: Reset, modifier: DIM,
x: 10, y: 2, fg: Rgb(254, 205, 178), bg: Rgb(43, 41, 45), underline: Reset, modifier: NONE,
x: 0, y: 4, fg: Rgb(254, 205, 178), bg: Rgb(43, 41, 45), underline: Reset, modifier: BOLD | UNDERLINED,
x: 0, y: 5, fg: Rgb(254, 205, 178), bg: Rgb(43, 41, 45), underline: Reset, modifier: NONE,
x: 0, y: 29, fg: Rgb(224, 107, 117), bg: Rgb(43, 41, 45), underline: Reset, modifier: NONE,
]
}
Loading

0 comments on commit 25641b2

Please sign in to comment.