|
4 | 4 | require "sablon" |
5 | 5 |
|
6 | 6 | RSpec.describe CaseCourtReport, type: :model do |
| 7 | + include DownloadHelpers |
7 | 8 | let(:path_to_template) { Rails.root.join("app", "documents", "templates", "default_report_template.docx").to_s } |
8 | 9 | let(:path_to_report) { Rails.root.join("tmp", "test_report.docx").to_s } |
9 | 10 |
|
|
107 | 108 | let(:contact_type) { create(:contact_type, name: document_data[:case_contact_type]) } |
108 | 109 | let(:case_contact) { create(:case_contact, contact_made: false, occurred_at: document_data[:case_contact_time]) } |
109 | 110 | let(:court_order) { create(:case_court_order, implementation_status: :partially_implemented) } |
110 | | - let(:document_inspector) { DocxInspector.new(docx_contents: report.generate_to_string) } |
111 | 111 |
|
112 | 112 | before(:each) do |
113 | 113 | casa_case_with_contacts.casa_org.update_attribute(:address, document_data[:org_address]) |
|
124 | 124 | end |
125 | 125 |
|
126 | 126 | it "displays the org address" do |
127 | | - expect(document_inspector.word_list_header_contains?(document_data[:org_address])).to eq(true) |
| 127 | + docx_response = Docx::Document.open(StringIO.new(report.generate_to_string)) |
| 128 | + expect(header_text(docx_response)).to include(document_data[:org_address]) |
128 | 129 | end |
129 | 130 |
|
130 | 131 | it "displays today's date formatted" do |
131 | | - expect(document_inspector.word_list_document_contains?(Date.current.strftime("%B %-d, %Y"))).to eq(true) |
| 132 | + docx_response = Docx::Document.open(StringIO.new(report.generate_to_string)) |
| 133 | + expect(docx_response.paragraphs.map(&:to_s)).to include(/#{Date.current.strftime("%B %-d, %Y")}.*/) |
132 | 134 | end |
133 | 135 |
|
134 | 136 | it "displays the case hearing date date formatted" do |
135 | | - expect(document_inspector.word_list_document_contains?(document_data[:case_hearing_date].strftime("%B %-d, %Y"))).to eq(true) |
| 137 | + docx_response = Docx::Document.open(StringIO.new(report.generate_to_string)) |
| 138 | + expect(docx_response.paragraphs.map(&:to_s)).to include(/#{document_data[:case_hearing_date].strftime("%B %-d, %Y")}.*/) |
136 | 139 | end |
137 | 140 |
|
138 | 141 | it "displays the case number" do |
139 | | - expect(document_inspector.word_list_document_contains?(document_data[:case_number])).to eq(true) |
| 142 | + docx_response = Docx::Document.open(StringIO.new(report.generate_to_string)) |
| 143 | + expect(docx_response.paragraphs.map(&:to_s)).to include(/#{document_data[:case_number]}.*/) |
140 | 144 | end |
141 | 145 |
|
142 | | - it "displays th case contact type" do |
143 | | - expect(document_inspector.word_list_document_contains?(document_data[:case_contact_type])).to eq(true) |
| 146 | + it "displays the case contact type" do |
| 147 | + docx_response = Docx::Document.open(StringIO.new(report.generate_to_string)) |
| 148 | + |
| 149 | + table_data = docx_response.tables.map { |t| t.rows.map(&:cells).flatten.map(&:to_s) }.flatten |
| 150 | + |
| 151 | + expect(table_data).to include(/#{document_data[:case_contact_type]}.*/) |
144 | 152 | end |
145 | 153 |
|
146 | | - it "displays the case contact tiime date formatted" do |
147 | | - expect(document_inspector.word_list_document_contains?("#{document_data[:case_contact_time].strftime("%-m/%d")}*")).to eq(true) |
| 154 | + it "displays the case contact time date formatted" do |
| 155 | + docx_response = Docx::Document.open(StringIO.new(report.generate_to_string)) |
| 156 | + |
| 157 | + table_data = docx_response.tables.map { |t| t.rows.map(&:cells).flatten.map(&:to_s) }.flatten |
| 158 | + |
| 159 | + expect(table_data).to include(/#{document_data[:case_contact_time].strftime("%-m/%d")}.*/) |
148 | 160 | end |
149 | 161 |
|
150 | 162 | it "displays the text" do |
151 | | - expect(document_inspector.word_list_document_contains?(document_data[:text])).to eq(true) |
| 163 | + docx_response = Docx::Document.open(StringIO.new(report.generate_to_string)) |
| 164 | + |
| 165 | + table_data = docx_response.tables.map { |t| t.rows.map(&:cells).flatten.map(&:to_s) }.flatten |
| 166 | + |
| 167 | + expect(table_data).to include(/#{document_data[:text]}.*/) |
152 | 168 | end |
153 | 169 |
|
154 | 170 | it "displays the order status" do |
155 | | - expect(document_inspector.word_list_document_contains?("Partially implemented")).to eq(true) # Order Status |
| 171 | + docx_response = Docx::Document.open(StringIO.new(report.generate_to_string)) |
| 172 | + |
| 173 | + table_data = docx_response.tables.map { |t| t.rows.map(&:cells).flatten.map(&:to_s) }.flatten |
| 174 | + |
| 175 | + expect(table_data).to include("Partially implemented") |
156 | 176 | end |
157 | 177 |
|
158 | 178 | it "displays the volunteer name" do |
159 | | - expect(document_inspector.word_list_document_contains?(document_data[:volunteer_name])).to eq(true) |
| 179 | + docx_response = Docx::Document.open(StringIO.new(report.generate_to_string)) |
| 180 | + |
| 181 | + table_data = docx_response.tables.map { |t| t.rows.map(&:cells).flatten.map(&:to_s) }.flatten |
| 182 | + |
| 183 | + expect(table_data).to include(/#{document_data[:volunteer_name]}.*/) |
160 | 184 | end |
161 | 185 |
|
162 | 186 | it "displays the volunteer case assignment date formatted" do |
163 | | - expect(document_inspector.word_list_document_contains?(document_data[:volunteer_case_assignment_date].strftime("%B %-d, %Y"))).to eq(true) |
| 187 | + docx_response = Docx::Document.open(StringIO.new(report.generate_to_string)) |
| 188 | + |
| 189 | + table_data = docx_response.tables.map { |t| t.rows.map(&:cells).flatten.map(&:to_s) }.flatten |
| 190 | + |
| 191 | + expect(table_data).to include(/#{document_data[:volunteer_case_assignment_date].strftime("%B %-d, %Y")}.*/) |
164 | 192 | end |
165 | 193 |
|
166 | 194 | it "displayes the supervisor name" do |
167 | | - expect(document_inspector.word_list_document_contains?(document_data[:supervisor_name])).to eq(true) |
| 195 | + docx_response = Docx::Document.open(StringIO.new(report.generate_to_string)) |
| 196 | + |
| 197 | + table_data = docx_response.tables.map { |t| t.rows.map(&:cells).flatten.map(&:to_s) }.flatten |
| 198 | + |
| 199 | + expect(table_data).to include(/#{document_data[:supervisor_name]}.*/) |
168 | 200 | end |
169 | 201 | end |
170 | 202 |
|
|
199 | 231 | let(:contact_type) { create(:contact_type, name: document_data[:case_contact_type]) } |
200 | 232 | let(:case_contact) { create(:case_contact, contact_made: false, occurred_at: document_data[:case_contact_time]) } |
201 | 233 | let(:court_order) { create(:case_court_order, implementation_status: :partially_implemented) } |
202 | | - let(:document_inspector) { DocxInspector.new(docx_contents: report.generate_to_string) } |
203 | 234 |
|
204 | 235 | before(:each) do |
205 | 236 | casa_case.casa_org.update_attribute(:address, document_data[:org_address]) |
|
213 | 244 | end |
214 | 245 |
|
215 | 246 | it "displays today's date formatted" do |
216 | | - expect(document_inspector.word_list_document_contains?(Date.current.strftime("%B %-d, %Y"))).to eq(true) |
| 247 | + docx_response = Docx::Document.open(StringIO.new(report.generate_to_string)) |
| 248 | + |
| 249 | + expect(docx_response.paragraphs.map(&:to_s)).to include(/#{Date.current.strftime("%B %-d, %Y")}.*/) |
217 | 250 | end |
218 | 251 |
|
219 | 252 | it "displays the case hearing date formatted" do |
220 | | - expect(document_inspector.word_list_document_contains?(document_data[:case_hearing_date].strftime("%B %-d, %Y"))).to eq(true) |
| 253 | + docx_response = Docx::Document.open(StringIO.new(report.generate_to_string)) |
| 254 | + |
| 255 | + expect(docx_response.paragraphs.map(&:to_s)).to include(/#{document_data[:case_hearing_date].strftime("%B %-d, %Y")}.*/) |
221 | 256 | end |
222 | 257 |
|
223 | | - it "displays the case numbet" do |
224 | | - expect(document_inspector.word_list_document_contains?(document_data[:case_number])).to eq(true) |
| 258 | + it "displays the case number" do |
| 259 | + docx_response = Docx::Document.open(StringIO.new(report.generate_to_string)) |
| 260 | + expect(docx_response.paragraphs.map(&:to_s)).to include(/.*#{document_data[:case_number]}.*/) |
225 | 261 | end |
226 | 262 |
|
227 | 263 | it "displays the case contact type" do |
228 | | - expect(document_inspector.word_list_document_contains?(document_data[:case_contact_type])).to eq(true) |
| 264 | + docx_response = Docx::Document.open(StringIO.new(report.generate_to_string)) |
| 265 | + |
| 266 | + table_data = docx_response.tables.map { |t| t.rows.map(&:cells).flatten.map(&:to_s) }.flatten |
| 267 | + |
| 268 | + expect(table_data).to include(document_data[:case_contact_type]) |
229 | 269 | end |
230 | 270 |
|
231 | 271 | it "displays the case contact time formatted" do |
232 | | - expect(document_inspector.word_list_document_contains?("#{document_data[:case_contact_time].strftime("%-m/%d")}*")).to eq(true) |
| 272 | + docx_response = Docx::Document.open(StringIO.new(report.generate_to_string)) |
| 273 | + |
| 274 | + table_data = docx_response.tables.map { |t| t.rows.map(&:cells).flatten.map(&:to_s) }.flatten |
| 275 | + |
| 276 | + expect(table_data).to include(document_data[:case_contact_time].strftime("%-m/%d*")) |
233 | 277 | end |
234 | 278 |
|
235 | 279 | it "displays the test" do |
236 | | - expect(document_inspector.word_list_document_contains?(document_data[:text])).to eq(true) |
| 280 | + docx_response = Docx::Document.open(StringIO.new(report.generate_to_string)) |
| 281 | + |
| 282 | + table_data = docx_response.tables.map { |t| t.rows.map(&:cells).flatten.map(&:to_s) }.flatten |
| 283 | + |
| 284 | + expect(table_data).to include("This text shall not be strikingly similar to other text in the document") |
237 | 285 | end |
238 | 286 |
|
239 | 287 | it "displays the order status" do |
240 | | - expect(document_inspector.word_list_document_contains?("Partially implemented")).to eq(true) # Order Status |
| 288 | + docx_response = Docx::Document.open(StringIO.new(report.generate_to_string)) |
| 289 | + |
| 290 | + table_data = docx_response.tables.map { |t| t.rows.map(&:cells).flatten.map(&:to_s) }.flatten |
| 291 | + |
| 292 | + expect(table_data).to include("Partially implemented") |
241 | 293 | end |
242 | 294 | end |
243 | 295 | end |
|
262 | 314 |
|
263 | 315 | describe "when court orders has different implementation statuses" do |
264 | 316 | let(:casa_case) { create(:casa_case, case_number: "Sample-Case-12345") } |
265 | | - let(:court_order_implemented) { create(:case_court_order, casa_case: casa_case, text: "K6N-ce8|NuXnht(", implementation_status: :implemented) } |
266 | | - let(:court_order_unimplemented) { create(:case_court_order, casa_case: casa_case, text: "'q\"tE1LP-9W>,2)", implementation_status: :unimplemented) } |
267 | | - let(:court_order_partially_implemented) { create(:case_court_order, casa_case: casa_case, text: "ZmCw@w@\d`&roct", implementation_status: :partially_implemented) } |
268 | | - let(:court_order_not_specified) { create(:case_court_order, casa_case: casa_case, text: "(4WqOL7e'FRYd@%", implementation_status: nil) } |
| 317 | + let(:court_order_implemented) { create(:case_court_order, casa_case: casa_case, text: "an order that got done", implementation_status: :implemented) } |
| 318 | + let(:court_order_unimplemented) { create(:case_court_order, casa_case: casa_case, text: "an order that got not done", implementation_status: :unimplemented) } |
| 319 | + let(:court_order_partially_implemented) { create(:case_court_order, casa_case: casa_case, text: "an order that got kinda done", implementation_status: :partially_implemented) } |
| 320 | + let(:court_order_not_specified) { create(:case_court_order, casa_case: casa_case, text: "what is going on", implementation_status: nil) } |
269 | 321 | let(:args) do |
270 | 322 | { |
271 | 323 | case_id: casa_case.id, |
|
275 | 327 | end |
276 | 328 | let(:context) { CaseCourtReportContext.new(args).context } |
277 | 329 | let(:case_report) { CaseCourtReport.new(path_to_template: path_to_template, context: context) } |
278 | | - let(:document_inspector) { DocxInspector.new(docx_contents: case_report.generate_to_string) } |
279 | 330 |
|
280 | 331 | before(:each) do |
281 | 332 | casa_case.case_court_orders << court_order_implemented |
|
285 | 336 | end |
286 | 337 |
|
287 | 338 | it "contains the case number" do |
288 | | - expect(document_inspector.word_list_document_contains?(casa_case.case_number)).to eq(true) |
| 339 | + docx_response = Docx::Document.open(StringIO.new(case_report.generate_to_string)) |
| 340 | + |
| 341 | + expect(docx_response.paragraphs.map(&:to_s)).to include(/#{casa_case.case_number}*/) |
289 | 342 | end |
290 | 343 |
|
291 | 344 | it "contains the court order text" do |
292 | | - expect(document_inspector.word_list_document_contains?(court_order_implemented.text)).to eq(true) |
| 345 | + docx_response = Docx::Document.open(StringIO.new(case_report.generate_to_string)) |
| 346 | + |
| 347 | + expect(table_text(docx_response)).to include(/#{court_order_implemented.text}.*/) |
293 | 348 | end |
294 | 349 |
|
295 | 350 | it "contains the exact value of 'Implemented'" do |
296 | | - expect(document_inspector.word_list_document_contains?("Implemented")).to eq(true) |
| 351 | + docx_response = Docx::Document.open(StringIO.new(case_report.generate_to_string)) |
| 352 | + |
| 353 | + expect(table_text(docx_response)).to include(/Implemented.*/) |
297 | 354 | end |
298 | 355 |
|
299 | 356 | it "contains the court order text" do |
300 | | - expect(document_inspector.word_list_document_contains?(court_order_unimplemented.text)).to eq(true) |
| 357 | + docx_response = Docx::Document.open(StringIO.new(case_report.generate_to_string)) |
| 358 | + |
| 359 | + expect(table_text(docx_response)).to include(/#{court_order_unimplemented.text}.*/) |
301 | 360 | end |
302 | 361 |
|
303 | 362 | it "contains the exact value of 'Unimplemented'" do |
304 | | - expect(document_inspector.word_list_document_contains?("Unimplemented")).to eq(true) |
| 363 | + docx_response = Docx::Document.open(StringIO.new(case_report.generate_to_string)) |
| 364 | + |
| 365 | + expect(table_text(docx_response)).to include(/Unimplemented.*/) |
305 | 366 | end |
306 | 367 |
|
307 | 368 | it "contains the court order text" do |
308 | | - expect(document_inspector.word_list_document_contains?(court_order_partially_implemented.text)).to eq(true) |
| 369 | + docx_response = Docx::Document.open(StringIO.new(case_report.generate_to_string)) |
| 370 | + |
| 371 | + expect(table_text(docx_response)).to include(/#{court_order_partially_implemented.text}.*/) |
309 | 372 | end |
310 | 373 |
|
311 | 374 | it "contains the exact value of 'Partially implemented'" do |
312 | | - expect(document_inspector.word_list_document_contains?("Partially implemented")).to eq(true) |
| 375 | + docx_response = Docx::Document.open(StringIO.new(case_report.generate_to_string)) |
| 376 | + |
| 377 | + expect(table_text(docx_response)).to include(/Partially implemented.*/) |
313 | 378 | end |
314 | 379 |
|
315 | 380 | it "contains the court order text" do |
316 | | - expect(document_inspector.word_list_document_contains?(court_order_not_specified.text)).to eq(true) |
| 381 | + docx_response = Docx::Document.open(StringIO.new(case_report.generate_to_string)) |
| 382 | + |
| 383 | + expect(table_text(docx_response)).to include(/#{court_order_not_specified.text}.*/) |
317 | 384 | end |
318 | 385 |
|
319 | 386 | it "contains the exact value of 'Not specified'" do |
320 | | - expect(document_inspector.word_list_document_contains?("Not specified")).to eq(true) |
| 387 | + docx_response = Docx::Document.open(StringIO.new(case_report.generate_to_string)) |
| 388 | + |
| 389 | + expect(table_text(docx_response)).to include(/Not specified.*/) |
321 | 390 | end |
322 | 391 | end |
323 | 392 | end |
|
0 commit comments