Radish alpha
r
Radicle desktop app
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add tests for `list_commits` unit test
Sebastian Martinez committed 1 year ago
commit 1f779a8a1bf396c865e3c2d5563d0d24faab51f9
parent 70ee53e859a3ebd86ccc79dfc2da595a3d35788c
4 files changed +125 -3
modified 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<T> {
modified 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/")]
modified 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/")]
modified 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![],
+
                }],
+
            }
+
        );
+
    }
+
}