Skip to content

Commit

Permalink
Update case data handling
Browse files Browse the repository at this point in the history
Prevent errors when case data doesn't have classifications or documents.

Fixes #119
  • Loading branch information
gbp committed Dec 18, 2024
1 parent 95fcf2c commit db22e43
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/icasework/case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions spec/fixtures/getcases_without_classifications.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
HTTP/1.1 200 OK
content-type: text/xml;charset=UTF-8
content-length: 1739

<?xml version="1.0" encoding="UTF-8"?>
<Cases>
<Case>
<CaseId>487347</CaseId>
<Type>Information request</Type>
<Label>IR - y</Label>
<RequestMethod>Online Form</RequestMethod>
<RequestDate>2021-02-15T16:42:19</RequestDate>
<Status>Some information sent but not all held</Status>
<Attributes>
<Details>y</Details>
<InformationWillBe>Embedded in the response</InformationWillBe>
<PublishInTheDisclosureLog>Yes</PublishInTheDisclosureLog>
<ReasonInformationNotHeld>t</ReasonInformationNotHeld>
<SuitableForPublicationScheme>Yes</SuitableForPublicationScheme>
</Attributes>
<Documents>
<Document Id="D225851" Name="Response (some not held)" Category="General upload" Type="application/pdf" Source="Document" DocumentDate="2021-02-15T16:43:11"><![CDATA[https://uatportal.icasework.com/servlet/servlets.getImg?ref=D225851&bin=Y&auth=0&db=UJzFimNH5H4%3D&access_token=773WgblkSUxU7tva_uAQRK77bUD4lDfgfes_mz3uPHwZNu3ucP5OXsYgCtvDCvYz.AJAhd9_B7RiK45ojg4Lilw%3D%3D]]></Document>
</Documents>
</Case>
</Cases>
27 changes: 27 additions & 0 deletions spec/fixtures/getcases_without_documents.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
HTTP/1.1 200 OK
content-type: text/xml;charset=UTF-8
content-length: 1739

<?xml version="1.0" encoding="UTF-8"?>
<Cases>
<Case>
<CaseId>487347</CaseId>
<Type>Information request</Type>
<Label>IR - y</Label>
<RequestMethod>Online Form</RequestMethod>
<RequestDate>2021-02-15T16:42:19</RequestDate>
<Status>Some information sent but not all held</Status>
<Attributes>
<Details>y</Details>
<InformationWillBe>Embedded in the response</InformationWillBe>
<PublishInTheDisclosureLog>Yes</PublishInTheDisclosureLog>
<ReasonInformationNotHeld>t</ReasonInformationNotHeld>
<SuitableForPublicationScheme>Yes</SuitableForPublicationScheme>
</Attributes>
<Classifications>
<Classification Group="About the council">Budgets spending and performance</Classification>
<Classification Group="Licensing and regulation">Animal licensing</Classification>
<Classification Group="Leisure and culture">Libraries</Classification>
</Classifications>
</Case>
</Cases>
18 changes: 18 additions & 0 deletions spec/icasework/case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit db22e43

Please sign in to comment.