This commit is contained in:
@@ -9,6 +9,24 @@ pub struct Issue {
|
||||
pub body: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
|
||||
pub struct Comment {
|
||||
pub id: u64,
|
||||
pub body: String,
|
||||
#[serde(default)]
|
||||
pub user: Option<CommentUser>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
|
||||
pub struct CommentUser {
|
||||
pub login: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Eq)]
|
||||
pub struct CommentPayload {
|
||||
pub body: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq, Eq)]
|
||||
pub struct CreateIssuePayload {
|
||||
pub title: String,
|
||||
@@ -117,4 +135,24 @@ mod tests {
|
||||
serde_json::json!({"title": "Updated", "body": "Changed"})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serializes_and_deserializes_comment_data() {
|
||||
let comment: Comment = serde_json::from_value(serde_json::json!({
|
||||
"id": 9001,
|
||||
"body": "Investigating",
|
||||
"user": {"login": "alice"}
|
||||
}))
|
||||
.expect("comment JSON");
|
||||
let payload = CommentPayload {
|
||||
body: "Resolved".to_owned(),
|
||||
};
|
||||
|
||||
assert_eq!(comment.id, 9001);
|
||||
assert_eq!(comment.user.expect("comment user").login, "alice");
|
||||
assert_eq!(
|
||||
serde_json::to_value(payload).expect("comment payload"),
|
||||
serde_json::json!({"body": "Resolved"})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user