Skip to content

Commit

Permalink
undo changes to request decorators and templates 1b45ade
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-shaw committed Dec 13, 2024
1 parent dd75fa4 commit 60a5f0e
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 73 deletions.
4 changes: 0 additions & 4 deletions app/decorators/data_request_area_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ def request_dates
}.join("\n")
end

def data_required
data_requests.first.decorate.data_required.presence
end

def data_request_area_status_tag(status)
case status
when :completed
Expand Down
2 changes: 1 addition & 1 deletion app/decorators/data_request_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def location
end

def data_required
request_type_note
request_type_note if request_type == "other"
end

def display_request_type_note?
Expand Down
14 changes: 0 additions & 14 deletions spec/decorators/data_request_area_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,6 @@
end
end

describe "#data_required" do
let(:decorated) { data_request_area.decorate }

context "with a data_request having a request_type_note value" do
before do
create(:data_request, data_request_area:, request_type_note: "more info")
end

it "returns the string for the request" do
expect(decorated.data_required).to eq "More info"
end
end
end

describe "#request_document" do
let(:decorated) { data_request_area.decorate }

Expand Down
15 changes: 12 additions & 3 deletions spec/decorators/data_request_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,23 @@
end

describe "#data_required" do
context "when request_type_note has a value" do
let(:data_request) { create(:data_request, request_type_note: "some information") }
context "when request_type = other" do
let(:data_request) { create(:data_request, request_type: "other", request_type_note: "some information") }
let(:decorated) { data_request.decorate }

it "returns matching string to request_type_note" do
it "uses what data is needed string" do
expect(decorated.data_required).to eq data_request.request_type_note
end
end

context "when request_type != other" do
let(:data_request) { create(:data_request) }
let(:decorated) { data_request.decorate }

it "uses what data is needed string" do
expect(decorated.data_required).to be_nil
end
end
end

describe "#display_request_type_note?" do
Expand Down
20 changes: 3 additions & 17 deletions spec/models/commissioning_document_template/prison_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "rails_helper"

RSpec.describe CommissioningDocumentTemplate::Prison do
subject(:template) { described_class.new(data_request_area:) }
subject(:template) { described_class.new(data_request_area: data_request) }

let(:kase) do
build_stubbed(:offender_sar_case,
Expand All @@ -11,21 +11,7 @@
subject_aliases: "Bad Bob",
prison_number: "AB12345")
end

let(:data_request) do
build_stubbed(:data_request,
offender_sar_case: kase,
date_from: Date.new(2024, 2, 15),
date_to: Date.new(2024, 6, 30))
end

let(:data_request_area) do
build_stubbed(:data_request_area,
offender_sar_case: kase,
data_requests: [data_request],
data_request_area_type: "prison",
location: "HMP halifax")
end
let(:data_request) { build_stubbed(:data_request, offender_sar_case: kase) }

describe "#path" do
it "matches to a file" do
Expand All @@ -43,7 +29,7 @@
aliases: "Bad Bob",
date: "21/10/2022",
prison_numbers: "AB12345",
date_range: "from 15/02/2024 to 30/06/2024",
date_range: "",
deadline: "26/10/2022",
data_required: "All paper & electronic information including Security",
}
Expand Down
58 changes: 24 additions & 34 deletions spec/models/commissioning_document_template/probation_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "rails_helper"

RSpec.describe CommissioningDocumentTemplate::Probation do
subject(:template) { described_class.new(data_request_area:) }
subject(:template) { described_class.new(data_request_area: data_request) }

let(:kase) do
build_stubbed(:offender_sar_case,
Expand All @@ -12,44 +12,34 @@
other_subject_ids: "CD98765",
case_reference_number: "EF45678")
end
let(:data_request) { build_stubbed(:data_request, offender_sar_case: kase) }

let(:data_request) do
build_stubbed(:data_request,
request_type: "probation_records",
date_from: Date.new(2024, 2, 15),
date_to: Date.new(2024, 6, 30))
end

let(:data_request_area) do
build_stubbed(:data_request_area,
offender_sar_case: kase,
data_requests: [data_request],
data_request_area_type: "probation",
location: "HMP halifax")
describe "#path" do
it "matches to a file" do
expect(File).to exist(template.path)
end
end

describe "#context" do
context "with fully populated values" do
let(:expected_context) do
{
addressee_location: "HMP halifax",
dpa_reference: "20062007",
offender_name: "Robert Badson",
date_of_birth: "11/03/2000",
date: "21/10/2022",
prison_numbers: "AB12345",
pnc: "CD98765",
crn: "EF45678",
deadline: "26/10/2022",
data_required: "All paper and electronic information",
date_range: "from 15/02/2024 to 30/06/2024",
}
end
let(:expected_context) do
{
addressee_location: "HMP halifax",
dpa_reference: "20062007",
offender_name: "Robert Badson",
date_of_birth: "11/03/2000",
date: "21/10/2022",
prison_numbers: "AB12345",
date_range: "",
deadline: "26/10/2022",
pnc: "CD98765",
crn: "EF45678",
data_required: "All paper and electronic information",
}
end

it "populates data from the data_request_area and case" do
Timecop.freeze(Date.new(2022, 10, 21)) do
expect(template.context).to eq expected_context
end
it "populates data from the data_request and case" do
Timecop.freeze(Date.new(2022, 10, 21)) do
expect(template.context).to eq expected_context
end
end
end
Expand Down

0 comments on commit 60a5f0e

Please sign in to comment.