|
193 | 193 | ]) |
194 | 194 | end |
195 | 195 | end |
196 | | - # let(:contacts) { create_list(:case_contact, 4, casa_case: casa_case, occurred_at: 1.month.ago) } |
197 | 196 |
|
198 | 197 | context "when given data" do |
199 | | - # Add some values that should get filtered out |
200 | 198 | before do |
201 | | - contact_one = create(:case_contact, casa_case: casa_case, medium_type: "in-person", occurred_at: 1.day.ago) |
202 | | - create_list(:contact_topic_answer, 2, case_contact: contact_one, contact_topic: topics[0], value: "Not included") |
203 | | - |
204 | | - contact_two = create(:case_contact, casa_case: casa_case, medium_type: "in-person", occurred_at: 50.day.ago) |
205 | | - create_list(:contact_topic_answer, 2, case_contact: contact_two, contact_topic: topics[0], value: "Not included") |
206 | | - |
207 | | - other_case = create(:casa_case, casa_org: org) |
208 | | - contact_three = create(:case_contact, casa_case: other_case, medium_type: "in-person", occurred_at: 50.day.ago) |
209 | | - create_list(:contact_topic_answer, 2, case_contact: contact_three, contact_topic: topics[0], value: "Not included") |
210 | | - end |
211 | | - |
212 | | - it "generates correctly shaped data" do |
213 | 199 | # Contact 1 Answers |
214 | 200 | create(:contact_topic_answer, case_contact: contacts[0], contact_topic: topics[0], value: "Answer 1") |
215 | 201 | create(:contact_topic_answer, case_contact: contacts[0], contact_topic: topics[1], value: "Answer 2") |
|
222 | 208 | create(:contact_topic_answer, case_contact: contacts[2], contact_topic: topics[1], value: "Answer 5") |
223 | 209 | create(:contact_topic_answer, case_contact: contacts[2], contact_topic: topics[2], value: "") |
224 | 210 |
|
225 | | - # Contact 4 Answers |
226 | | - # No Answers |
227 | | - |
228 | | - expected_topics = { |
229 | | - "Question 1" => {topic: "Question 1", details: "Details 1", answers: [ |
230 | | - {date: "12/02/20", medium: "Type A1, Type B1", value: "Answer 1"}, |
231 | | - {date: "12/03/20", medium: "Type A2, Type B2", value: "Answer 3"} |
232 | | - ]}, |
233 | | - "Question 2" => {topic: "Question 2", details: "Details 2", answers: [ |
234 | | - {date: "12/02/20", medium: "Type A1, Type B1", value: "Answer 2"}, |
235 | | - {date: "12/04/20", medium: "Type A3, Type B3", value: "Answer 5"} |
236 | | - ]}, |
237 | | - "Question 3" => {topic: "Question 3", details: "Details 3", answers: [ |
238 | | - {date: "12/03/20", medium: "Type A2, Type B2", value: "No Answer Provided"}, |
239 | | - {date: "12/04/20", medium: "Type A3, Type B3", value: "No Answer Provided"} |
240 | | - ]} |
241 | | - } |
| 211 | + # Contacts that will be filtered |
| 212 | + one_day_ago_contact = create(:case_contact, casa_case: casa_case, medium_type: "in-person", occurred_at: 1.day.ago) |
| 213 | + create_list(:contact_topic_answer, 2, case_contact: one_day_ago_contact, contact_topic: topics[0], value: "Answer From One Day Ago") |
242 | 214 |
|
243 | | - 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) |
| 215 | + one_year_ago_contact = create(:case_contact, casa_case: casa_case, medium_type: "in-person", occurred_at: 1.year.ago) |
| 216 | + create_list(:contact_topic_answer, 2, case_contact: one_year_ago_contact, contact_topic: topics[0], value: "Answer From One Year Ago") |
| 217 | + |
| 218 | + other_case = create(:casa_case, casa_org: org) |
| 219 | + other_case_contact = create(:case_contact, casa_case: other_case, medium_type: "in-person", occurred_at: 1.month.ago) |
| 220 | + create_list(:contact_topic_answer, 2, case_contact: other_case_contact, contact_topic: topics[0], value: "Answer From Another Case") |
| 221 | + end |
| 222 | + |
| 223 | + it "returns a hash of topics with the correct shape" do |
| 224 | + court_topics = build(:case_court_report_context, casa_case: casa_case).court_topics |
| 225 | + |
| 226 | + expect(court_topics).to be_a(Hash) |
| 227 | + |
| 228 | + expect(court_topics.keys).to all(a_kind_of(String)) |
| 229 | + expect(court_topics.values).to all( |
| 230 | + a_hash_including( |
| 231 | + topic: a_kind_of(String), |
| 232 | + details: a_kind_of(String), |
| 233 | + answers: all( |
| 234 | + a_hash_including( |
| 235 | + date: a_string_matching(/\d{2}\/\d{2}\/\d{2}/), |
| 236 | + medium: a_kind_of(String), |
| 237 | + value: a_kind_of(String) |
| 238 | + ) |
| 239 | + ) |
| 240 | + ) |
| 241 | + ) |
| 242 | + end |
| 243 | + |
| 244 | + it "returns topics related to the case" do |
| 245 | + court_topics = build(:case_court_report_context, casa_case: casa_case).court_topics |
| 246 | + |
| 247 | + expect(court_topics.keys).to match_array(["Question 1", "Question 2", "Question 3"]) |
| 248 | + expect(court_topics["Question 1"][:answers].map { |a| a[:value] }).to match_array( |
| 249 | + ["Answer From One Year Ago", "Answer 1", "Answer 3", "Answer From One Day Ago"] |
| 250 | + ) |
| 251 | + expect(court_topics["Question 2"][:answers].map { |a| a[:value] }).to match_array(["Answer 2", "Answer 5"]) |
| 252 | + expect(court_topics["Question 3"][:answers].map { |a| a[:value] }).to match_array(["No Answer Provided", "No Answer Provided"]) |
| 253 | + end |
| 254 | + |
| 255 | + it "filters by date range" do |
| 256 | + 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 |
| 257 | + |
| 258 | + expect(court_topics.keys).to match_array(["Question 1", "Question 2", "Question 3"]) |
| 259 | + expect(court_topics["Question 1"][:answers].map { |a| a[:value] }).to match_array(["Answer 1", "Answer 3"]) |
| 260 | + end |
| 261 | + |
| 262 | + it "filters answers from topics set be excluded from court report" do |
| 263 | + topics[0].update(exclude_from_court_report: true) |
| 264 | + |
| 265 | + court_topics = build(:case_court_report_context, casa_case: casa_case).court_topics |
244 | 266 |
|
245 | | - expect(court_report_context.court_topics).to eq(expected_topics) |
| 267 | + expect(court_topics.keys).not_to include("Question 1") |
| 268 | + expect(court_topics.keys).to include("Question 2", "Question 3") |
246 | 269 | end |
247 | 270 | end |
248 | 271 |
|
|
0 commit comments