From bf3881fa7d60af4b1929a284f2bf177b20707379 Mon Sep 17 00:00:00 2001 From: Joe Haig Date: Thu, 28 Mar 2024 11:57:49 +0000 Subject: [PATCH] Add tests for defendant presenters --- .../case_workers/defendant_presenter_spec.rb | 20 +++++++++++++++++++ .../defendant_presenter_spec.rb | 20 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 spec/presenters/case_workers/defendant_presenter_spec.rb create mode 100644 spec/presenters/external_users/defendant_presenter_spec.rb diff --git a/spec/presenters/case_workers/defendant_presenter_spec.rb b/spec/presenters/case_workers/defendant_presenter_spec.rb new file mode 100644 index 0000000000..60bf1d343d --- /dev/null +++ b/spec/presenters/case_workers/defendant_presenter_spec.rb @@ -0,0 +1,20 @@ +RSpec.describe CaseWorkers::DefendantPresenter do + subject(:defendant_presenter) { described_class.new(defendant, view) } + + describe '#representation_orders' do + subject(:representation_orders) { defendant_presenter.representation_orders } + + context 'when there are representation orders' do + let(:defendant) { build(:defendant, representation_orders: build_list(:representation_order, 3)) } + + it { expect(representation_orders.length).to eq 3 } + it { is_expected.to all(be_a(CaseWorkers::RepresentationOrder)) } + end + + context 'when there are no representation orders' do + let(:defendant) { build(:defendant, representation_orders: []) } + + it { is_expected.to be_empty } + end + end +end diff --git a/spec/presenters/external_users/defendant_presenter_spec.rb b/spec/presenters/external_users/defendant_presenter_spec.rb new file mode 100644 index 0000000000..67f43669d6 --- /dev/null +++ b/spec/presenters/external_users/defendant_presenter_spec.rb @@ -0,0 +1,20 @@ +RSpec.describe ExternalUsers::DefendantPresenter do + subject(:defendant_presenter) { described_class.new(defendant, view) } + + describe '#representation_orders' do + subject(:representation_orders) { defendant_presenter.representation_orders } + + context 'when there are representation orders' do + let(:defendant) { build(:defendant, representation_orders: build_list(:representation_order, 3)) } + + it { expect(representation_orders.length).to eq 3 } + it { is_expected.to all(be_a(ExternalUsers::RepresentationOrder)) } + end + + context 'when there are no representation orders' do + let(:defendant) { build(:defendant, representation_orders: []) } + + it { is_expected.to be_empty } + end + end +end