Skip to content

Commit c9c342c

Browse files
committed
test cloudinary_url.ex
1 parent e8fb324 commit c9c342c

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
defmodule Cloudex.CloudinaryApi.Test do
2+
@moduledoc """
3+
Testing stub for `Cloudex`,
4+
5+
Each function should have the same signature as `Cloudex`.
6+
"""
7+
8+
defmodule Url do
9+
def for(public_id, options) do
10+
{public_id, options}
11+
end
12+
end
13+
end
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
defmodule CodeCorps.Helpers.CloudinaryUrl do
22

3+
@cloudex Application.get_env(:cloudex, :cloudinary_api)
4+
35
def for(nil, _options, version, default_color, type) do
46
"#{Application.get_env(:code_corps, :asset_host)}/icons/#{type}_default_#{version}_#{default_color}.png"
57
end
68
def for(public_id, options, _version, _default_color, _type) do
7-
Cloudex.Url.for(public_id, options)
9+
@cloudex.Url.for(public_id, options)
810
end
911
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
defmodule CodeCorps.Helpers.CloudinaryUrlTest do
2+
use ExUnit.Case, async: true
3+
4+
test "calls Cloudex.Url.for with correct arguments" do
5+
expected_args = {:test_public_id, %{test_option: nil}}
6+
args = CodeCorps.Helpers.CloudinaryUrl.for(:test_public_id, %{test_option: nil}, nil, nil, nil)
7+
assert expected_args == args
8+
end
9+
10+
test "returns correct url if called without public_id" do
11+
expected_url = "#{Application.get_env(:code_corps, :asset_host)}/icons/type1_default_version1_color1.png"
12+
url = CodeCorps.Helpers.CloudinaryUrl.for(nil, %{}, "version1", "color1", "type1")
13+
assert expected_url == url
14+
end
15+
end

0 commit comments

Comments
 (0)