Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions app/services/court_report_format_contact_date.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
# frozen_string_literal: true

class CourtReportFormatContactDate
CONTACT_UNSUCCESSFUL_PREFIX = "*"
CONTACT_SUCCESSFUL_SUFFIX = ""
CONTACT_UNSUCCESSFUL_SUFFIX = "*"

def initialize(case_contact)
@case_contact = case_contact
end

def format
I18n.l(@case_contact.occurred_at, format: :short_date, default: nil).concat(@case_contact.contact_made ? "" : CONTACT_UNSUCCESSFUL_PREFIX)
I18n.l(@case_contact.occurred_at, format: :short_date, default: nil).concat(contact_made_suffix)
end

def format_long
I18n.l(@case_contact.occurred_at, format: :long_date, default: nil)
end

private

attr_reader :case_contact

def contact_made_suffix
@case_contact.contact_made ? CONTACT_SUCCESSFUL_SUFFIX : CONTACT_UNSUCCESSFUL_SUFFIX
end
end
3 changes: 3 additions & 0 deletions app/services/fdf_inputs_service.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# frozen_string_literal: true

class FdfInputsService
FDF_ERB_TEMPLATE_PATH = ["data", "inputs_fdf.erb"].freeze

def self.clean(str)
return unless str.present?

str
.to_s
.gsub(/[)(\\]/, '\\\\\0')
Expand Down
38 changes: 36 additions & 2 deletions spec/services/court_report_format_contact_date_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe CourtReportFormatContactDate, type: :service do
# TODO: Add tests for CourtReportFormatContactDate
describe "#format" do
context "when there has been a successful contact" do
it "returns the day and month of when the Case Contact's occcurred" do
case_contact = build(
:case_contact,
occurred_at: Date.new(2026, 4, 16),
contact_made: true
)

contact_date = CourtReportFormatContactDate.new(case_contact).format

expect(contact_date).to eq("4/16")
end
end

context "when there has been no contact made" do
it "returns the day and month of when the Case Contact's occcurred with a suffix" do
case_contact = build(:case_contact, occurred_at: Date.new(2026, 3, 16))

contact_date = CourtReportFormatContactDate.new(case_contact).format

expect(contact_date).to eq("3/16*")
end
end
end

describe "#format_long" do
it "returns the day, month and year of when the Case Contact's in the long format" do
case_contact = build(:case_contact, occurred_at: Date.new(2026, 2, 16))

contact_date = CourtReportFormatContactDate.new(case_contact).format_long

pending "add some tests for CourtReportFormatContactDate"
expect(contact_date).to eq("02/16/26")
end
end
end
53 changes: 51 additions & 2 deletions spec/services/fdf_inputs_service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,56 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe FdfInputsService, type: :service do
# TODO: Add tests for FdfInputsService
describe ".clean" do
context "when the string is nil" do
it "returns nil" do
expect(FdfInputsService.clean("")).to be_nil
expect(FdfInputsService.clean(" ")).to be_nil
expect(FdfInputsService.clean(nil)).to be_nil
end
end

it "returns the escaped string" do
expect(FdfInputsService.clean("hello world")).to eq("hello world")
expect(FdfInputsService.clean("(test)")).to eq("\\(test\\)")
expect(FdfInputsService.clean("path\\to\\file")).to eq("path\\\\to\\\\file")
expect(FdfInputsService.clean("(a\\b)")).to eq("\\(a\\\\b\\)")
expect(FdfInputsService.clean("((a))")).to eq("\\(\\(a\\)\\)")
expect(FdfInputsService.clean("\\(test\\)")).to eq("\\\\\\(test\\\\\\)")
end
end

describe "#write_to_file" do
it "calls PdfForms with the given arguments and returns a file" do
inputs = {name: "Bob Cat"}
pdf_template_path = "/path/to/template.pdf"
basename = "test_file"

fake_pdf_forms = double("PdfForms")
allow(PdfForms).to receive(:new).and_return(fake_pdf_forms)
allow(fake_pdf_forms).to receive(:fill_form_with_fdf)

service = FdfInputsService.new(
inputs: inputs,
pdf_template_path: pdf_template_path,
basename: basename
)

result = service.write_to_file

expect(fake_pdf_forms).to have_received(:fill_form_with_fdf) do |template, output_path, fdf_path, flatten|
expect(template).to eq(pdf_template_path)
expect(output_path).to be_a(String)
expect(File.exist?(output_path)).to be(true)
expect(fdf_path).to be_a(String)
expect(File.exist?(fdf_path)).to be(true)
expect(flatten).to eq(flatten: true)
end

pending "add some tests for FdfInputsService"
expect(result).to be_a(Tempfile)
expect(File.exist?(result.path)).to be(true)
end
end
end
35 changes: 0 additions & 35 deletions spec/support/pdf_helpers.rb

This file was deleted.

Loading