|
116 | 116 | end |
117 | 117 | end |
118 | 118 |
|
| 119 | + context "with additional_filters" do |
| 120 | + let!(:other_case) { create(:casa_case, casa_org: organization) } |
| 121 | + let(:contact_type) { create(:contact_type) } |
| 122 | + |
| 123 | + def post_with_filters(filters) |
| 124 | + post datatable_case_contacts_new_design_path, |
| 125 | + params: datatable_params.merge(additional_filters: filters), |
| 126 | + as: :json |
| 127 | + end |
| 128 | + |
| 129 | + def ids |
| 130 | + JSON.parse(response.body, symbolize_names: true)[:data].pluck(:id) |
| 131 | + end |
| 132 | + |
| 133 | + it "filters by occurred_starting_at" do |
| 134 | + old_contact = create(:case_contact, :active, casa_case: casa_case, occurred_at: 2.weeks.ago) |
| 135 | + |
| 136 | + post_with_filters(occurred_starting_at: 1.week.ago.to_date.to_s) |
| 137 | + |
| 138 | + expect(ids).to include(case_contact.id.to_s) |
| 139 | + expect(ids).not_to include(old_contact.id.to_s) |
| 140 | + end |
| 141 | + |
| 142 | + it "filters by occurred_ending_at" do |
| 143 | + old_contact = create(:case_contact, :active, casa_case: casa_case, occurred_at: 2.weeks.ago) |
| 144 | + recent_contact = create(:case_contact, :active, casa_case: casa_case, occurred_at: Time.zone.today) |
| 145 | + |
| 146 | + post_with_filters(occurred_ending_at: 1.week.ago.to_date.to_s) |
| 147 | + |
| 148 | + expect(ids).to include(old_contact.id.to_s) |
| 149 | + expect(ids).not_to include(recent_contact.id.to_s) |
| 150 | + end |
| 151 | + |
| 152 | + it "filters by casa_case_ids" do |
| 153 | + other_contact = create(:case_contact, :active, casa_case: other_case) |
| 154 | + |
| 155 | + post_with_filters(casa_case_ids: [casa_case.id.to_s]) |
| 156 | + |
| 157 | + expect(ids).to include(case_contact.id.to_s) |
| 158 | + expect(ids).not_to include(other_contact.id.to_s) |
| 159 | + end |
| 160 | + |
| 161 | + it "filters by contact_type_ids" do |
| 162 | + matching_contact = create(:case_contact, :active, casa_case: casa_case, contact_types: [contact_type]) |
| 163 | + non_matching_contact = create(:case_contact, :active, casa_case: casa_case, contact_types: [create(:contact_type)]) |
| 164 | + |
| 165 | + post_with_filters(contact_type_ids: [contact_type.id.to_s]) |
| 166 | + |
| 167 | + expect(ids).to include(matching_contact.id.to_s) |
| 168 | + expect(ids).not_to include(non_matching_contact.id.to_s) |
| 169 | + end |
| 170 | + |
| 171 | + it "filters by contact_medium" do |
| 172 | + in_person_contact = create(:case_contact, :active, casa_case: casa_case, medium_type: CaseContact::IN_PERSON) |
| 173 | + video_contact = create(:case_contact, :active, casa_case: casa_case, medium_type: CaseContact::VIDEO) |
| 174 | + |
| 175 | + post_with_filters(contact_medium: CaseContact::IN_PERSON) |
| 176 | + |
| 177 | + expect(ids).to include(in_person_contact.id.to_s) |
| 178 | + expect(ids).not_to include(video_contact.id.to_s) |
| 179 | + end |
| 180 | + |
| 181 | + it "filters by contact_made true" do |
| 182 | + reached_contact = create(:case_contact, :active, casa_case: casa_case, contact_made: true) |
| 183 | + not_reached_contact = create(:case_contact, :active, casa_case: casa_case, contact_made: false) |
| 184 | + |
| 185 | + post_with_filters(contact_made: "true") |
| 186 | + |
| 187 | + expect(ids).to include(reached_contact.id.to_s) |
| 188 | + expect(ids).not_to include(not_reached_contact.id.to_s) |
| 189 | + end |
| 190 | + |
| 191 | + it "filters by contact_made false" do |
| 192 | + reached_contact = create(:case_contact, :active, casa_case: casa_case, contact_made: true) |
| 193 | + not_reached_contact = create(:case_contact, :active, casa_case: casa_case, contact_made: false) |
| 194 | + |
| 195 | + post_with_filters(contact_made: "false") |
| 196 | + |
| 197 | + expect(ids).to include(not_reached_contact.id.to_s) |
| 198 | + expect(ids).not_to include(reached_contact.id.to_s) |
| 199 | + end |
| 200 | + |
| 201 | + it "filters by no_drafts" do |
| 202 | + active_contact = create(:case_contact, :active, casa_case: casa_case) |
| 203 | + draft_contact = create(:case_contact, casa_case: casa_case, status: "started") |
| 204 | + |
| 205 | + post_with_filters(no_drafts: "1") |
| 206 | + |
| 207 | + expect(ids).to include(active_contact.id.to_s) |
| 208 | + expect(ids).not_to include(draft_contact.id.to_s) |
| 209 | + end |
| 210 | + |
| 211 | + it "combines multiple filters with AND logic" do |
| 212 | + matching = create(:case_contact, :active, |
| 213 | + casa_case: casa_case, |
| 214 | + medium_type: CaseContact::IN_PERSON, |
| 215 | + occurred_at: 2.days.ago) |
| 216 | + wrong_medium = create(:case_contact, :active, |
| 217 | + casa_case: casa_case, |
| 218 | + medium_type: CaseContact::VIDEO, |
| 219 | + occurred_at: 2.days.ago) |
| 220 | + wrong_case = create(:case_contact, :active, |
| 221 | + casa_case: other_case, |
| 222 | + medium_type: CaseContact::IN_PERSON, |
| 223 | + occurred_at: 2.days.ago) |
| 224 | + |
| 225 | + post_with_filters( |
| 226 | + casa_case_ids: [casa_case.id.to_s], |
| 227 | + contact_medium: CaseContact::IN_PERSON |
| 228 | + ) |
| 229 | + |
| 230 | + expect(ids).to include(matching.id.to_s) |
| 231 | + expect(ids).not_to include(wrong_medium.id.to_s) |
| 232 | + expect(ids).not_to include(wrong_case.id.to_s) |
| 233 | + end |
| 234 | + end |
| 235 | + |
119 | 236 | context "when user is a volunteer" do |
120 | 237 | let(:volunteer) { create(:volunteer, casa_org: organization) } |
121 | 238 |
|
|
0 commit comments