Skip to content

Commit

Permalink
Merge pull request #82 from Glutexo/create_file_name
Browse files Browse the repository at this point in the history
♻️ Extract file name creation
  • Loading branch information
Glutexo authored Mar 11, 2022
2 parents ec7ca2e + 9487966 commit 048e7f5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/onigumo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule Onigumo do
end

def download_url(url, root_path) do
file_name = Base.url_encode64(url, padding: false)
file_name = create_file_name(url)
file_path = Path.join(root_path, file_name)

url
Expand Down Expand Up @@ -54,4 +54,8 @@ defmodule Onigumo do
defp http_client() do
Application.get_env(:onigumo, :http_client)
end

def create_file_name(url) do
Base.url_encode64(url, padding: false)
end
end
13 changes: 12 additions & 1 deletion test/onigumo_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule OnigumoTest do
download_result = Onigumo.download_url(input_url, tmp_dir)
assert(download_result == :ok)

output_file_name = Base.url_encode64(input_url, padding: false)
output_file_name = Onigumo.create_file_name(input_url)
output_path = Path.join(tmp_dir, output_file_name)
read_output = File.read!(output_path)
expected_output = body(input_url)
Expand Down Expand Up @@ -90,6 +90,17 @@ defmodule OnigumoTest do
assert(read_output == response)
end

test("create file name from URL") do
input_url = "https://onigumo.local/hello.html"
created_file_name = Onigumo.create_file_name(input_url)

expected_file_name = Base.url_encode64(input_url, padding: false)
assert(created_file_name == expected_file_name)

unexpected_file_name = Base.url_encode64(input_url, padding: true)
assert(created_file_name != unexpected_file_name)
end

defp prepare_response(url) do
%HTTPoison.Response{
status_code: 200,
Expand Down

0 comments on commit 048e7f5

Please sign in to comment.