feat: implement Comment + tests + test def macro
This commit is contained in:
parent
1d8d9a2d47
commit
81d00564f6
3 changed files with 89 additions and 18 deletions
|
@ -121,3 +121,19 @@ macro_rules! implement_boolean_enum {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Define the macro that generates the deserialization test for a API type
|
||||
#[macro_export]
|
||||
macro_rules! define_deserialize_test {
|
||||
($api_type:ty, $path_to_data:expr) => {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn deserialize() {
|
||||
let data = include_str!($path_to_data);
|
||||
let _: $api_type = serde_json::from_str(data).unwrap();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,18 +1,36 @@
|
|||
// Comment{
|
||||
// description:
|
||||
// Comment represents a comment on a commit or issue
|
||||
//
|
||||
// assets [
|
||||
// x-go-name: Attachments
|
||||
// Attachment{...}]
|
||||
// body string
|
||||
// created_at string($date-time)
|
||||
// html_url string
|
||||
// id integer($int64)
|
||||
// issue_url string
|
||||
// original_author string
|
||||
// original_author_id integer($int64)
|
||||
// pull_request_url string
|
||||
// updated_at string($date-time)
|
||||
// user User{...}
|
||||
// }]
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use url::Url;
|
||||
|
||||
use crate::define_deserialize_test;
|
||||
use crate::types::api::attachment::Attachment;
|
||||
use crate::types::api::user::User;
|
||||
|
||||
/// Represents a comment on a commit or issue.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Comment {
|
||||
/// List of attachments in the comment.
|
||||
pub assets: Vec<Attachment>,
|
||||
/// The body of the comment.
|
||||
pub body: String,
|
||||
/// The date and time when the comment was created.
|
||||
pub created_at: DateTime<Utc>,
|
||||
/// The HTML URL of the comment.
|
||||
pub html_url: Url,
|
||||
/// The unique identifier of the comment.
|
||||
pub id: usize,
|
||||
/// The URL of the issue associated with the comment.
|
||||
pub issue_url: Url,
|
||||
/// The original author of the comment.
|
||||
pub original_author: String,
|
||||
/// The ID of the original author.
|
||||
pub original_author_id: usize,
|
||||
/// The URL of the pull request associated with the comment.
|
||||
pub pull_request_url: Url,
|
||||
/// The date and time when the comment was last updated.
|
||||
pub updated_at: DateTime<Utc>,
|
||||
/// The user who created the comment.
|
||||
pub user: User,
|
||||
}
|
||||
|
||||
define_deserialize_test!(Vec<Comment>, "../../../test_data/example_comment.json");
|
||||
|
|
37
test_data/example_comment.json
Normal file
37
test_data/example_comment.json
Normal file
|
@ -0,0 +1,37 @@
|
|||
[
|
||||
{
|
||||
"assets": [],
|
||||
"body": "This is a comment.",
|
||||
"created_at": "2023-10-21T14:30:00Z",
|
||||
"html_url": "https://example.com/comments/1",
|
||||
"id": 1,
|
||||
"issue_url": "https://example.com/issues/1",
|
||||
"original_author": "original_author",
|
||||
"original_author_id": 123,
|
||||
"pull_request_url": "https://example.com/pull-requests/1",
|
||||
"updated_at": "2023-10-21T14:35:00Z",
|
||||
"user": {
|
||||
"active": true,
|
||||
"avatar_url": "https://codeberg.org/avatars/foo-bar",
|
||||
"created": "2022-11-04T14:41:29Z",
|
||||
"description": "",
|
||||
"email": "example@mail.com",
|
||||
"followers_count": 2,
|
||||
"following_count": 1,
|
||||
"full_name": "",
|
||||
"id": 12345,
|
||||
"is_admin": false,
|
||||
"language": "en-US",
|
||||
"last_login": "2023-07-26T19:38:27Z",
|
||||
"location": "",
|
||||
"login": "ExampleUser",
|
||||
"login_name": "",
|
||||
"prohibit_login": false,
|
||||
"restricted": false,
|
||||
"starred_repos_count": 0,
|
||||
"username": "ExampleUser",
|
||||
"visibility": "public",
|
||||
"website": "https://example.com"
|
||||
}
|
||||
}
|
||||
]
|
Loading…
Reference in a new issue