Fixing unit tests.

This commit is contained in:
Dessalines 2021-09-27 21:45:07 -04:00
parent 51c9e47f16
commit 04d74f81e4
2 changed files with 7 additions and 12 deletions

View file

@ -122,7 +122,7 @@ impl CommentReportView {
.first::<CommentReportViewTuple>(conn)?; .first::<CommentReportViewTuple>(conn)?;
let my_vote = if comment_like.is_none() { let my_vote = if comment_like.is_none() {
Some(0) None
} else { } else {
comment_like comment_like
}; };
@ -404,7 +404,7 @@ mod tests {
let agg = CommentAggregates::read(&conn, inserted_comment.id).unwrap(); let agg = CommentAggregates::read(&conn, inserted_comment.id).unwrap();
let read_jessica_report_view = 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 { let expected_jessica_report_view = CommentReportView {
comment_report: inserted_jessica_report.to_owned(), comment_report: inserted_jessica_report.to_owned(),
comment: inserted_comment.to_owned(), comment: inserted_comment.to_owned(),
@ -519,7 +519,7 @@ mod tests {
// Try to resolve the report // Try to resolve the report
CommentReport::resolve(&conn, inserted_jessica_report.id, inserted_timmy.id).unwrap(); CommentReport::resolve(&conn, inserted_jessica_report.id, inserted_timmy.id).unwrap();
let read_jessica_report_view_after_resolve = 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; let mut expected_jessica_report_view_after_resolve = expected_jessica_report_view;
expected_jessica_report_view_after_resolve expected_jessica_report_view_after_resolve

View file

@ -112,13 +112,7 @@ impl PostReportView {
)) ))
.first::<PostReportViewTuple>(conn)?; .first::<PostReportViewTuple>(conn)?;
// If a person is given, then my_vote, if None, should be 0, not null let my_vote = if post_like.is_none() { None } else { post_like };
// Necessary to differentiate between other person's votes
let my_vote = if post_like.is_none() {
Some(0)
} else {
post_like
};
Ok(Self { Ok(Self {
post_report, post_report,
@ -388,7 +382,7 @@ mod tests {
let agg = PostAggregates::read(&conn, inserted_post.id).unwrap(); let agg = PostAggregates::read(&conn, inserted_post.id).unwrap();
let read_jessica_report_view = 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 { let expected_jessica_report_view = PostReportView {
post_report: inserted_jessica_report.to_owned(), post_report: inserted_jessica_report.to_owned(),
post: inserted_post.to_owned(), post: inserted_post.to_owned(),
@ -466,6 +460,7 @@ mod tests {
let mut expected_sara_report_view = expected_jessica_report_view.clone(); let mut expected_sara_report_view = expected_jessica_report_view.clone();
expected_sara_report_view.post_report = inserted_sara_report; expected_sara_report_view.post_report = inserted_sara_report;
expected_sara_report_view.my_vote = None;
expected_sara_report_view.creator = PersonSafe { expected_sara_report_view.creator = PersonSafe {
id: inserted_sara.id, id: inserted_sara.id,
name: inserted_sara.name, name: inserted_sara.name,
@ -506,7 +501,7 @@ mod tests {
// Try to resolve the report // Try to resolve the report
PostReport::resolve(&conn, inserted_jessica_report.id, inserted_timmy.id).unwrap(); PostReport::resolve(&conn, inserted_jessica_report.id, inserted_timmy.id).unwrap();
let read_jessica_report_view_after_resolve = 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; let mut expected_jessica_report_view_after_resolve = expected_jessica_report_view;
expected_jessica_report_view_after_resolve expected_jessica_report_view_after_resolve