Skip to content

Commit

Permalink
Merge pull request #409 from midarrlabs/feature/add-follow-series
Browse files Browse the repository at this point in the history
Add follow series
  • Loading branch information
trueChazza authored Oct 9, 2023
2 parents 315744f + 232d9c1 commit 2d6f028
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lib/media_server_web/live/series_live/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,25 @@
</div>
</div>

<h1><%= @serie["title"] %></h1>

<div class="not-prose mb-16 mt-6 flex gap-3"></div>
<header class="flex flex-col gap-y-2">
<div class="flex items-center gap-6">
<div class="flex flex-col">
<h1 class="text-4xl font-bold text-slate-900"><%= @serie["title"] %></h1>
</div>
</div>
<div class="flex gap-x-4 items-center">
<.live_component
module={MediaServerWeb.Components.FollowComponent}
id="followComponent"
media_id={@serie["id"]}
media_type="series"
user_id={@current_user.id}
return_to={~p"/series/#{@serie["id"]}"}
/>
</div>
</header>

<h2 class="scroll-mt-24">Overview</h2>
<h2>Overview</h2>

<p class="lead">
<%= @serie["overview"] %>
Expand Down
4 changes: 4 additions & 0 deletions priv/repo/seeds.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ MediaServer.MediaTypes.create(%{
type: "movie"
})

MediaServer.MediaTypes.create(%{
type: "series"
})

MediaServer.MediaTypes.create(%{
type: "episode"
})
Expand Down
52 changes: 52 additions & 0 deletions test/media_server_web/user_follow_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,58 @@ defmodule MediaServerWeb.UserFollowTest do
assert Enum.count(media) === 0
end

test "it should follow series", %{conn: conn, user: user} do
Phoenix.PubSub.subscribe(MediaServer.PubSub, "user")

series = MediaServer.SeriesIndex.all() |> List.first()

{:ok, view, _html} = live(conn, ~p"/series/#{series["id"]}")

view
|> element("#follow", "Follow")
|> render_hook(:follow, %{media_id: series["id"], media_type: "series", user_id: user.id})

assert_received {:followed, %{"media_id" => 1, "media_type" => "series", "user_id" => _user_id}}

# Not ideal but wait for processed message (async)
:timer.sleep(1000)

media = MediaServer.MediaActions.all()

assert Enum.count(media) === 1

assert Enum.at(media, 0).media_id === series["id"]
assert Enum.at(media, 0).action_id === MediaServer.Actions.get_followed_id()
end

test "it should unfollow series", %{conn: conn, user: user} do
Phoenix.PubSub.subscribe(MediaServer.PubSub, "user")

series = MediaServer.SeriesIndex.all() |> List.first()

MediaServer.MediaActions.create(%{
media_id: series["id"],
user_id: user.id,
action_id: MediaServer.Actions.get_followed_id(),
media_type_id: MediaServer.MediaTypes.get_type_id("series")
})

{:ok, view, _html} = live(conn, ~p"/series/#{series["id"]}")

view
|> element("#follow", "Following")
|> render_hook(:unfollow, %{media_id: series["id"], media_type: "series", user_id: user.id})

assert_received {:unfollowed, %{"media_id" => 1, "media_type" => "series", "user_id" => _user_id}}

# Not ideal but wait for processed message (async)
:timer.sleep(1000)

media = MediaServer.MediaActions.all()

assert Enum.count(media) === 0
end

test "it should grant push notifications", %{conn: conn, user: user} do
Phoenix.PubSub.subscribe(MediaServer.PubSub, "user")

Expand Down

0 comments on commit 2d6f028

Please sign in to comment.