Skip to content

Commit e90d80c

Browse files
tegiozcynthia-sg
andauthored
Add participation section to audit page (#659)
Signed-off-by: Sergio Castaño Arteaga <tegioz@icloud.com> Signed-off-by: Cintia Sánchez García <cynthiasg@icloud.com> Co-authored-by: Cintia Sánchez García <cynthiasg@icloud.com>
1 parent 40cdfa7 commit e90d80c

4 files changed

Lines changed: 775 additions & 125 deletions

File tree

src/handlers.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ async fn audit(
111111
return Err(StatusCode::INTERNAL_SERVER_ERROR);
112112
}
113113
};
114-
let template = tmpl::Audit {
115-
repository_full_name,
116-
votes,
117-
};
114+
let template = tmpl::Audit::new(repository_full_name, votes);
118115
match template.render() {
119116
Ok(html) => Ok(Html(html)),
120117
Err(err) => {

src/testutil.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//! This modules defines some test utilities.
22
3-
use std::{collections::BTreeMap, fs, path::Path, time::Duration};
3+
use std::{collections::BTreeMap, fs, path::Path, sync::Arc, time::Duration};
44

55
use time::{OffsetDateTime, format_description::well_known::Rfc3339};
66
use uuid::Uuid;
77

88
use crate::{
99
cfg_repo::{AllowedVoters, Announcements, CfgProfile, DiscussionsAnnouncements},
1010
github::*,
11-
results::{UserVote, Vote, VoteOption, VoteResults},
11+
results::{UserVote, Vote, VoteOption, VoteResults, calculate},
1212
};
1313

1414
pub(crate) const BRANCH: &str = "main";
@@ -178,3 +178,32 @@ pub(crate) fn setup_test_vote_results() -> VoteResults {
178178
pending_voters: vec![],
179179
}
180180
}
181+
182+
pub(crate) fn setup_test_vote_with_calculated_results(
183+
created_at: &str,
184+
allowed_voters: Vec<UserName>,
185+
reactions: Vec<Reaction>,
186+
) -> Vote {
187+
// Setup GitHub mock
188+
let mut gh = MockGH::new();
189+
gh.expect_get_comment_reactions().return_once(move |_, _, _, _| {
190+
Box::pin(async move { Ok::<Vec<Reaction>, anyhow::Error>(reactions) })
191+
});
192+
gh.expect_get_allowed_voters().return_once(move |_, _, _, _, _| {
193+
Box::pin(async move { Ok::<Vec<UserName>, anyhow::Error>(allowed_voters) })
194+
});
195+
196+
// Setup vote
197+
let mut vote = setup_test_vote();
198+
let created_at_ts = OffsetDateTime::parse(created_at, &Rfc3339).expect("valid created_at timestamp");
199+
vote.created_at = created_at_ts;
200+
201+
// Calculate results and attach to vote
202+
let runtime = tokio::runtime::Runtime::new().expect("runtime creation should succeed");
203+
let results = runtime
204+
.block_on(calculate(Arc::new(gh), OWNER, REPO, &vote))
205+
.expect("vote calculation should succeed");
206+
vote.results = Some(results);
207+
208+
vote
209+
}

0 commit comments

Comments
 (0)