diff --git a/lib/icasework/case.rb b/lib/icasework/case.rb index 76c057a..30e5c69 100644 --- a/lib/icasework/case.rb +++ b/lib/icasework/case.rb @@ -30,8 +30,8 @@ def case_data(data) case_status: case_status_data(data), case_status_receipt: case_status_receipt_data(data), attributes: data[:attributes], - classifications: [data[:classifications][:classification]].flatten, - documents: [data[:documents][:document]].flatten + classifications: case_classifications_data(data), + documents: case_documents_data(data) } end @@ -47,6 +47,18 @@ def case_status_receipt_data(data) def case_status_data(data) { status: data[:status] } end + + def case_classifications_data(data) + return [] unless data[:classifications] + + [data[:classifications][:classification]].flatten + end + + def case_documents_data(data) + return [] unless data[:documents] + + [data[:documents][:document]].flatten + end end def initialize(hash) diff --git a/spec/fixtures/getcases_without_classifications.txt b/spec/fixtures/getcases_without_classifications.txt new file mode 100644 index 0000000..fad3928 --- /dev/null +++ b/spec/fixtures/getcases_without_classifications.txt @@ -0,0 +1,25 @@ +HTTP/1.1 200 OK +content-type: text/xml;charset=UTF-8 +content-length: 1739 + + + + + 487347 + Information request + + Online Form + 2021-02-15T16:42:19 + Some information sent but not all held + +
y
+ Embedded in the response + Yes + t + Yes +
+ + + +
+
diff --git a/spec/fixtures/getcases_without_documents.txt b/spec/fixtures/getcases_without_documents.txt new file mode 100644 index 0000000..22c4804 --- /dev/null +++ b/spec/fixtures/getcases_without_documents.txt @@ -0,0 +1,27 @@ +HTTP/1.1 200 OK +content-type: text/xml;charset=UTF-8 +content-length: 1739 + + + + + 487347 + Information request + + Online Form + 2021-02-15T16:42:19 + Some information sent but not all held + +
y
+ Embedded in the response + Yes + t + Yes +
+ + Budgets spending and performance + Animal licensing + Libraries + +
+
diff --git a/spec/icasework/case_spec.rb b/spec/icasework/case_spec.rb index 17cf2c8..35cc923 100644 --- a/spec/icasework/case_spec.rb +++ b/spec/icasework/case_spec.rb @@ -50,6 +50,24 @@ it { is_expected.to all(be_an(described_class)) } it { expect(cases.count).to eq 2 } end + + context 'without classifications' do + let(:response) do + File.new('spec/fixtures/getcases_without_classifications.txt') + end + + it { is_expected.to be_an Array } + it { is_expected.to all(be_an(described_class)) } + end + + context 'without documents' do + let(:response) do + File.new('spec/fixtures/getcases_without_documents.txt') + end + + it { is_expected.to be_an Array } + it { is_expected.to all(be_an(described_class)) } + end end describe '.create' do