From 04d74f81e4270d9b2f691a1b50d3932a8db68ef8 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 27 Sep 2021 21:45:07 -0400 Subject: [PATCH] Fixing unit tests. --- crates/db_views/src/comment_report_view.rs | 6 +++--- crates/db_views/src/post_report_view.rs | 13 ++++--------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/crates/db_views/src/comment_report_view.rs b/crates/db_views/src/comment_report_view.rs index 753b82fdd..497dec6d6 100644 --- a/crates/db_views/src/comment_report_view.rs +++ b/crates/db_views/src/comment_report_view.rs @@ -122,7 +122,7 @@ impl CommentReportView { .first::(conn)?; let my_vote = if comment_like.is_none() { - Some(0) + None } else { comment_like }; @@ -404,7 +404,7 @@ mod tests { let agg = CommentAggregates::read(&conn, inserted_comment.id).unwrap(); let read_jessica_report_view = - CommentReportView::read(&conn, inserted_jessica_report.id, inserted_jessica.id).unwrap(); + CommentReportView::read(&conn, inserted_jessica_report.id, inserted_timmy.id).unwrap(); let expected_jessica_report_view = CommentReportView { comment_report: inserted_jessica_report.to_owned(), comment: inserted_comment.to_owned(), @@ -519,7 +519,7 @@ mod tests { // Try to resolve the report CommentReport::resolve(&conn, inserted_jessica_report.id, inserted_timmy.id).unwrap(); let read_jessica_report_view_after_resolve = - CommentReportView::read(&conn, inserted_jessica_report.id, inserted_jessica.id).unwrap(); + CommentReportView::read(&conn, inserted_jessica_report.id, inserted_timmy.id).unwrap(); let mut expected_jessica_report_view_after_resolve = expected_jessica_report_view; expected_jessica_report_view_after_resolve diff --git a/crates/db_views/src/post_report_view.rs b/crates/db_views/src/post_report_view.rs index 79a10ac72..b7becdbc5 100644 --- a/crates/db_views/src/post_report_view.rs +++ b/crates/db_views/src/post_report_view.rs @@ -112,13 +112,7 @@ impl PostReportView { )) .first::(conn)?; - // If a person is given, then my_vote, if None, should be 0, not null - // Necessary to differentiate between other person's votes - let my_vote = if post_like.is_none() { - Some(0) - } else { - post_like - }; + let my_vote = if post_like.is_none() { None } else { post_like }; Ok(Self { post_report, @@ -388,7 +382,7 @@ mod tests { let agg = PostAggregates::read(&conn, inserted_post.id).unwrap(); let read_jessica_report_view = - PostReportView::read(&conn, inserted_jessica_report.id, inserted_jessica.id).unwrap(); + PostReportView::read(&conn, inserted_jessica_report.id, inserted_timmy.id).unwrap(); let expected_jessica_report_view = PostReportView { post_report: inserted_jessica_report.to_owned(), post: inserted_post.to_owned(), @@ -466,6 +460,7 @@ mod tests { let mut expected_sara_report_view = expected_jessica_report_view.clone(); expected_sara_report_view.post_report = inserted_sara_report; + expected_sara_report_view.my_vote = None; expected_sara_report_view.creator = PersonSafe { id: inserted_sara.id, name: inserted_sara.name, @@ -506,7 +501,7 @@ mod tests { // Try to resolve the report PostReport::resolve(&conn, inserted_jessica_report.id, inserted_timmy.id).unwrap(); let read_jessica_report_view_after_resolve = - PostReportView::read(&conn, inserted_jessica_report.id, inserted_jessica.id).unwrap(); + PostReportView::read(&conn, inserted_jessica_report.id, inserted_timmy.id).unwrap(); let mut expected_jessica_report_view_after_resolve = expected_jessica_report_view; expected_jessica_report_view_after_resolve