diff --git a/js/src/api/eventFetch.js b/js/src/api/eventFetch.js index a2669cee4..d735a2ca6 100644 --- a/js/src/api/eventFetch.js +++ b/js/src/api/eventFetch.js @@ -24,16 +24,6 @@ export default function eventFetch(url, store, optionsarg = {}) { return fetch(link, options).then((response) => { if (response.ok) return response; - return response - .json() - .then((json) => { - const error = json['hydra:description'] ? json['hydra:description'] : response.statusText; - if (!json.violations) throw Error(error); - - // const errors = { _error: error }; - // json.violations.map(violation => errors[violation.propertyPath] = violation.message); - - // throw errors; - }); + throw response.text(); }); } diff --git a/js/src/components/Event/Create.vue b/js/src/components/Event/Create.vue index 715df5bfc..e5181c380 100644 --- a/js/src/components/Event/Create.vue +++ b/js/src/components/Event/Create.vue @@ -261,7 +261,8 @@ // '@type': 'Tag', }); }); - this.event.organizer_id = this.$store.state.user.account.id; + this.event.category_id = this.event.category.id; + this.event.organizer_account_id = this.$store.state.user.account.id; this.event.participants = [this.$store.state.user.account.id]; this.event.price = parseFloat(this.event.price); diff --git a/js/src/components/Event/Event.vue b/js/src/components/Event/Event.vue index 02f6a0574..86c790692 100644 --- a/js/src/components/Event/Event.vue +++ b/js/src/components/Event/Event.vue @@ -2,8 +2,9 @@ + Error : event not found - + @@ -32,12 +33,27 @@
{{ event.title }}
-

{{ event.organizer.username }} organises {{ event.title }} in {{ event.address.addressLocality }} on the {{ event.startDate | formatDate }}.

- + - + Membres + + + + + + + + Organisateur {{ event.organizer.username }} + @@ -79,6 +95,7 @@ data() { return { loading: true, + error: false, event: { id: this.id, title: '', @@ -95,7 +112,6 @@ deleteEvent() { const router = this.$router; eventFetch(`/events/${this.id}`, this.$store, { method: 'DELETE' }) - .then(response => response.json()) .then(() => router.push({'name': 'EventList'})); }, fetchData() { @@ -103,8 +119,14 @@ .then(response => response.json()) .then((data) => { this.loading = false; - this.event = data; - }); + this.event = data.data; + }).catch((res) => { + Promise.resolve(res).then((data) => { + console.log(data); + this.error = true; + this.loading = false; + }) + }); }, joinEvent() { eventFetch(`/events/${this.id}/join`, this.$store) @@ -121,7 +143,7 @@ }); }, downloadIcsEvent() { - eventFetch('/events/' + this.event.id + '/export', this.$store, {responseType: 'arraybuffer'}) + eventFetch('/events/' + this.event.id + '/ics', this.$store, {responseType: 'arraybuffer'}) .then((response) => response.text()) .then(response => { const blob = new Blob([response],{type: 'text/calendar'}); diff --git a/js/src/components/Group/Create.vue b/js/src/components/Group/Create.vue index dae94001c..d68b7d576 100644 --- a/js/src/components/Group/Create.vue +++ b/js/src/components/Group/Create.vue @@ -42,7 +42,7 @@ response.json()) .then((data) => { this.loading = false; @@ -98,7 +98,7 @@ .then(response => response.json()) .then((data) => { this.loading = false; - this.categories = data; + this.categories = data.data; }); }, getAddressData: function (addressData) { diff --git a/js/src/components/Group/Group.vue b/js/src/components/Group/Group.vue index 506c89996..d531976d1 100644 --- a/js/src/components/Group/Group.vue +++ b/js/src/components/Group/Group.vue @@ -69,21 +69,21 @@ - + Membres - - + + - stars + stars - @@ -162,7 +162,7 @@ .then(response => response.json()) .then((data) => { this.loading = false; - this.group = data; + this.group = data.data; }); }, deleteGroup() { diff --git a/js/src/components/Group/GroupList.vue b/js/src/components/Group/GroupList.vue index 720ca802d..2fa196244 100644 --- a/js/src/components/Group/GroupList.vue +++ b/js/src/components/Group/GroupList.vue @@ -58,7 +58,7 @@ .then(response => response.json()) .then((data) => { this.loading = false; - this.groups = data; + this.groups = data.data; }); }, deleteEvent(id) { diff --git a/lib/eventos/accounts/account.ex b/lib/eventos/accounts/account.ex index 85ce940bd..18dcdfd14 100644 --- a/lib/eventos/accounts/account.ex +++ b/lib/eventos/accounts/account.ex @@ -18,7 +18,7 @@ defmodule Eventos.Accounts.Account do field :uri, :string field :url, :string field :username, :string - has_many :organized_events, Event, [foreign_key: :organizer_id] + has_many :organized_events, Event, [foreign_key: :organizer_account_id] many_to_many :groups, Group, join_through: Member has_many :group_request, Request has_one :user, User diff --git a/lib/eventos/events/event.ex b/lib/eventos/events/event.ex index c1249ddbd..807f7ba81 100644 --- a/lib/eventos/events/event.ex +++ b/lib/eventos/events/event.ex @@ -35,6 +35,7 @@ defmodule Eventos.Events.Event do alias Eventos.Events.{Event, Participant, Request, Tag, Category, Session, Track} alias Eventos.Events.Event.TitleSlug alias Eventos.Accounts.Account + alias Eventos.Groups.Group schema "events" do field :begins_on, Timex.Ecto.DateTimeWithTimezone @@ -49,7 +50,8 @@ defmodule Eventos.Events.Event do field :thumbnail, :string field :large_image, :string field :publish_at, Timex.Ecto.DateTimeWithTimezone - belongs_to :organizer, Account, [foreign_key: :organizer_id] + belongs_to :organizer_account, Account, [foreign_key: :organizer_account_id] + belongs_to :organizer_group, Group, [foreign_key: :organizer_group_id] many_to_many :tags, Tag, join_through: "events_tags" belongs_to :category, Category many_to_many :participants, Account, join_through: Participant @@ -63,9 +65,9 @@ defmodule Eventos.Events.Event do @doc false def changeset(%Event{} = event, attrs) do event - |> cast(attrs, [:title, :description, :begins_on, :ends_on, :organizer_id, :category_id, :state, :geom, :status, :public, :thumbnail, :large_image, :publish_at]) + |> cast(attrs, [:title, :description, :begins_on, :ends_on, :organizer_account_id, :organizer_group_id, :category_id, :state, :geom, :status, :public, :thumbnail, :large_image, :publish_at]) |> cast_assoc(:tags) - |> validate_required([:title, :description, :begins_on, :ends_on, :organizer_id, :category_id]) + |> validate_required([:title, :description, :begins_on, :ends_on, :organizer_account_id, :category_id]) |> TitleSlug.maybe_generate_slug() |> TitleSlug.unique_constraint() end diff --git a/lib/eventos/events/events.ex b/lib/eventos/events/events.ex index 20cdf23e3..dd7bf116f 100644 --- a/lib/eventos/events/events.ex +++ b/lib/eventos/events/events.ex @@ -7,6 +7,7 @@ defmodule Eventos.Events do alias Eventos.Repo alias Eventos.Events.Event + alias Eventos.Accounts.Account @doc """ Returns the list of events. @@ -37,6 +38,14 @@ defmodule Eventos.Events do """ def get_event!(id), do: Repo.get!(Event, id) + @doc """ + Gets a single event, with all associations loaded. + """ + def get_event_full!(id) do + event = Repo.get!(Event, id) + Repo.preload(event, [:organizer_account, :organizer_group, :category, :sessions, :tracks, :tags, :participants]) + end + @doc """ Creates a event. @@ -407,6 +416,10 @@ defmodule Eventos.Events do Repo.all(Request) end + def list_requests_for_account(%Account{} = account) do + Repo.all(from r in Request, where: r.account_id == ^account.id) + end + @doc """ Gets a single request. @@ -503,6 +516,20 @@ defmodule Eventos.Events do Repo.all(Session) end + @doc """ + Returns the list of sessions for an event + """ + def list_sessions_for_event(event_id) do + Repo.all(from s in Session, where: s.event_id == ^event_id) + end + + @doc """ + Returns the list of sessions for a track + """ + def list_sessions_for_track(track_id) do + Repo.all(from s in Session, where: s.track_id == ^track_id) + end + @doc """ Gets a single session. diff --git a/lib/eventos/groups/group.ex b/lib/eventos/groups/group.ex index a11256f03..1613b5343 100644 --- a/lib/eventos/groups/group.ex +++ b/lib/eventos/groups/group.ex @@ -32,6 +32,7 @@ defmodule Eventos.Groups.Group do """ use Ecto.Schema import Ecto.Changeset + alias Eventos.Events.Event alias Eventos.Groups.{Group, Member, Request} alias Eventos.Accounts.Account alias Eventos.Groups.Group.TitleSlug @@ -43,7 +44,8 @@ defmodule Eventos.Groups.Group do field :slug, TitleSlug.Type field :uri, :string field :url, :string - many_to_many :accounts, Account, join_through: Member + many_to_many :members, Account, join_through: Member + has_many :organized_events, Event, [foreign_key: :organizer_group_id] has_many :requests, Request timestamps() diff --git a/lib/eventos/groups/groups.ex b/lib/eventos/groups/groups.ex index 9d2f7d73b..925b33aa0 100644 --- a/lib/eventos/groups/groups.ex +++ b/lib/eventos/groups/groups.ex @@ -37,6 +37,14 @@ defmodule Eventos.Groups do """ def get_group!(id), do: Repo.get!(Group, id) + @doc """ + Gets a single group, with all associations loaded. + """ + def get_group_full!(id) do + group = Repo.get!(Group, id) + Repo.preload(group, [:members, :organized_events]) + end + @doc """ Creates a group. diff --git a/lib/eventos_web/controllers/event_controller.ex b/lib/eventos_web/controllers/event_controller.ex index a07130144..991aa925e 100644 --- a/lib/eventos_web/controllers/event_controller.ex +++ b/lib/eventos_web/controllers/event_controller.ex @@ -20,12 +20,12 @@ defmodule EventosWeb.EventController do conn |> put_status(:created) |> put_resp_header("location", event_path(conn, :show, event)) - |> render("show.json", event: event) + |> render("show_simple.json", event: event) end end def show(conn, %{"id" => id}) do - event = Events.get_event!(id) + event = Events.get_event_full!(id) render(conn, "show.json", event: event) end @@ -40,7 +40,7 @@ defmodule EventosWeb.EventController do event = Events.get_event!(id) with {:ok, %Event{} = event} <- Events.update_event(event, event_params) do - render(conn, "show.json", event: event) + render(conn, "show_simple.json", event: event) end end diff --git a/lib/eventos_web/controllers/event_request_controller.ex b/lib/eventos_web/controllers/event_request_controller.ex new file mode 100644 index 000000000..ce541d14b --- /dev/null +++ b/lib/eventos_web/controllers/event_request_controller.ex @@ -0,0 +1,52 @@ +defmodule EventosWeb.EventRequestController do + @moduledoc """ + Controller for Event requests + """ + use EventosWeb, :controller + + alias Eventos.Events + alias Eventos.Events.{Event, Request} + + action_fallback EventosWeb.FallbackController + + def index_for_user(conn, _params) do + account = Guardian.Plug.current_resource(conn).account + requests = Events.list_requests_for_account(account) + render(conn, "index.json", requests: requests) + end + + def create(conn, %{"request" => request_params}) do + request_params = Map.put(request_params, "account_id", Guardian.Plug.current_resource(conn).account.id) + with {:ok, %Request{} = request} <- Events.create_request(request_params) do + conn + |> put_status(:created) + |> put_resp_header("location", event_request_path(conn, :show, request)) + |> render("show.json", request: request) + end + end + + def create_for_event(conn, %{"request" => request_params, "id" => event_id}) do + request_params = Map.put(request_params, "event_id", event_id) + create(conn, request_params) + end + + def show(conn, %{"id" => id}) do + request = Events.get_request!(id) + render(conn, "show.json", request: request) + end + + def update(conn, %{"id" => id, "request" => request_params}) do + request = Events.get_request!(id) + + with {:ok, %Request{} = request} <- Events.update_request(request, request_params) do + render(conn, "show.json", request: request) + end + end + + def delete(conn, %{"id" => id}) do + request = Events.get_request!(id) + with {:ok, %Request{}} <- Events.delete_request(request) do + send_resp(conn, :no_content, "") + end + end +end diff --git a/lib/eventos_web/controllers/group_controller.ex b/lib/eventos_web/controllers/group_controller.ex index fbaf8c61e..a3a060b18 100644 --- a/lib/eventos_web/controllers/group_controller.ex +++ b/lib/eventos_web/controllers/group_controller.ex @@ -15,16 +15,18 @@ defmodule EventosWeb.GroupController do end def create(conn, %{"group" => group_params}) do + group_params = Map.put(group_params, "uri", "h") + group_params = Map.put(group_params, "url", "h") with {:ok, %Group{} = group} <- Groups.create_group(group_params) do conn |> put_status(:created) |> put_resp_header("location", group_path(conn, :show, group)) - |> render("show.json", group: group) + |> render("show_simple.json", group: group) end end def show(conn, %{"id" => id}) do - group = Groups.get_group!(id) + group = Groups.get_group_full!(id) render(conn, "show.json", group: group) end @@ -32,7 +34,7 @@ defmodule EventosWeb.GroupController do group = Groups.get_group!(id) with {:ok, %Group{} = group} <- Groups.update_group(group, group_params) do - render(conn, "show.json", group: group) + render(conn, "show_simple.json", group: group) end end diff --git a/lib/eventos_web/controllers/session_controller.ex b/lib/eventos_web/controllers/session_controller.ex index dcedd9917..ac1454750 100644 --- a/lib/eventos_web/controllers/session_controller.ex +++ b/lib/eventos_web/controllers/session_controller.ex @@ -28,6 +28,16 @@ defmodule EventosWeb.SessionController do render(conn, "show.json", session: session) end + def show_sessions_for_event(conn, %{"id" => event_id}) do + sessions = Events.list_sessions_for_event(event_id) + render(conn, "index.json", sessions: sessions) + end + + def show_sessions_for_track(conn, %{"id" => track}) do + sessions = Events.list_sessions_for_track(track) + render(conn, "index.json", sessions: sessions) + end + def update(conn, %{"id" => id, "session" => session_params}) do session = Events.get_session!(id) diff --git a/lib/eventos_web/router.ex b/lib/eventos_web/router.ex index b0cd532da..58d95f740 100644 --- a/lib/eventos_web/router.ex +++ b/lib/eventos_web/router.ex @@ -28,6 +28,9 @@ defmodule EventosWeb.Router do post "/login", UserSessionController, :sign_in resources "/groups", GroupController, only: [:index, :show] resources "/events", EventController, only: [:index, :show] + get "/events/:id/ics", EventController, :export_to_ics + get "/events/:id/tracks", TrackController, :show_tracks_for_event + get "/events/:id/sessions", SessionController, :show_sessions_for_event resources "/accounts", AccountController, only: [:index, :show] resources "/tags", TagController, only: [:index, :show] resources "/categories", CategoryController, only: [:index, :show] @@ -44,16 +47,18 @@ defmodule EventosWeb.Router do resources "/users", UserController, except: [:new, :edit, :show] resources "/accounts", AccountController, except: [:new, :edit] resources "/events", EventController - get "/events/:id/ics", EventController, :export_to_ics + post "/events/:id/request", EventRequestController, :create_for_event + resources "/participant", ParticipantController + resources "/requests", EventRequestController + resources "/groups", GroupController, except: [:index, :show] + post "/groups/:id/request", GroupRequestController, :create_for_group + resources "/members", MemberController + resources "/requests", GroupRequestController + resources "/sessions", SessionController, except: [:index, :show] + resources "/tracks", TrackController, except: [:index, :show] + get "/tracks/:id/sessions", SessionController, :show_sessions_for_track resources "/categories", CategoryController resources "/tags", TagController - resources "/event_accounts", EventAccountsController - resources "/event_requests", EventRequestController - resources "/groups", GroupController, except: [:index] - resources "/group_accounts", GroupAccountController - resources "/group_requests", GroupRequestController - resources "/sessions", SessionController, except: [:new, :edit] - resources "/tracks", TrackController, except: [:new, :edit] end scope "/", EventosWeb do diff --git a/lib/eventos_web/views/account_view.ex b/lib/eventos_web/views/account_view.ex index c36373bd0..e6c49caea 100644 --- a/lib/eventos_web/views/account_view.ex +++ b/lib/eventos_web/views/account_view.ex @@ -3,23 +3,27 @@ defmodule EventosWeb.AccountView do View for Accounts """ use EventosWeb, :view - alias EventosWeb.AccountView + alias EventosWeb.{AccountView, EventView} def render("index.json", %{accounts: accounts}) do - %{data: render_many(accounts, AccountView, "account_for_user.json")} + %{data: render_many(accounts, AccountView, "acccount_basic.json")} end def render("show.json", %{account: account}) do %{data: render_one(account, AccountView, "account.json")} end - def render("account_for_user.json", %{account: account}) do + def render("show_basic.json", %{account: account}) do + %{data: render_one(account, AccountView, "account_basic.json")} + end + + def render("acccount_basic.json", %{account: account}) do %{id: account.id, username: account.username, domain: account.domain, display_name: account.display_name, description: account.description, - public_key: account.public_key, + # public_key: account.public_key, suspended: account.suspended, uri: account.uri, url: account.url, @@ -32,11 +36,11 @@ defmodule EventosWeb.AccountView do domain: account.domain, display_name: account.display_name, description: account.description, - public_key: account.public_key, + # public_key: account.public_key, suspended: account.suspended, uri: account.uri, url: account.url, - organized_events: account.organized_events + organized_events: render_many(account.organized_events, EventView, "event_simple.json") } end end diff --git a/lib/eventos_web/views/event_view.ex b/lib/eventos_web/views/event_view.ex index 3e013157a..d63686a2f 100644 --- a/lib/eventos_web/views/event_view.ex +++ b/lib/eventos_web/views/event_view.ex @@ -3,21 +3,38 @@ defmodule EventosWeb.EventView do View for Events """ use EventosWeb, :view - alias EventosWeb.EventView + alias EventosWeb.{EventView, AccountView, GroupView} def render("index.json", %{events: events}) do - %{data: render_many(events, EventView, "event.json")} + %{data: render_many(events, EventView, "event_simple.json")} + end + + def render("show_simple.json", %{event: event}) do + %{data: render_one(event, EventView, "event_simple.json")} end def render("show.json", %{event: event}) do %{data: render_one(event, EventView, "event.json")} end + def render("event_simple.json", %{event: event}) do + %{id: event.id, + title: event.title, + description: event.description, + begins_on: event.begins_on, + ends_on: event.ends_on, + } + end + def render("event.json", %{event: event}) do %{id: event.id, title: event.title, description: event.description, begins_on: event.begins_on, - ends_on: event.ends_on} + ends_on: event.ends_on, + organizer: render_one(event.organizer_account, AccountView, "acccount_basic.json"), + group: render_one(event.organizer_group, GroupView, "group_basic.json"), + participants: render_many(event.participants, AccountView, "show_basic.json"), + } end end diff --git a/lib/eventos_web/views/group_view.ex b/lib/eventos_web/views/group_view.ex index 883054078..b00a7c725 100644 --- a/lib/eventos_web/views/group_view.ex +++ b/lib/eventos_web/views/group_view.ex @@ -3,22 +3,39 @@ defmodule EventosWeb.GroupView do View for Groups """ use EventosWeb, :view - alias EventosWeb.GroupView + alias EventosWeb.{GroupView, AccountView} def render("index.json", %{groups: groups}) do - %{data: render_many(groups, GroupView, "group.json")} + %{data: render_many(groups, GroupView, "group_simple.json")} end def render("show.json", %{group: group}) do %{data: render_one(group, GroupView, "group.json")} end + def render("show_simple.json", %{group: group}) do + %{data: render_one(group, GroupView, "group_simple.json")} + end + + def render("group_simple.json", %{group: group}) do + %{id: group.id, + title: group.title, + description: group.description, + suspended: group.suspended, + url: group.url, + uri: group.uri + } + end + def render("group.json", %{group: group}) do %{id: group.id, title: group.title, description: group.description, suspended: group.suspended, url: group.url, - uri: group.uri} + uri: group.uri, + members: render_many(group.members, AccountView, "acccount_basic.json"), + events: render_many(group.organized_events, EventView, "event_simple.json") + } end end diff --git a/lib/eventos_web/views/user_view.ex b/lib/eventos_web/views/user_view.ex index f3db6669c..9d7ac9d1f 100644 --- a/lib/eventos_web/views/user_view.ex +++ b/lib/eventos_web/views/user_view.ex @@ -28,7 +28,7 @@ defmodule EventosWeb.UserView do def render("user_simple.json", %{user: user}) do %{id: user.id, role: user.role, - account: render_one(user.account, AccountView, "account_for_user.json") + account: render_one(user.account, AccountView, "acccount_basic.json") } end diff --git a/priv/repo/migrations/20180110094758_create_groups.exs b/priv/repo/migrations/20180110092500_create_groups.exs similarity index 100% rename from priv/repo/migrations/20180110094758_create_groups.exs rename to priv/repo/migrations/20180110092500_create_groups.exs diff --git a/priv/repo/migrations/20180110092600_create_events.exs b/priv/repo/migrations/20180110092600_create_events.exs index 4b5dd2946..8774de44c 100644 --- a/priv/repo/migrations/20180110092600_create_events.exs +++ b/priv/repo/migrations/20180110092600_create_events.exs @@ -15,13 +15,15 @@ defmodule Eventos.Repo.Migrations.CreateEvents do add :large_image, :string add :thumbnail, :string add :publish_at, :datetimetz - add :organizer_id, references(:accounts, on_delete: :nothing), null: false + add :organizer_account_id, references(:accounts, on_delete: :nothing) + add :organizer_group_id, references(:groups, on_delete: :nothing) add :category_id, references(:categories, on_delete: :nothing), null: false timestamps() end - create index(:events, [:organizer_id]) + create index(:events, [:organizer_account_id]) + create index(:events, [:organizer_group_id]) create unique_index(:events, [:slug]) end diff --git a/priv/repo/seeds.exs b/priv/repo/seeds.exs index ae6594fb3..03a8cc0c4 100644 --- a/priv/repo/seeds.exs +++ b/priv/repo/seeds.exs @@ -9,7 +9,6 @@ # # We recommend using the bang functions (`insert!`, `update!` # and so on) as they will fail if something goes wrong. -import Logger Eventos.Repo.delete_all Eventos.Accounts.User diff --git a/test/eventos/events/events_test.exs b/test/eventos/events/events_test.exs index 894bc4d5a..1c4069478 100644 --- a/test/eventos/events/events_test.exs +++ b/test/eventos/events/events_test.exs @@ -14,7 +14,7 @@ defmodule Eventos.EventsTest do end def event_fixture do - insert(:event, organizer: account_fixture()) + insert(:event, organizer_account: account_fixture()) end def category_fixture do @@ -42,7 +42,7 @@ defmodule Eventos.EventsTest do test "create_event/1 with valid data creates a event" do {:ok, account} = Accounts.create_account(@account_valid_attrs) category = category_fixture() - valid_attrs_with_account_id = Map.put(@event_valid_attrs, :organizer_id, account.id) + valid_attrs_with_account_id = Map.put(@event_valid_attrs, :organizer_account_id, account.id) valid_attrs_with_account_id = Map.put(valid_attrs_with_account_id, :category_id, category.id) assert {:ok, %Event{} = event} = Events.create_event(valid_attrs_with_account_id) assert event.begins_on == DateTime.from_naive!(~N[2010-04-17 14:00:00.000000Z], "Etc/UTC") diff --git a/test/eventos_web/controllers/event_controller_test.exs b/test/eventos_web/controllers/event_controller_test.exs index c5e51e54d..17d4fd92e 100644 --- a/test/eventos_web/controllers/event_controller_test.exs +++ b/test/eventos_web/controllers/event_controller_test.exs @@ -30,7 +30,7 @@ defmodule EventosWeb.EventControllerTest do describe "create event" do test "renders event when data is valid", %{conn: conn, user: user} do - attrs = Map.put(@create_attrs, :organizer_id, user.account.id) + attrs = Map.put(@create_attrs, :organizer_account_id, user.account.id) category = insert(:category) attrs = Map.put(attrs, :category_id, category.id) @@ -44,12 +44,25 @@ defmodule EventosWeb.EventControllerTest do "begins_on" => "2010-04-17T14:00:00Z", "description" => "some description", "ends_on" => "2010-04-17T14:00:00Z", - "title" => "some title"} + "title" => "some title", + "group" => nil, + "organizer" => %{ + "description" => nil, + "display_name" => nil, + "domain" => nil, + "id" => user.account.id, + "suspended" => false, + "uri" => "https://", + "url" => "https://", + "username" => user.account.username + }, + "participants" => [] + } end test "renders errors when data is invalid", %{conn: conn, user: user} do conn = auth_conn(conn, user) - attrs = Map.put(@invalid_attrs, :organizer_id, user.account.id) + attrs = Map.put(@invalid_attrs, :organizer_account_id, user.account.id) conn = post conn, event_path(conn, :create), event: attrs assert json_response(conn, 422)["errors"] != %{} end @@ -71,7 +84,7 @@ defmodule EventosWeb.EventControllerTest do test "renders event when data is valid", %{conn: conn, event: %Event{id: id} = event, user: user} do conn = auth_conn(conn, user) - attrs = Map.put(@update_attrs, :organizer_id, user.account.id) + attrs = Map.put(@update_attrs, :organizer_account_id, user.account.id) conn = put conn, event_path(conn, :update, event), event: attrs assert %{"id" => ^id} = json_response(conn, 200)["data"] @@ -81,12 +94,25 @@ defmodule EventosWeb.EventControllerTest do "begins_on" => "2011-05-18T15:01:01Z", "description" => "some updated description", "ends_on" => "2011-05-18T15:01:01Z", - "title" => "some updated title"} + "title" => "some updated title", + "group" => nil, + "organizer" => %{ + "description" => nil, + "display_name" => nil, + "domain" => nil, + "id" => user.account.id, + "suspended" => false, + "uri" => "https://", + "url" => "https://", + "username" => user.account.username + }, + "participants" => [] + } end test "renders errors when data is invalid", %{conn: conn, event: event, user: user} do conn = auth_conn(conn, user) - attrs = Map.put(@invalid_attrs, :organizer_id, user.account.id) + attrs = Map.put(@invalid_attrs, :organizer_account_id, user.account.id) conn = put conn, event_path(conn, :update, event), event: attrs assert json_response(conn, 422)["errors"] != %{} end @@ -107,7 +133,7 @@ defmodule EventosWeb.EventControllerTest do defp create_event(_) do account = insert(:account) - event = insert(:event, organizer: account) + event = insert(:event, organizer_account: account) {:ok, event: event, account: account} end diff --git a/test/eventos_web/controllers/group_controller_test.exs b/test/eventos_web/controllers/group_controller_test.exs index 88f494c99..6b4813037 100644 --- a/test/eventos_web/controllers/group_controller_test.exs +++ b/test/eventos_web/controllers/group_controller_test.exs @@ -40,8 +40,11 @@ defmodule EventosWeb.GroupControllerTest do "description" => "some description", "suspended" => true, "title" => "some title", - "uri" => "some uri", - "url" => "some url"} + "uri" => "h", + "url" => "h", + "events" => [], + "members" => [] + } end test "renders errors when data is invalid", %{conn: conn, user: user} do @@ -66,7 +69,10 @@ defmodule EventosWeb.GroupControllerTest do "suspended" => false, "title" => "some updated title", "uri" => "some updated uri", - "url" => "some updated url"} + "url" => "some updated url", + "events" => [], + "members" => [] + } end test "renders errors when data is invalid", %{conn: conn, group: group, user: user} do diff --git a/test/eventos_web/controllers/session_controller_test.exs b/test/eventos_web/controllers/session_controller_test.exs index d1d1620c1..bae187c5b 100644 --- a/test/eventos_web/controllers/session_controller_test.exs +++ b/test/eventos_web/controllers/session_controller_test.exs @@ -18,7 +18,7 @@ defmodule EventosWeb.SessionControllerTest do setup %{conn: conn} do account = insert(:account) user = insert(:user, account: account) - event = insert(:event, organizer: account) + event = insert(:event, organizer_account: account) {:ok, conn: conn, user: user, event: event} end @@ -32,10 +32,14 @@ defmodule EventosWeb.SessionControllerTest do describe "create session" do test "renders session when data is valid", %{conn: conn, user: user, event: event} do conn = auth_conn(conn, user) - attrs = Map.put(@create_attrs, :event_id, event.id) + event_id = event.id + attrs = Map.put(@create_attrs, :event_id, event_id) conn = post conn, session_path(conn, :create), session: attrs assert %{"id" => id} = json_response(conn, 201)["data"] + conn = get conn, "/api/events/" <> Integer.to_string(event_id) <> "/sessions" + assert hd(json_response(conn, 200)["data"])["id"] == id + conn = get conn, session_path(conn, :show, id) assert json_response(conn, 200)["data"] == %{ "id" => id, diff --git a/test/eventos_web/controllers/track_controller_test.exs b/test/eventos_web/controllers/track_controller_test.exs index 801853484..90b815210 100644 --- a/test/eventos_web/controllers/track_controller_test.exs +++ b/test/eventos_web/controllers/track_controller_test.exs @@ -18,7 +18,7 @@ defmodule EventosWeb.TrackControllerTest do setup %{conn: conn} do account = insert(:account) user = insert(:user, account: account) - event = insert(:event, organizer: account) + event = insert(:event, organizer_account: account) {:ok, conn: conn, user: user, event: event} end diff --git a/test/support/factory.ex b/test/support/factory.ex index 21e0927c7..cf3933370 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -39,7 +39,7 @@ defmodule Eventos.Factory do description: "My desc", begins_on: nil, ends_on: nil, - organizer: build(:account), + organizer_account: build(:account), category: build(:category) } end