Skip to content

Commit

Permalink
make simplified_attached_file_type more robust to handle nil case (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikStreek authored Nov 27, 2024
1 parent b16e214 commit 397aaf3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/mindwendel/attachments.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defmodule Mindwendel.Attachments do
"""
def simplified_attached_file_type(file_type) do
case String.split(file_type, "/") do
case String.split(file_type || "", "/") do
["image", _] -> "image"
[_, "pdf"] -> "pdf"
[_, _] -> "misc"
Expand Down
10 changes: 9 additions & 1 deletion test/mindwendel/attachments_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ defmodule Mindwendel.AttachmentsTest do
assert Attachments.simplified_attached_file_type("application/pdf") == "pdf"
end

test "simplifies the file type for an unknown file" do
test "simplifies the file type for an unknown type" do
assert Attachments.simplified_attached_file_type("application_unknown") == "misc"
end

test "simplifies the file type for an empty type" do
assert Attachments.simplified_attached_file_type("") == "misc"
end

test "simplifies the file type for a missing type" do
assert Attachments.simplified_attached_file_type(nil) == "misc"
end
end

describe "delete_attached_file" do
Expand Down

0 comments on commit 397aaf3

Please sign in to comment.