59 lines
1.9 KiB
Rust
59 lines
1.9 KiB
Rust
use gitea_pr_review::model::{
|
|
CommentItem, CommentThread, DiffStat, FileStat, PrMeta, PrReviewDocument,
|
|
};
|
|
|
|
#[test]
|
|
fn model_json_roundtrip() {
|
|
let doc = PrReviewDocument {
|
|
version: "v1".into(),
|
|
meta: PrMeta {
|
|
repo: "org/repo".into(),
|
|
pr_index: 9,
|
|
title: "feat: x".into(),
|
|
description: Some("desc".into()),
|
|
fetched_at: "2026-04-08T12:34:56Z".into(),
|
|
state: "open".into(),
|
|
author: "alice".into(),
|
|
base_branch: "main".into(),
|
|
head_branch: "feature/x".into(),
|
|
created_at: "2026-04-08T10:00:00Z".into(),
|
|
updated_at: "2026-04-08T11:00:00Z".into(),
|
|
merged_at: None,
|
|
},
|
|
commits: vec![],
|
|
diff_stat: DiffStat {
|
|
files_changed: 1,
|
|
additions: 2,
|
|
deletions: 1,
|
|
files: vec![FileStat {
|
|
path: "src/main.rs".into(),
|
|
additions: 2,
|
|
deletions: 1,
|
|
}],
|
|
},
|
|
reviews: vec![],
|
|
threads: vec![CommentThread {
|
|
thread_id: "t1".into(),
|
|
file_path: Some("src/main.rs".into()),
|
|
line: Some(10),
|
|
root_comment: CommentItem {
|
|
id: 100,
|
|
review_id: Some(1),
|
|
user: "reviewer".into(),
|
|
created_at: "2026-04-08T12:00:00Z".into(),
|
|
path: Some("src/main.rs".into()),
|
|
line: Some(10),
|
|
body: "hello".into(),
|
|
},
|
|
replies: vec![],
|
|
}],
|
|
};
|
|
|
|
let encoded = serde_json::to_string(&doc).unwrap();
|
|
let decoded: PrReviewDocument = serde_json::from_str(&encoded).unwrap();
|
|
assert_eq!(decoded.version, "v1");
|
|
assert_eq!(decoded.meta.repo, "org/repo");
|
|
assert_eq!(decoded.meta.fetched_at, "2026-04-08T12:34:56Z");
|
|
assert_eq!(decoded.threads[0].root_comment.body, "hello");
|
|
}
|