Skip to content

Commit 1a55edf

Browse files
Add coverage for CourtReportFormatContactDate
1 parent 21e937a commit 1a55edf

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
1+
# frozen_string_literal: true
2+
13
class CourtReportFormatContactDate
2-
CONTACT_UNSUCCESSFUL_PREFIX = "*"
4+
CONTACT_SUCCESSFUL_SUFFIX = ''
5+
CONTACT_UNSUCCESSFUL_SUFFIX = '*'
36

47
def initialize(case_contact)
58
@case_contact = case_contact
69
end
710

811
def format
9-
I18n.l(@case_contact.occurred_at, format: :short_date, default: nil).concat(@case_contact.contact_made ? "" : CONTACT_UNSUCCESSFUL_PREFIX)
12+
I18n.l(
13+
@case_contact.occurred_at,
14+
format: :short_date,
15+
default: nil
16+
).concat(contact_made_suffix)
1017
end
1118

1219
def format_long
1320
I18n.l(@case_contact.occurred_at, format: :long_date, default: nil)
1421
end
22+
23+
private
24+
25+
attr_reader :case_contact
26+
27+
def contact_made_suffix
28+
@case_contact.contact_made ? CONTACT_SUCCESSFUL_SUFFIX : CONTACT_UNSUCCESSFUL_SUFFIX
29+
end
1530
end
Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,41 @@
1+
# frozen_string_literal: true
2+
13
require "rails_helper"
24

35
RSpec.describe CourtReportFormatContactDate, type: :service do
4-
# TODO: Add tests for CourtReportFormatContactDate
6+
describe "#format" do
7+
context "when there has been a successful contact" do
8+
it "returns the day and month of when the Case Contact's occcurred" do
9+
case_contact = build(
10+
:case_contact,
11+
occurred_at: Date.new(2026, 4, 16),
12+
contact_made: true
13+
)
14+
15+
contact_date = CourtReportFormatContactDate.new(case_contact).format
16+
17+
expect(contact_date).to eq("4/16")
18+
end
19+
end
20+
21+
context "when there has been no contact made" do
22+
it "returns the day and month of when the Case Contact's occcurred with a suffix" do
23+
case_contact = build(:case_contact, occurred_at: Date.new(2026, 3, 16))
24+
25+
contact_date = CourtReportFormatContactDate.new(case_contact).format
26+
27+
expect(contact_date).to eq("3/16*")
28+
end
29+
end
30+
end
31+
32+
describe "#format_long" do
33+
it "returns the day, month and year of when the Case Contact's in the long format" do
34+
case_contact = build(:case_contact, occurred_at: Date.new(2026, 2, 16))
35+
36+
contact_date = CourtReportFormatContactDate.new(case_contact).format_long
537

6-
pending "add some tests for CourtReportFormatContactDate"
38+
expect(contact_date).to eq("02/16/26")
39+
end
40+
end
741
end

0 commit comments

Comments
 (0)