Skip to content

Commit

Permalink
Expand analyze_commit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 committed Aug 30, 2024
1 parent 5602aa3 commit 92f55ad
Showing 1 changed file with 71 additions and 7 deletions.
78 changes: 71 additions & 7 deletions src/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,17 @@ mod tests {
assert_eq!(changeset.approvals, Vec::<String>::new());
}

#[tokio::test]
async fn analyze_commit() {
fn get_mock_remote() -> Remote<MockClient> {
let mut api_clients = ClientSet::new();
let mut remote = Remote::<MockClient>::parse("https://github.com/example/project.git").unwrap();
api_clients.fill(&mut remote).unwrap();

remote
}

#[tokio::test]
async fn analyze_commit_approved() {
let mut remote = get_mock_remote();
let remote_client = (&mut remote.client).as_ref().unwrap();

remote_client
Expand All @@ -238,14 +243,72 @@ mod tests {
url: "https://github.com/example/project/pulls/1".to_owned(),
}]);

remote_client.pr_reviews.lock().unwrap().insert(1, vec![
Review {
approved: false,
commit_id: "00000000000000000000000000000001".to_owned(),
submitted_at: 42,
user: "user1".to_owned(),
},
Review {
approved: true,
commit_id: "00000000000000000000000000000002".to_owned(),
submitted_at: 42,
user: "user1".to_owned(),
},
]);

remote_client
.pr_head_hash
.lock()
.unwrap()
.insert(1, "00000000000000000000000000000002".to_owned());

let changeset = RepoChangeset::analyze_commit(remote.into(), Commit {
html_url: "https://github.com/example/project/commit/00000000000000000000000000000002".to_owned(),
message: "Testing test".to_owned(),
sha: "00000000000000000000000000000002".to_owned(),
})
.await
.unwrap();

assert_eq!(changeset.len(), 1);
assert_eq!(changeset[0], Changeset {
approvals: vec!["user1".to_owned()],
commits: vec![CommitMetadata {
headline: "Testing test".to_owned(),
link: "https://github.com/example/project/commit/00000000000000000000000000000002".to_owned(),
}],
pr_link: Some("https://github.com/example/project/pulls/1".to_owned()),
});
}

#[tokio::test]
async fn analyze_commit_none() {
let mut remote = get_mock_remote();
let remote_client = (&mut remote.client).as_ref().unwrap();

remote_client
.associated_prs
.lock()
.unwrap()
.insert("00000000000000000000000000000002".to_string(), vec![PullRequest {
number: 1,
url: "https://github.com/example/project/pulls/2".to_owned(),
}]);

remote_client.pr_reviews.lock().unwrap().insert(1, vec![Review {
approved: true,
commit_id: "00000000000000000000000000000002".to_owned(),
approved: false,
commit_id: "00000000000000000000000000000001".to_owned(),
submitted_at: 42,
user: "user1".to_owned(),
}]);

remote_client.pr_head_hash.lock().unwrap().insert(1, "00000000000000000000000000000002".to_owned());
remote_client
.pr_head_hash
.lock()
.unwrap()
.insert(1, "00000000000000000000000000000003".to_owned());

let changeset = RepoChangeset::analyze_commit(remote.into(), Commit {
html_url: "https://github.com/example/project/commit/00000000000000000000000000000002".to_owned(),
Expand All @@ -255,13 +318,14 @@ mod tests {
.await
.unwrap();

assert_eq!(changeset.len(), 1);
assert_eq!(changeset[0], Changeset {
approvals: vec!["user1".to_owned()],
approvals: vec![],
commits: vec![CommitMetadata {
headline: "Testing test".to_owned(),
link: "https://github.com/example/project/commit/00000000000000000000000000000002".to_owned(),
}],
pr_link: Some("https://github.com/example/project/pulls/1".to_owned()),
pr_link: Some("https://github.com/example/project/pulls/2".to_owned()),
});
}
}

0 comments on commit 92f55ad

Please sign in to comment.