chore: implement simple serde tests
This commit is contained in:
parent
4961874386
commit
0383b32fdd
8 changed files with 251 additions and 0 deletions
|
@ -28,3 +28,13 @@ impl Display for Attachment {
|
|||
write!(f, "{}", self.name)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn deserialize_multiple_attachments() {
|
||||
let data = include_str!("../../../test_data/example_attachments.json");
|
||||
|
||||
let _: Vec<super::Attachment> = serde_json::from_str(data).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,3 +33,89 @@
|
|||
// url string
|
||||
// user User{...}
|
||||
// }]
|
||||
|
||||
use std::fmt::Display;
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use url::Url;
|
||||
|
||||
use crate::types::api::attachment::Attachment;
|
||||
use crate::types::api::label::Label;
|
||||
use crate::types::api::milestone::Milestone;
|
||||
use crate::types::api::pull_request_meta::PullRequestMeta;
|
||||
use crate::types::api::repo_meta::RepositoryMeta;
|
||||
use crate::types::api::user::User;
|
||||
use crate::types::misc::boolean_enums::is::locked::IsLocked;
|
||||
use crate::types::misc::boolean_enums::state_type::StateType;
|
||||
|
||||
/// Represents an issue in a repository.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Issue {
|
||||
/// List of attachments.
|
||||
pub assets: Vec<Attachment>,
|
||||
/// The user assigned to the issue.
|
||||
pub assignee: Option<User>,
|
||||
/// List of assignees.
|
||||
pub assignees: Vec<User>,
|
||||
/// The body of the issue.
|
||||
pub body: String,
|
||||
/// The date and time when the issue was closed (if closed).
|
||||
pub closed_at: Option<DateTime<Utc>>,
|
||||
/// The number of comments on the issue.
|
||||
pub comments: usize,
|
||||
/// The date and time when the issue was created.
|
||||
pub created_at: DateTime<Utc>,
|
||||
/// The due date of the issue.
|
||||
pub due_date: Option<DateTime<Utc>>,
|
||||
/// The HTML URL of the issue.
|
||||
pub html_url: Url,
|
||||
/// The unique identifier of the issue.
|
||||
pub id: usize,
|
||||
/// Indicates whether the issue is locked.
|
||||
pub is_locked: IsLocked,
|
||||
/// List of labels associated with the issue.
|
||||
pub labels: Vec<Label>,
|
||||
/// The milestone associated with the issue.
|
||||
pub milestone: Option<Milestone>,
|
||||
/// The issue number.
|
||||
pub number: usize,
|
||||
/// The original author of the issue.
|
||||
pub original_author: String,
|
||||
/// The ID of the original author.
|
||||
pub original_author_id: usize,
|
||||
/// Pull request information for the issue.
|
||||
pub pull_request: Option<PullRequestMeta>,
|
||||
/// The reference for the issue.
|
||||
pub ref_field: String,
|
||||
/// Metadata for the repository.
|
||||
pub repository: RepositoryMeta,
|
||||
/// The state of the issue.
|
||||
pub state: StateType,
|
||||
/// The title of the issue.
|
||||
pub title: String,
|
||||
/// The date and time when the issue was last updated.
|
||||
pub updated_at: DateTime<Utc>,
|
||||
/// The URL of the issue.
|
||||
pub url: Url,
|
||||
/// The user who created the issue.
|
||||
pub user: User,
|
||||
}
|
||||
|
||||
impl Display for Issue {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.title)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::types::api::issue::Issue;
|
||||
|
||||
#[test]
|
||||
fn deserialize_issue() {
|
||||
let data = include_str!("../../../test_data/example_issue.json");
|
||||
|
||||
let _: Issue = serde_json::from_str(data).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,3 +11,13 @@ pub struct PullRequestMeta {
|
|||
/// The date and time when the PR was merged (if merged).
|
||||
pub merged_at: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn deserialize_pull_request_meta() {
|
||||
let json_response = include_str!("../../../test_data/example_pull_request_meta.json");
|
||||
|
||||
let _: super::PullRequestMeta = serde_json::from_str(json_response).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,3 +20,13 @@ impl Display for RepositoryMeta {
|
|||
write!(f, "{}", self.full_name)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn deserialize_repo_meta() {
|
||||
let data = include_str!("../../../test_data/example_repo_meta.json");
|
||||
|
||||
let _: super::RepositoryMeta = serde_json::from_str(data).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
20
test_data/example_attachments.json
Normal file
20
test_data/example_attachments.json
Normal file
|
@ -0,0 +1,20 @@
|
|||
[
|
||||
{
|
||||
"browser_download_url": "https://example.com/attachment1",
|
||||
"created_at": "2023-10-21T14:30:00Z",
|
||||
"download_count": 100,
|
||||
"id": 1,
|
||||
"name": "attachment1",
|
||||
"size": 1024,
|
||||
"uuid": "abc123"
|
||||
},
|
||||
{
|
||||
"browser_download_url": "https://example.com/attachment2",
|
||||
"created_at": "2023-10-21T14:45:00Z",
|
||||
"download_count": 50,
|
||||
"id": 2,
|
||||
"name": "attachment2",
|
||||
"size": 2048,
|
||||
"uuid": "def456"
|
||||
}
|
||||
]
|
105
test_data/example_issue.json
Normal file
105
test_data/example_issue.json
Normal file
|
@ -0,0 +1,105 @@
|
|||
{
|
||||
"assets": [
|
||||
{
|
||||
"browser_download_url": "https://example.com/attachment1",
|
||||
"created_at": "2023-10-21T14:30:00Z",
|
||||
"download_count": 100,
|
||||
"id": 1,
|
||||
"name": "attachment1",
|
||||
"size": 1024,
|
||||
"uuid": "abc123"
|
||||
},
|
||||
{
|
||||
"browser_download_url": "https://example.com/attachment2",
|
||||
"created_at": "2023-10-21T14:45:00Z",
|
||||
"download_count": 50,
|
||||
"id": 2,
|
||||
"name": "attachment2",
|
||||
"size": 2048,
|
||||
"uuid": "def456"
|
||||
}
|
||||
],
|
||||
"assignee": null,
|
||||
"assignees": [
|
||||
{
|
||||
"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"
|
||||
}
|
||||
],
|
||||
"body": "Issue body text",
|
||||
"closed_at": null,
|
||||
"comments": 0,
|
||||
"created_at": "2023-10-21T14:30:00Z",
|
||||
"due_date": null,
|
||||
"html_url": "https://example.com/issues/1",
|
||||
"id": 1,
|
||||
"is_locked": false,
|
||||
"labels": [
|
||||
{
|
||||
"color": "00aabb",
|
||||
"description": "Label a label to an issue or a pr",
|
||||
"exclusive": false,
|
||||
"id": 42,
|
||||
"name": "bug",
|
||||
"url": "https://example.com/labels/bug"
|
||||
}
|
||||
],
|
||||
"milestone": null,
|
||||
"number": 1,
|
||||
"original_author": "original_author",
|
||||
"original_author_id": 123,
|
||||
"pull_request": null,
|
||||
"ref_field": "refs/1",
|
||||
"repository": {
|
||||
"full_name": "exampleuser/example-repo",
|
||||
"id": 123,
|
||||
"name": "example-repo",
|
||||
"owner": "exampleuser"
|
||||
},
|
||||
"state": "Open",
|
||||
"title": "Example Issue",
|
||||
"updated_at": "2023-10-21T14:30:00Z",
|
||||
"url": "https://example.com/issues/1",
|
||||
"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"
|
||||
}
|
||||
}
|
4
test_data/example_pull_request_meta.json
Normal file
4
test_data/example_pull_request_meta.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"merged": true,
|
||||
"merged_at": "2023-10-21T14:30:00Z"
|
||||
}
|
6
test_data/example_repo_meta.json
Normal file
6
test_data/example_repo_meta.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"full_name": "exampleuser/example-repo",
|
||||
"id": 123,
|
||||
"name": "example-repo",
|
||||
"owner": "exampleuser"
|
||||
}
|
Loading…
Reference in a new issue