Skip to content

Commit 724f0c7

Browse files
committed
Add end-to-end test for mentions_in_commits method handler
1 parent e1ede9d commit 724f0c7

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

src/handlers/check_commits/no_mentions.rs

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,44 @@ fn mentions_in_commits_warn(commits: Vec<&str>) -> String {
3535
}
3636

3737
#[test]
38-
fn test_warning_printing() {
39-
let commits_to_warn = vec![
40-
"4d6ze57403udfrzefrfe6574",
41-
"f54efz57405u46z6ef465z4f6ze57",
42-
"404u57403uzf5fe5f4f5e57405u4zf",
43-
];
38+
fn test_mentions_in_commits() {
39+
fn dummy_commit_from_body(sha: &str, body: &str) -> GithubCommit {
40+
use chrono::{DateTime, FixedOffset};
4441

45-
let msg = mentions_in_commits_warn(commits_to_warn);
42+
GithubCommit {
43+
sha: sha.to_string(),
44+
commit: crate::github::GithubCommitCommitField {
45+
author: crate::github::GitUser {
46+
date: DateTime::<FixedOffset>::MIN_UTC.into(),
47+
},
48+
message: body.to_string(),
49+
tree: crate::github::GitCommitTree {
50+
sha: "60ff73dfdd81aa1e6737eb3dacdfd4a141f6e14d".to_string(),
51+
},
52+
},
53+
parents: vec![],
54+
}
55+
}
56+
57+
let mut commits = vec![dummy_commit_from_body(
58+
"d1992a392617dfb10518c3e56446b6c9efae38b0",
59+
"This is simple without mentions!",
60+
)];
61+
62+
assert_eq!(mentions_in_commits(&NoMentionsConfig {}, &commits), None);
63+
64+
commits.push(dummy_commit_from_body(
65+
"d7daa17bc97df9377640b0d33cbd0bbeed703c3a",
66+
"This is a body with a @mention!",
67+
));
4668

4769
assert_eq!(
48-
msg,
49-
r#"There are username mentions (such as `@user`) in the commit messages of the following commits.
70+
mentions_in_commits(&NoMentionsConfig {}, &commits),
71+
Some(
72+
r#"There are username mentions (such as `@user`) in the commit messages of the following commits.
5073
*Please remove the mentions to avoid spamming these users.*
51-
- 4d6ze57403udfrzefrfe6574
52-
- f54efz57405u46z6ef465z4f6ze57
53-
- 404u57403uzf5fe5f4f5e57405u4zf
54-
"#
74+
- d7daa17bc97df9377640b0d33cbd0bbeed703c3a
75+
"#.to_string()
76+
)
5577
);
5678
}

0 commit comments

Comments
 (0)