-
-
Notifications
You must be signed in to change notification settings - Fork 519
Am exclude from court report issue 6429 #6444
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
Changes from 5 commits
f9cf401
3fe89f1
4131ce2
6646514
de4f9ee
0536e7a
2dc45a0
e3c80f8
de771a9
be9d871
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| class AddExcludeFromCourtReportToContactTopics < ActiveRecord::Migration[7.2] | ||
| def change | ||
| add_column :contact_topics, :exclude_from_court_report, :boolean, default: false, null: false | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -182,6 +182,9 @@ | |
| let(:org) { create(:casa_org) } | ||
| let(:casa_case) { create(:casa_case, casa_org: org) } | ||
| let(:topics) { [1, 2, 3].map { |i| create(:contact_topic, casa_org: org, question: "Question #{i}", details: "Details #{i}") } } | ||
| let(:hidden_topic) do | ||
amuta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| create(:contact_topic, casa_org: org, question: "Dont Show Me", details: "I Shall Not Appear On Court Reports") | ||
| end | ||
| let(:contacts) do | ||
| [1, 2, 3, 4].map do |i| | ||
| create(:case_contact, | ||
|
|
@@ -193,23 +196,9 @@ | |
| ]) | ||
| end | ||
| end | ||
| # let(:contacts) { create_list(:case_contact, 4, casa_case: casa_case, occurred_at: 1.month.ago) } | ||
|
|
||
| context "when given data" do | ||
| # Add some values that should get filtered out | ||
| before do | ||
| contact_one = create(:case_contact, casa_case: casa_case, medium_type: "in-person", occurred_at: 1.day.ago) | ||
| create_list(:contact_topic_answer, 2, case_contact: contact_one, contact_topic: topics[0], value: "Not included") | ||
|
|
||
| contact_two = create(:case_contact, casa_case: casa_case, medium_type: "in-person", occurred_at: 50.day.ago) | ||
| create_list(:contact_topic_answer, 2, case_contact: contact_two, contact_topic: topics[0], value: "Not included") | ||
|
|
||
| other_case = create(:casa_case, casa_org: org) | ||
| contact_three = create(:case_contact, casa_case: other_case, medium_type: "in-person", occurred_at: 50.day.ago) | ||
| create_list(:contact_topic_answer, 2, case_contact: contact_three, contact_topic: topics[0], value: "Not included") | ||
| end | ||
|
|
||
| it "generates correctly shaped data" do | ||
| # Contact 1 Answers | ||
| create(:contact_topic_answer, case_contact: contacts[0], contact_topic: topics[0], value: "Answer 1") | ||
| create(:contact_topic_answer, case_contact: contacts[0], contact_topic: topics[1], value: "Answer 2") | ||
|
|
@@ -222,27 +211,95 @@ | |
| create(:contact_topic_answer, case_contact: contacts[2], contact_topic: topics[1], value: "Answer 5") | ||
| create(:contact_topic_answer, case_contact: contacts[2], contact_topic: topics[2], value: "") | ||
|
|
||
| # Contact 4 Answers | ||
| # No Answers | ||
|
|
||
| expected_topics = { | ||
| "Question 1" => {topic: "Question 1", details: "Details 1", answers: [ | ||
| {date: "12/02/20", medium: "Type A1, Type B1", value: "Answer 1"}, | ||
| {date: "12/03/20", medium: "Type A2, Type B2", value: "Answer 3"} | ||
| ]}, | ||
| "Question 2" => {topic: "Question 2", details: "Details 2", answers: [ | ||
| {date: "12/02/20", medium: "Type A1, Type B1", value: "Answer 2"}, | ||
| {date: "12/04/20", medium: "Type A3, Type B3", value: "Answer 5"} | ||
| ]}, | ||
| "Question 3" => {topic: "Question 3", details: "Details 3", answers: [ | ||
| {date: "12/03/20", medium: "Type A2, Type B2", value: "No Answer Provided"}, | ||
| {date: "12/04/20", medium: "Type A3, Type B3", value: "No Answer Provided"} | ||
| ]} | ||
| # Contacts that will be filtered | ||
| one_day_ago_contact = create(:case_contact, casa_case: casa_case, medium_type: "in-person", occurred_at: 1.day.ago) | ||
| create_list(:contact_topic_answer, 2, case_contact: one_day_ago_contact, contact_topic: topics[0], value: "Answer From One Day Ago") | ||
|
|
||
| one_year_ago_contact = create(:case_contact, casa_case: casa_case, medium_type: "in-person", occurred_at: 1.year.ago) | ||
| create_list(:contact_topic_answer, 2, case_contact: one_year_ago_contact, contact_topic: topics[0], value: "Answer From One Year Ago") | ||
|
|
||
| other_case = create(:casa_case, casa_org: org) | ||
| other_case_contact = create(:case_contact, casa_case: other_case, medium_type: "in-person", occurred_at: 1.month.ago) | ||
| create_list(:contact_topic_answer, 2, case_contact: other_case_contact, contact_topic: topics[0], value: "Answer From Another Case") | ||
| end | ||
|
|
||
| let(:related_topics_hash) do | ||
| { | ||
| "Question 1" => { | ||
| answers: [ | ||
| {date: "01/01/20", medium: "Type 2, Type 2", value: "Answer From One Year Ago"}, | ||
| {date: "12/02/20", medium: "Type A1, Type B1", value: "Answer 1"}, | ||
| {date: "12/03/20", medium: "Type A2, Type B2", value: "Answer 3"}, | ||
| {date: "12/31/20", medium: "Type 1, Type 1", value: "Answer From One Day Ago"} | ||
| ], | ||
| topic: "Question 1", | ||
| details: "Details 1" | ||
| }, | ||
| "Question 2" => { | ||
compwron marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| answers: [ | ||
| {date: "12/02/20", medium: "Type A1, Type B1", value: "Answer 2"}, | ||
| {date: "12/04/20", medium: "Type A3, Type B3", value: "Answer 5"} | ||
| ], | ||
| topic: "Question 2", | ||
| details: "Details 2" | ||
| }, | ||
| "Question 3" => { | ||
| answers: [ | ||
| {date: "12/03/20", medium: "Type A2, Type B2", value: "No Answer Provided"}, | ||
| {date: "12/04/20", medium: "Type A3, Type B3", value: "No Annilswer Provided"} | ||
compwron marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ], | ||
| topic: "Question 3", | ||
| details: "Details 3" | ||
| } | ||
| } | ||
| end | ||
|
|
||
| court_report_context = build(:case_court_report_context, start_date: 45.day.ago.to_s, end_date: 5.day.ago.to_s, casa_case: casa_case) | ||
| it "returns a hash of topics with the correct shape" do | ||
| court_topics = build(:case_court_report_context, casa_case: casa_case).court_topics | ||
|
|
||
| expect(court_topics).to be_a(Hash) | ||
|
|
||
| expect(court_topics.keys).to all(a_kind_of(String)) | ||
| expect(court_topics.values).to all( | ||
| a_hash_including( | ||
| topic: a_kind_of(String), | ||
| details: a_kind_of(String), | ||
| answers: all( | ||
| a_hash_including( | ||
| date: a_string_matching(/\d{2}\/\d{2}\/\d{2}/), | ||
| medium: a_kind_of(String), | ||
| value: a_kind_of(String) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| end | ||
|
|
||
| it "returns topics related to the case" do | ||
| court_topics = build(:case_court_report_context, casa_case: casa_case).court_topics | ||
|
|
||
| expect(court_topics.keys).to match_array(["Question 1", "Question 2", "Question 3"]) | ||
| expect(court_topics["Question 1"][:answers].map { |a| a[:value] }).to match_array( | ||
| ["Answer From One Year Ago", "Answer 1", "Answer 3", "Answer From One Day Ago"] | ||
| ) | ||
| expect(court_topics["Question 2"][:answers].map { |a| a[:value] }).to match_array(["Answer 2", "Answer 5"]) | ||
| expect(court_topics["Question 3"][:answers].map { |a| a[:value] }).to match_array(["No Answer Provided", "No Answer Provided"]) | ||
| end | ||
|
|
||
| it "filters by date range" do | ||
| court_topics = build(:case_court_report_context, start_date: 45.day.ago.to_s, end_date: 5.day.ago.to_s, casa_case: casa_case).court_topics | ||
|
|
||
| expect(court_topics.keys).to match_array(["Question 1", "Question 2", "Question 3"]) | ||
| expect(court_topics["Question 1"][:answers].map { |a| a[:value] }).to match_array(["Answer 1", "Answer 3"]) | ||
| end | ||
|
|
||
| it "filters answers from topics set be excluded from court report" do | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yay tests :) |
||
| topics[0].update(exclude_from_court_report: true) | ||
|
|
||
| court_topics = build(:case_court_report_context, casa_case: casa_case).court_topics | ||
|
|
||
| expect(court_report_context.court_topics).to eq(expected_topics) | ||
| expect(court_topics.keys).not_to include("Question 1") | ||
| expect(court_topics.keys).to include("Question 2", "Question 3") | ||
| end | ||
| end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,17 @@ | |
| post contact_topics_url, params: {contact_topic: attributes} | ||
| expect(response).to redirect_to(edit_casa_org_path(casa_org)) | ||
| end | ||
|
|
||
| it "can set exclude_from_court_report attribute" do | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yay tests :) |
||
| attributes[:exclude_from_court_report] = true | ||
|
|
||
| expect do | ||
| post contact_topics_url, params: {contact_topic: attributes} | ||
| end.to change(ContactTopic, :count).by(1) | ||
|
|
||
| topic = ContactTopic.last | ||
| expect(topic.exclude_from_court_report).to be true | ||
| end | ||
| end | ||
|
|
||
| context "with invalid parameters" do | ||
|
|
@@ -107,6 +118,14 @@ | |
| patch contact_topic_url(contact_topic), params: {contact_topic: new_attributes} | ||
| expect(response).to redirect_to(edit_casa_org_path(casa_org)) | ||
| end | ||
|
|
||
| it "can change exclude_from_court_report" do | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yay tests :) |
||
| new_attributes = {exclude_from_court_report: true} | ||
|
|
||
| expect { | ||
| patch contact_topic_url(contact_topic), params: {contact_topic: new_attributes} | ||
| }.to change { contact_topic.reload.exclude_from_court_report }.from(false).to(true) | ||
| end | ||
| end | ||
|
|
||
| context "with invalid parameters" do | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.