Skip to content

Commit 246c1c9

Browse files
Add coverage for FdfInputService
Delete unused file
1 parent 1a55edf commit 246c1c9

File tree

4 files changed

+55
-42
lines changed

4 files changed

+55
-42
lines changed

app/services/court_report_format_contact_date.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ def initialize(case_contact)
99
end
1010

1111
def format
12-
I18n.l(
13-
@case_contact.occurred_at,
14-
format: :short_date,
15-
default: nil
16-
).concat(contact_made_suffix)
12+
I18n.l(@case_contact.occurred_at, format: :short_date, default: nil).concat(contact_made_suffix)
1713
end
1814

1915
def format_long

app/services/fdf_inputs_service.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
# frozen_string_literal: true
2+
13
class FdfInputsService
24
FDF_ERB_TEMPLATE_PATH = ["data", "inputs_fdf.erb"].freeze
35

46
def self.clean(str)
57
return unless str.present?
8+
69
str
710
.to_s
811
.gsub(/[)(\\]/, '\\\\\0')
Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,56 @@
1+
# frozen_string_literal: true
2+
13
require "rails_helper"
24

35
RSpec.describe FdfInputsService, type: :service do
4-
# TODO: Add tests for FdfInputsService
6+
describe ".clean" do
7+
context "when the string is nil" do
8+
it "returns nil" do
9+
expect(FdfInputsService.clean("")).to be_nil
10+
expect(FdfInputsService.clean(" ")).to be_nil
11+
expect(FdfInputsService.clean(nil)).to be_nil
12+
end
13+
end
14+
15+
it "returns the escaped string" do
16+
expect(FdfInputsService.clean("hello world")).to eq("hello world")
17+
expect(FdfInputsService.clean("(test)")).to eq("\\(test\\)")
18+
expect(FdfInputsService.clean("path\\to\\file")).to eq("path\\\\to\\\\file")
19+
expect(FdfInputsService.clean("(a\\b)")).to eq("\\(a\\\\b\\)")
20+
expect(FdfInputsService.clean("((a))")).to eq("\\(\\(a\\)\\)")
21+
expect(FdfInputsService.clean("\\(test\\)")).to eq("\\\\\\(test\\\\\\)")
22+
end
23+
end
24+
25+
describe "#write_to_file" do
26+
it "calls PdfForms with the given arguments and returns a file" do
27+
inputs = { name: "Bob Cat" }
28+
pdf_template_path = "/path/to/template.pdf"
29+
basename = "test_file"
30+
31+
fake_pdf_forms = double("PdfForms")
32+
allow(PdfForms).to receive(:new).and_return(fake_pdf_forms)
33+
allow(fake_pdf_forms).to receive(:fill_form_with_fdf)
34+
35+
service = FdfInputsService.new(
36+
inputs: inputs,
37+
pdf_template_path: pdf_template_path,
38+
basename: basename
39+
)
40+
41+
result = service.write_to_file
42+
43+
expect(fake_pdf_forms).to have_received(:fill_form_with_fdf) do |template, output_path, fdf_path, flatten|
44+
expect(template).to eq(pdf_template_path)
45+
expect(output_path).to be_a(String)
46+
expect(File.exist?(output_path)).to be(true)
47+
expect(fdf_path).to be_a(String)
48+
expect(File.exist?(fdf_path)).to be(true)
49+
expect(flatten).to eq(flatten: true)
50+
end
551

6-
pending "add some tests for FdfInputsService"
52+
expect(result).to be_a(Tempfile)
53+
expect(File.exist?(result.path)).to be(true)
54+
end
55+
end
756
end

spec/support/pdf_helpers.rb

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)