generated from kommitters/.template
-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added EnvData and PactCode with tests
Co-authored-by: Santiago Botero <[email protected]>
- Loading branch information
1 parent
60ace1b
commit d52f61a
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
defmodule Kadena.Types.EnvData do | ||
@moduledoc """ | ||
`EnvData` struct definition. | ||
""" | ||
|
||
@behaviour Kadena.Types.Spec | ||
|
||
@type data :: map() | ||
|
||
@type t :: %__MODULE__{data: data()} | ||
|
||
defstruct [:data] | ||
|
||
@impl true | ||
def new(data) when is_map(data), do: %__MODULE__{data: data} | ||
def new(_data), do: {:error, [data: :invalid]} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
defmodule Kadena.Types.PactCode do | ||
@moduledoc """ | ||
`PactCode` struct definition | ||
""" | ||
|
||
@behaviour Kadena.Types.Spec | ||
|
||
@type code :: String.t() | ||
|
||
@type t :: %__MODULE__{code: code()} | ||
|
||
defstruct [:code] | ||
|
||
@impl true | ||
def new(code) when is_binary(code), do: %__MODULE__{code: code} | ||
def new(_code), do: {:error, [code: :invalid]} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
defmodule Kadena.Types.EnvDataTest do | ||
@moduledoc """ | ||
`EnvData` struct definition tests. | ||
""" | ||
|
||
use ExUnit.Case | ||
|
||
alias Kadena.Types.EnvData | ||
|
||
describe "new/1" do | ||
test "with valid env data" do | ||
%EnvData{data: %{}} = EnvData.new(%{}) | ||
end | ||
|
||
test "with nil env data" do | ||
{:error, [data: :invalid]} = EnvData.new(nil) | ||
end | ||
|
||
test "with number env data" do | ||
{:error, [data: :invalid]} = EnvData.new(12_345) | ||
end | ||
|
||
test "with atom env data" do | ||
{:error, [data: :invalid]} = EnvData.new(:atom) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
defmodule Kadena.Types.PactCodeTest do | ||
@moduledoc """ | ||
`PactCode` struct definition tests. | ||
""" | ||
|
||
use ExUnit.Case | ||
|
||
alias Kadena.Types.PactCode | ||
|
||
describe "new/1" do | ||
test "with a valid pact code" do | ||
%PactCode{code: ~S(format \"hello {}\" [\"world\"])} = | ||
PactCode.new(~S(format \"hello {}\" [\"world\"])) | ||
end | ||
|
||
test "with a number pact code" do | ||
{:error, [code: :invalid]} = PactCode.new(12_345) | ||
end | ||
|
||
test "with a atom pact code" do | ||
{:error, [code: :invalid]} = PactCode.new(:atom) | ||
end | ||
|
||
test "with a nil pact code" do | ||
{:error, [code: :invalid]} = PactCode.new(nil) | ||
end | ||
end | ||
end |