diff --git a/crates/radicle-types/src/cobs.rs b/crates/radicle-types/src/cobs.rs index 6b39f4376..5549265b8 100644 --- a/crates/radicle-types/src/cobs.rs +++ b/crates/radicle-types/src/cobs.rs @@ -52,7 +52,7 @@ impl CobOptions { } } -#[derive(Serialize, Deserialize, TS)] +#[derive(Serialize, Deserialize, TS, Debug, PartialEq, Clone)] #[ts(export)] #[ts(export_to = "cob/")] pub struct PaginatedQuery { diff --git a/crates/radicle-types/src/config.rs b/crates/radicle-types/src/config.rs index a1a683f2c..becdb6d45 100644 --- a/crates/radicle-types/src/config.rs +++ b/crates/radicle-types/src/config.rs @@ -6,7 +6,7 @@ use radicle::node::config::DefaultSeedingPolicy; use radicle::node::Alias; /// Service configuration. -#[derive(TS, Serialize)] +#[derive(Debug, TS, Serialize, PartialEq)] #[serde(rename_all = "camelCase")] #[ts(export)] #[ts(export_to = "config/")] diff --git a/crates/radicle-types/src/repo.rs b/crates/radicle-types/src/repo.rs index 0df2eda26..a8717b689 100644 --- a/crates/radicle-types/src/repo.rs +++ b/crates/radicle-types/src/repo.rs @@ -114,7 +114,7 @@ pub struct ProjectPayloadMeta { pub last_commit_timestamp: i64, } -#[derive(Clone, Serialize, TS)] +#[derive(Clone, Serialize, TS, Debug, PartialEq)] #[serde(rename_all = "camelCase")] #[ts(export)] #[ts(export_to = "repo/")] diff --git a/crates/radicle-types/src/traits/repo.rs b/crates/radicle-types/src/traits/repo.rs index 350ef4177..06b1730da 100644 --- a/crates/radicle-types/src/traits/repo.rs +++ b/crates/radicle-types/src/traits/repo.rs @@ -193,3 +193,125 @@ pub trait Repo: Profile { }) } } + +#[cfg(test)] +#[allow(clippy::unwrap_used)] +mod test { + use std::str::FromStr; + + use radicle::crypto::test::signer::MockSigner; + use radicle::{git, test}; + use radicle_surf::Author; + + use crate::cobs; + use crate::repo; + use crate::traits::repo::Repo; + use crate::AppState; + + #[test] + fn list_commits_pagination() { + let signer = MockSigner::from_seed([0xff; 32]); + let tempdir = tempfile::tempdir().unwrap(); + let profile = crate::test::profile(tempdir.path(), [0xff; 32]); + let (rid, _, _, _) = + test::fixtures::project(tempdir.path().join("original"), &profile.storage, &signer) + .unwrap(); + let state = AppState { profile }; + let commits = Repo::list_commits(&state, rid, None, None, Some(1)).unwrap(); + + assert_eq!( + commits, + cobs::PaginatedQuery { + cursor: 0, + more: true, + content: vec![repo::Commit { + id: git::Oid::from_str("f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354").unwrap(), + author: Author { + name: "anonymous".to_string(), + email: "anonymous@radicle.xyz".to_string(), + time: radicle::git::raw::Time::new(1514817556, 0).into(), + }, + committer: Author { + name: "anonymous".to_string(), + email: "anonymous@radicle.xyz".to_string(), + time: radicle::git::raw::Time::new(1514817556, 0).into(), + }, + message: "Second commit".to_string(), + summary: "Second commit".to_string(), + parents: vec![ + git::Oid::from_str("08c788dd1be6315de09e3fe09b5b1b7a2b8711d9").unwrap() + ], + }], + } + ); + + let commits = Repo::list_commits(&state, rid, None, Some(1), None).unwrap(); + + assert_eq!( + commits, + cobs::PaginatedQuery { + cursor: 1, + more: false, + content: vec![repo::Commit { + id: git::Oid::from_str("08c788dd1be6315de09e3fe09b5b1b7a2b8711d9").unwrap(), + author: Author { + name: "anonymous".to_string(), + email: "anonymous@radicle.xyz".to_string(), + time: radicle::git::raw::Time::new(1514817556, 0).into(), + }, + committer: Author { + name: "anonymous".to_string(), + email: "anonymous@radicle.xyz".to_string(), + time: radicle::git::raw::Time::new(1514817556, 0).into(), + }, + message: "Initial commit".to_string(), + summary: "Initial commit".to_string(), + parents: vec![], + }], + } + ); + } + + #[test] + fn list_commits_with_head() { + let signer = MockSigner::from_seed([0xff; 32]); + let tempdir = tempfile::tempdir().unwrap(); + let profile = crate::test::profile(tempdir.path(), [0xff; 32]); + let (rid, _, _, _) = + test::fixtures::project(tempdir.path().join("original"), &profile.storage, &signer) + .unwrap(); + let state = AppState { profile }; + let commits = Repo::list_commits( + &state, + rid, + Some("08c788dd1be6315de09e3fe09b5b1b7a2b8711d9".to_string()), + None, + None, + ) + .unwrap(); + + assert_eq!( + commits, + cobs::PaginatedQuery { + cursor: 0, + more: false, + content: vec![repo::Commit { + id: git::Oid::from_str("08c788dd1be6315de09e3fe09b5b1b7a2b8711d9").unwrap(), + author: Author { + name: "anonymous".to_string(), + email: "anonymous@radicle.xyz".to_string(), + time: radicle::git::raw::Time::new(1514817556, 0).into(), + }, + committer: Author { + name: "anonymous".to_string(), + email: "anonymous@radicle.xyz".to_string(), + time: radicle::git::raw::Time::new(1514817556, 0).into(), + }, + message: "Initial commit".to_string(), + summary: "Initial commit".to_string(), + parents: vec![], + }], + } + ); + } +}