Skip to content

Commit 70a5986

Browse files
committed
tests: proposal_review_summary_markdown function unit tests
1 parent 41ccfa6 commit 70a5986

4 files changed

Lines changed: 135 additions & 8 deletions

File tree

src/backend/impl/src/fixtures/commit_sha.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ pub fn commit_sha_a() -> CommitSha {
1111
pub fn commit_sha_b() -> CommitSha {
1212
CommitSha::try_from("47d98477c6c59e570e2220aab433b0943b326ef8").unwrap()
1313
}
14+
15+
#[fixture]
16+
pub fn commit_sha_c() -> CommitSha {
17+
CommitSha::try_from("e62e328fa193e73fbb7562458d719f311c25d455").unwrap()
18+
}

src/backend/impl/src/repositories/types/proposal_review_commit.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,19 @@ mod tests {
209209
}
210210

211211
#[rstest]
212-
fn display_impl() {
212+
fn reviewed_commit_state_display_impl() {
213213
let mut state = ReviewedCommitState {
214-
matches_description: Some(true),
214+
matches_description: None,
215215
comment: None,
216216
highlights: vec![],
217217
};
218218

219+
assert_eq!(state.to_string(), "Matches description: false");
220+
221+
state.matches_description = Some(false);
222+
assert_eq!(state.to_string(), "Matches description: false");
223+
224+
state.matches_description = Some(true);
219225
assert_eq!(state.to_string(), "Matches description: true");
220226

221227
state.comment = Some("".to_string());

src/backend/impl/src/services/proposal_review_service.rs

Lines changed: 118 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -770,19 +770,22 @@ fn proposal_review_summary_markdown(
770770
{
771771
if !reviewed_commits.is_empty() {
772772
md_content.push_str("\nCommits review:\n");
773+
774+
const INDENT: &str = " ";
775+
773776
let mut commits_list = String::new();
774777
for (_, commit) in reviewed_commits {
775778
if let Some(state) = commit.reviewed_state() {
776779
let mut commit_sha = commit.commit_sha.to_string();
777780
commit_sha.truncate(9);
778781
commits_list.push_str(&format!(
779-
"- **{}**:\n\t{}\n",
782+
"- **{}**:\n{INDENT}{}\n",
780783
commit_sha,
781784
state
782785
.to_string()
783786
.lines()
784787
.collect::<Vec<&str>>()
785-
.join("\n\t")
788+
.join(&format!("\n{INDENT}"))
786789
));
787790
}
788791
}
@@ -801,7 +804,8 @@ mod tests {
801804
repositories::{
802805
ImageId, MockCertificationRepository, MockImageRepository, MockProposalRepository,
803806
MockProposalReviewCommitRepository, MockProposalReviewRepository,
804-
MockUserProfileRepository, ProposalReviewId, IMAGES_BASE_PATH,
807+
MockUserProfileRepository, NervousSystem, ProposalReviewId, ReviewCommitState,
808+
ReviewedCommitState, IMAGES_BASE_PATH,
805809
},
806810
};
807811
use backend_api::{
@@ -2463,4 +2467,115 @@ mod tests {
24632467
),
24642468
)
24652469
}
2470+
2471+
#[fixture]
2472+
fn basic_proposal() -> Proposal {
2473+
let proposal = fixtures::nns_replica_version_management_proposal(None, None);
2474+
Proposal {
2475+
nervous_system: match proposal.nervous_system {
2476+
NervousSystem::Network { proposal_info, .. } => NervousSystem::Network {
2477+
proposal_id: 123,
2478+
proposal_info,
2479+
},
2480+
},
2481+
..proposal
2482+
}
2483+
}
2484+
2485+
#[fixture]
2486+
fn basic_review() -> ProposalReview {
2487+
ProposalReview {
2488+
vote: ProposalVote::Yes,
2489+
summary: Some("Test summary".to_string()),
2490+
build_reproduced: Some(true),
2491+
..fixtures::proposal_review_published()
2492+
}
2493+
}
2494+
2495+
#[fixture]
2496+
fn reviewed_commits() -> Vec<(ProposalReviewCommitId, ProposalReviewCommit)> {
2497+
vec![
2498+
(
2499+
fixtures::uuid(),
2500+
ProposalReviewCommit {
2501+
commit_sha: fixtures::commit_sha_a(),
2502+
state: ReviewCommitState::Reviewed(ReviewedCommitState {
2503+
matches_description: Some(true),
2504+
comment: Some("Good commit".to_string()),
2505+
highlights: vec!["Feature A".to_string(), "Bug fix B".to_string()],
2506+
}),
2507+
..fixtures::proposal_review_commit_reviewed()
2508+
},
2509+
),
2510+
(
2511+
fixtures::uuid(),
2512+
ProposalReviewCommit {
2513+
commit_sha: fixtures::commit_sha_b(),
2514+
state: ReviewCommitState::Reviewed(ReviewedCommitState {
2515+
matches_description: Some(false),
2516+
comment: Some("Issues found".to_string()),
2517+
highlights: vec!["Missing tests".to_string()],
2518+
}),
2519+
..fixtures::proposal_review_commit_reviewed()
2520+
},
2521+
),
2522+
(
2523+
fixtures::uuid(),
2524+
ProposalReviewCommit {
2525+
commit_sha: fixtures::commit_sha_c(),
2526+
state: ReviewCommitState::NotReviewed,
2527+
..fixtures::proposal_review_commit_reviewed()
2528+
},
2529+
),
2530+
]
2531+
}
2532+
2533+
#[fixture]
2534+
fn images_paths() -> Vec<String> {
2535+
vec![
2536+
"/images/13449503-1b2f-4b92-8346-8e843253e842.png".to_string(),
2537+
"/images/68362227-6f0f-4fb4-b80a-0bfa53a9e99b.png".to_string(),
2538+
]
2539+
}
2540+
2541+
#[rstest]
2542+
fn test_proposal_review_summary_markdown() {
2543+
let basic_proposal = basic_proposal();
2544+
let basic_review = basic_review();
2545+
let reviewed_commits = reviewed_commits();
2546+
let images_paths = images_paths();
2547+
let markdown = proposal_review_summary_markdown(
2548+
&basic_proposal,
2549+
&basic_review,
2550+
&reviewed_commits,
2551+
&images_paths,
2552+
);
2553+
2554+
assert_eq!(
2555+
markdown,
2556+
r#"# Proposal 123
2557+
2558+
Vote: ADOPTED
2559+
Hashes match: true
2560+
All reviewed commits match their descriptions: false
2561+
2562+
![](/images/13449503-1b2f-4b92-8346-8e843253e842.png)
2563+
2564+
![](/images/68362227-6f0f-4fb4-b80a-0bfa53a9e99b.png)
2565+
2566+
Summary:
2567+
Test summary
2568+
2569+
Commits review:
2570+
- **28111ed23**:
2571+
Matches description: true
2572+
Comment: Good commit
2573+
Highlights: Feature A, Bug fix B
2574+
- **47d98477c**:
2575+
Matches description: false
2576+
Comment: Issues found
2577+
Highlights: Missing tests
2578+
"#
2579+
);
2580+
}
24662581
}

src/backend/integration/src/tests/get_my_proposal_review_summary.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,17 @@ describe('get my proposal review summary', () => {
140140
expectedMarkdown += `\nSummary:\n${proposalReview.summary[0]}\n`;
141141
expectedMarkdown += '\nCommits review:\n';
142142

143+
const INDENT = ' ';
143144
for (const {
144145
proposal_review_commit: commit,
145146
} of proposalReview.proposal_review_commits) {
146147
if ('reviewed' in commit.state) {
147-
let commitReview = `\tMatches description: ${commit.state.reviewed.matches_description}`;
148+
let commitReview = `${INDENT}Matches description: ${commit.state.reviewed.matches_description}`;
148149
if (commit.state.reviewed.comment) {
149-
commitReview += `\n\tComment: ${commit.state.reviewed.comment}`;
150+
commitReview += `\n${INDENT}Comment: ${commit.state.reviewed.comment}`;
150151
}
151152
if (commit.state.reviewed.highlights.length > 0) {
152-
commitReview += `\n\tHighlights: ${commit.state.reviewed.highlights.join(', ')}`;
153+
commitReview += `\n${INDENT}Highlights: ${commit.state.reviewed.highlights.join(', ')}`;
153154
}
154155
expectedMarkdown += `- **${commit.commit_sha.slice(0, 9)}**:\n${commitReview}\n`;
155156
}

0 commit comments

Comments
 (0)