Skip to content

Commit

Permalink
Redefined PactInt
Browse files Browse the repository at this point in the history
  • Loading branch information
Santiago Botero committed Sep 16, 2022
1 parent fa5c330 commit 534986e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/types/pact_int.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ defmodule Kadena.Types.PactInt do

@behaviour Kadena.Types.Spec

@type t :: %__MODULE__{value: String.t()}
@type t :: %__MODULE__{value: integer(), raw_value: String.t()}

defstruct [:value]
defstruct [:value, :raw_value]

@impl true
def new(value) when is_binary(value), do: %__MODULE__{value: value}
def new(value) when is_integer(value), do: %__MODULE__{value: value, raw_value: "#{value}"}
def new(_value), do: {:error, :invalid_int}
end
6 changes: 3 additions & 3 deletions test/types/pact_int_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ defmodule Kadena.Types.PactIntTest do
alias Kadena.Types.PactInt

describe "new/1" do
test "With valid params" do
%PactInt{value: "500"} = PactInt.new("500")
test "With valid integer" do
%PactInt{value: 500, raw_value: "500"} = PactInt.new(500)
end

test "With nil value" do
Expand All @@ -25,7 +25,7 @@ defmodule Kadena.Types.PactIntTest do
end

test "With one list item with valid value" do
{:error, :invalid_int} = PactInt.new(["2333", nil, true])
{:error, :invalid_int} = PactInt.new([2333, nil, true])
end

test "With each list item with invalid value" do
Expand Down

0 comments on commit 534986e

Please sign in to comment.