Skip to content

Commit 5c60bd6

Browse files
committed
Add file_size to document details for PDF downloads
This change includes the file_size field in the document details sent to the Publishing API, enabling the frontend to display human-readable file sizes for downloadable PDF maps.
1 parent 7f8a136 commit 5c60bd6

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

app/presenters/edition_presenter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def document
152152
"id" => SecureRandom.uuid,
153153
"url" => edition.document["file_url"],
154154
"content_type" => edition.document["content_type"],
155+
"file_size" => edition.document["size"],
155156
}
156157
end
157158
end

spec/presenters/edition_presenter_spec.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,5 +214,45 @@
214214
expect(presented_data["last_edited_by_editor_id"]).to eq(user.uid)
215215
end
216216
end
217+
218+
describe "document field" do
219+
let(:document_details) { presented_data["details"]["document"] }
220+
221+
context "when the edition has a document with size" do
222+
before do
223+
allow(edition).to receive(:document).and_return(
224+
"file_url" => "https://assets.example.com/map.pdf",
225+
"content_type" => "application/pdf",
226+
"size" => 201_672,
227+
)
228+
end
229+
230+
it "includes the file size in the document details" do
231+
expect(document_details).to include(
232+
"file_size" => 201_672,
233+
"url" => "https://assets.example.com/map.pdf",
234+
"content_type" => "application/pdf",
235+
"attachment_type" => "file",
236+
)
237+
end
238+
end
239+
240+
context "when the edition has a document without size" do
241+
before do
242+
allow(edition).to receive(:document).and_return(
243+
"file_url" => "https://assets.example.com/map.pdf",
244+
"content_type" => "application/pdf",
245+
)
246+
end
247+
248+
it "includes file_size as nil when no size is provided" do
249+
expect(document_details).to include(
250+
"url" => "https://assets.example.com/map.pdf",
251+
"content_type" => "application/pdf",
252+
"file_size" => nil,
253+
)
254+
end
255+
end
256+
end
217257
end
218258
end

0 commit comments

Comments
 (0)