Skip to content

Commit

Permalink
Fix module doc and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Santiago Botero committed Sep 15, 2022
1 parent 94a130e commit 972814f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lib/types/base16_string.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Kadena.Types.Base16String do
@moduledoc """
`Base16String` struct definition
`Base16String` struct definition.
"""

@behaviour Kadena.Types.Spec
Expand Down
8 changes: 4 additions & 4 deletions lib/types/base64_url.ex
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
defmodule Kadena.Types.Base64Url do
@moduledoc """
`Base64Url` struct definition
`Base64Url` struct definition.
"""

@behaviour Kadena.Types.Spec

@type t :: %__MODULE__{value: String.t()}
@type t :: %__MODULE__{url: String.t()}

defstruct [:value]
defstruct [:url]

@impl true
def new(str) when is_binary(str), do: %__MODULE__{value: str}
def new(str) when is_binary(str), do: %__MODULE__{url: str}
def new(_str), do: {:error, :invalid_string}
end
2 changes: 1 addition & 1 deletion lib/types/spec.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Kadena.Types.Spec do
@moduledoc """
Defines base types constructions
Defines base types constructions.
"""

@type error :: {:error, atom()}
Expand Down
16 changes: 5 additions & 11 deletions test/types/base16_string_test.exs
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
defmodule Kadena.Types.Base16StringTest do
@moduledoc """
`Base16String` struct definition tests
`Base16String` struct definition tests.
"""

use ExUnit.Case

alias Kadena.Types.Base16String

setup do
%{valid_param: "valid_param", invalid_param: :atom}
end

test "new/1 with valid params", %{valid_param: valid_param} do
test "new/1 with valid params" do
valid_param = "valid_param"
%Base16String{value: ^valid_param} = Base16String.new(valid_param)
end

test "new/1 with invalid params", %{invalid_param: invalid_param} do
{:error, :invalid_string} = Base16String.new(invalid_param)
end

test "new/1 with nil params" do
test "new/1 with invalid params" do
{:error, :invalid_string} = Base16String.new(:atom)
{:error, :invalid_string} = Base16String.new(nil)
end
end
18 changes: 6 additions & 12 deletions test/types/base64_url_test.exs
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
defmodule Kadena.Types.Base64UrlTest do
@moduledoc """
`Base64Url` struct definition tests
`Base64Url` struct definition tests.
"""

use ExUnit.Case

alias Kadena.Types.Base64Url

setup do
%{valid_param: "valid_param", invalid_param: :atom}
test "new/1 with valid params" do
valid_param = "valid_param"
%Base64Url{url: ^valid_param} = Base64Url.new(valid_param)
end

test "new/1 with valid params", %{valid_param: valid_param} do
%Base64Url{value: ^valid_param} = Base64Url.new(valid_param)
end

test "new/1 with invalid params", %{invalid_param: invalid_param} do
{:error, :invalid_string} = Base64Url.new(invalid_param)
end

test "new/1 with nil params" do
test "new/1 with invalid params" do
{:error, :invalid_string} = Base64Url.new(:atom)
{:error, :invalid_string} = Base64Url.new(nil)
end
end

0 comments on commit 972814f

Please sign in to comment.