Move Participant role from integer to enum

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-02-07 16:37:40 +01:00
parent 7b83682b26
commit 4bac5a07bd
9 changed files with 89 additions and 22 deletions

View File

@@ -306,9 +306,9 @@ defmodule Mobilizon.EventsTest do
alias Mobilizon.Events.{Participant, Event}
alias Mobilizon.Actors.Actor
@valid_attrs %{role: 42}
@update_attrs %{role: 43}
@invalid_attrs %{role: nil}
@valid_attrs %{role: :creator}
@update_attrs %{role: :moderator}
@invalid_attrs %{role: :no_such_role}
setup do
actor = insert(:actor)
@@ -341,7 +341,7 @@ defmodule Mobilizon.EventsTest do
with {:ok, %Participant{} = participant} <- Events.create_participant(valid_attrs) do
assert participant.event_id == event.id
assert participant.actor_id == actor.id
assert participant.role == 42
assert participant.role == :creator
else
err ->
flunk("Failed to create a participant #{inspect(err)}")
@@ -357,7 +357,7 @@ defmodule Mobilizon.EventsTest do
} do
with {:ok, %Participant{} = participant} <-
Events.update_participant(participant, @update_attrs) do
assert participant.role == 43
assert participant.role == :moderator
else
err ->
flunk("Failed to update a participant #{inspect(err)}")

View File

@@ -89,13 +89,17 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
assert json_response(res, 200)["data"]["participants"] == [
%{
"actor" => %{"preferredUsername" => context.actor.preferred_username},
"role" => 4
"role" => "creator"
}
]
# Adding a participant
# Adding two participants
actor2 = insert(:actor)
participant = insert(:participant, event: event, actor: actor2)
actor3 = insert(:actor)
# This one won't get listed (as not approved)
participant = insert(:participant, event: event, actor: actor2, role: :not_approved)
# This one will (as a participant)
participant2 = insert(:participant, event: event, actor: actor3, role: :participant)
res =
context.conn
@@ -104,11 +108,11 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
assert json_response(res, 200)["data"]["participants"] == [
%{
"actor" => %{"preferredUsername" => context.actor.preferred_username},
"role" => 4
"role" => "creator"
},
%{
"actor" => %{"preferredUsername" => participant.actor.preferred_username},
"role" => 0
"actor" => %{"preferredUsername" => participant2.actor.preferred_username},
"role" => "participant"
}
]
end

View File

@@ -117,7 +117,7 @@ defmodule Mobilizon.Factory do
%Mobilizon.Events.Participant{
event: build(:event),
actor: build(:actor),
role: 0
role: :creator
}
end