-
-
Notifications
You must be signed in to change notification settings - Fork 483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: expose court report methods #5590
Conversation
Expose methods in court report context to make unit testing easier. Write additional unit tests. Remove old tests. Remove redundant tests, some behavior is already tested by the Dates object.
# not sure how to test this without just restating the code | ||
# context 'when there are interviewees' do | ||
# it 'it calls CaseContactsContactDates with filtered values' do | ||
# create_list(:case_contact_contact_type, 3, case_contact: create(:case_contact, casa_case: casa_case)) | ||
# context.case_contacts | ||
# end | ||
# end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how best to test the case where there are interviewees, should I even test it?
def case_contacts
cccts = CaseContactContactType.includes(:case_contact, :contact_type).where("case_contacts.casa_case_id": @casa_case.id)
interviewees = filter_out_old_case_contacts(cccts)
return [] unless interviewees.size.positive?
CaseContactsContactDates.new(interviewees).contact_dates_details
end
All this could really test is that the ActiveRecord
query is correct, and its not a very complex query. Is there value in it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am somewhat unclear on what an interviewee is
In general I am in favor of more testing rather than less tho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I am in favor of this but I am nervous about it possibly breaking court report generation somehow
It certainly could be just because the testing around report generation is pretty convoluted. That said these changes still pass all the tests directly related to report generation. In my other PR I test the report like this:
Which imo makes it much easier to be sure we get all the edge cases. Ideally I would like to refactor the whole report test to be of that form. But it's a pretty big shift so idk. |
Context
I will soon need to make a few changes to report generation and the current
CaseCourtReportContext
makes it very difficult to change behavior.The Problem
Currently
CaseCourtReportContext
has a single public method that outputs a very complex object:The hash itself gets built using smaller methods but is tested by creating the full hash then inspecting each key. Ex:
This makes it hard to extend the behavior of the class and write additional tests.
What changed, and why?
This PR reworks some of the methods and tests for
CaseCourtReportContext
.CaseContactsContactDates
.How will this affect user permissions?
None
How is this tested? (please write tests!) 💖💪
Unit tests