-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4308ccb
commit 0b807e7
Showing
10 changed files
with
189 additions
and
8 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
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
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
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,16 @@ | ||
defmodule ViralSpiral.Room.Actions.Player.InitiateCancel do | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
@primary_key false | ||
embedded_schema do | ||
field :from, :string | ||
field :target, :string | ||
field :affinity, Ecto.Enum, values: [:houseboat, :skub, :cat, :highfive, :socks] | ||
end | ||
|
||
def changeset(initiate_cancel, attrs) do | ||
initiate_cancel | ||
|> cast(attrs, [:from, :target, :affinity]) | ||
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,16 @@ | ||
defmodule ViralSpiral.Room.Actions.Player.VoteToCancel do | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
embedded_schema do | ||
field :player, :string | ||
field :vote, :boolean | ||
end | ||
|
||
def changeset(vote, attrs) do | ||
vote | ||
|> cast(attrs, [:player, :vote]) | ||
|
||
# todo add tests that player should start with `player_`? | ||
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
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
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
30 changes: 30 additions & 0 deletions
30
test/viral_spiral/room/actions/player/initiate_cancel_test.exs
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,30 @@ | ||
defmodule ViralSpiral.Room.Actions.Player.InitiateCancelTest do | ||
alias ViralSpiral.Room.Actions.Player.InitiateCancel | ||
use ExUnit.Case | ||
|
||
@valid_attr %{ | ||
"from" => "player_abc", | ||
"target" => "player_def", | ||
"affinity" => "cat" | ||
} | ||
|
||
@invaid_attr %{ | ||
"from" => "player_abc", | ||
"target" => "player_def", | ||
"affinity" => "Cat" | ||
} | ||
|
||
test "validation" do | ||
changeset = | ||
%InitiateCancel{} | ||
|> InitiateCancel.changeset(@valid_attr) | ||
|
||
assert changeset.valid? == true | ||
|
||
changeset = | ||
%InitiateCancel{} | ||
|> InitiateCancel.changeset(@invaid_attr) | ||
|
||
assert changeset.valid? == false | ||
end | ||
end |
28 changes: 28 additions & 0 deletions
28
test/viral_spiral/room/actions/player/vote_to_cancel_test.exs
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 ViralSpiral.Room.Actions.Player.VoteToCancelTest do | ||
alias ViralSpiral.Room.Actions.Player.VoteToCancel | ||
use ExUnit.Case | ||
|
||
@valid_attr %{ | ||
"player" => "player_abc", | ||
"vote" => "true" | ||
} | ||
|
||
@invalid_attr %{ | ||
"player" => "player_abc", | ||
"vote" => "NaN" | ||
} | ||
|
||
test "validation" do | ||
changeset = | ||
%VoteToCancel{} | ||
|> VoteToCancel.changeset(@valid_attr) | ||
|
||
assert changeset.valid? == true | ||
|
||
changeset = | ||
%VoteToCancel{} | ||
|> VoteToCancel.changeset(@invalid_attr) | ||
|
||
assert changeset.valid? == false | ||
end | ||
end |