Skip to content

Commit

Permalink
Clean the house (rauversion#26)
Browse files Browse the repository at this point in the history
* silent warns

* specs on peaks

* live helpers tests

* status badge
  • Loading branch information
michelson authored Jul 16, 2022
1 parent 4edd3ba commit fb7286a
Show file tree
Hide file tree
Showing 21 changed files with 109 additions and 65 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

![image](https://user-images.githubusercontent.com/11976/174422926-b392a1f5-bd6a-4bd2-b6c8-8d41dad6711d.png)

[![.github/workflows/ci.yml](https://github.com/rauversion/rauversion-phx/actions/workflows/ci.yml/badge.svg)](https://github.com/rauversion/rauversion-phx/actions/workflows/ci.yml)

Rauversion is an open source music sharing platform.

Rauversion is built on Elixir with Phoenix framework.
Expand Down
9 changes: 6 additions & 3 deletions lib/rauversion/tracks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defmodule Rauversion.Tracks do
end

def signed_id(track) do
token = Phoenix.Token.sign(RauversionWeb.Endpoint, "user auth", track.id)
Phoenix.Token.sign(RauversionWeb.Endpoint, "user auth", track.id)
end

def find_by_signed_id!(token) do
Expand Down Expand Up @@ -76,7 +76,10 @@ defmodule Rauversion.Tracks do
|> Repo.preload(:user)
end

def preload_tracks_preloaded_by_user(query, current_user_id = %Rauversion.Accounts.User{id: id}) do
def preload_tracks_preloaded_by_user(
query,
_current_user_id = %Rauversion.Accounts.User{id: id}
) do
likes_query =
from pi in Rauversion.TrackLikes.TrackLike,
where: pi.user_id == ^id
Expand All @@ -89,7 +92,7 @@ defmodule Rauversion.Tracks do
|> Repo.preload(likes: likes_query, reposts: reposts_query)
end

def preload_tracks_preloaded_by_user(query, current_user_id = nil) do
def preload_tracks_preloaded_by_user(query, _current_user_id = nil) do
query
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule RauversionWeb.ProfileLive.StatsComponent do
# use Phoenix.LiveComponent
use RauversionWeb, :live_component

def render(%{track: track, profile: profile} = assigns) do
def render(%{track: _track, profile: profile} = assigns) do
~H"""
<div class="grid grid-cols-3 divide-x">
<div class="p-4">
Expand Down
2 changes: 0 additions & 2 deletions lib/rauversion_web/live/profile_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ defmodule RauversionWeb.ProfileLive.Index do
end

def handle_params(%{"sort_by" => _sort_by}, _url, _socket) do
require IEx
IEx.pry()
# post_id = socket.assigns.post.id
# do something with sort_by
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defmodule RauversionWeb.TrackLive.CommentsComponent do
@impl true
def handle_event(
"validate",
%{"_target" => ["track_comment", "body"], "track_comment" => %{"body" => body}},
%{"_target" => ["track_comment", "body"], "track_comment" => %{"body" => _body}},
socket
) do
{:noreply, socket}
Expand Down
12 changes: 7 additions & 5 deletions lib/rauversion_web/live/track_live/components/track_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule RauversionWeb.TrackLive.TrackComponent do
@impl true
def update(assigns = %{current_user: _current_user}, socket) do
case assigns do
%{current_user: current_user} ->
%{current_user: _current_user} ->
repost =
case assigns.track.reposts do
[repost] -> repost
Expand Down Expand Up @@ -48,8 +48,10 @@ defmodule RauversionWeb.TrackLive.TrackComponent do
@impl true
def handle_event(
"like-track",
%{"id" => id},
socket = %{assigns: %{track: track, current_user: current_user}}
%{"id" => _id},
socket = %{
assigns: %{track: track, current_user: current_user = %Rauversion.Accounts.User{}}
}
) do
attrs = %{user_id: current_user.id, track_id: track.id}

Expand All @@ -70,7 +72,7 @@ defmodule RauversionWeb.TrackLive.TrackComponent do
def handle_event(
"like-track",
%{"id" => _id},
socket = %{assigns: %{track: _track, current_user: nil}}
socket = %{assigns: %{track: _track, current_user: _user = nil}}
) do
# TODO: SHOW MODAL HERE
{:noreply, socket}
Expand All @@ -79,7 +81,7 @@ defmodule RauversionWeb.TrackLive.TrackComponent do
@impl true
def handle_event(
"repost-track",
%{"id" => id},
%{"id" => _id},
socket = %{
assigns: %{track: track, current_user: current_user = %Rauversion.Accounts.User{}}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ defmodule RauversionWeb.TrackLive.TrackListingComponent do
{:ok, socket, temporary_assigns: [messages: []]}
end

@impl true
def handle_event("paginate", %{}, socket) do
{:noreply,
socket
|> assign(:page, socket.assigns.page + 1)
|> assign(:tracks, list_tracks(socket.assigns))}
end

@impl true
def update(assigns, socket) do
tracks = list_tracks(assigns)
Expand All @@ -32,7 +24,15 @@ defmodule RauversionWeb.TrackLive.TrackListingComponent do

defp list_tracks(page) do
Tracks.list_public_tracks()
|> Rauversion.Repo.paginate(page: page, page_size: 5)
|> Repo.paginate(page: page, page_size: 5)
end

@impl true
def handle_event("paginate", %{}, socket) do
{:noreply,
socket
|> assign(:page, socket.assigns.page + 1)
|> assign(:tracks, list_tracks(socket.assigns))}
end

@impl true
Expand Down
7 changes: 3 additions & 4 deletions lib/rauversion_web/templates/layout/_user_menu.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Tracks
<% end %>

<% live_redirect to: "/users/settings", class: "rounded-md py-2 px-3 text-sm font-medium text-white hover:bg-gray-800" do %>
<%= live_redirect to: "/users/settings", class: "rounded-md py-2 px-3 text-sm font-medium text-white hover:bg-gray-800" do %>
Account
<% end %>

Expand Down Expand Up @@ -44,9 +44,8 @@
</div>

<div class="flex items-center px-2 lg:px-0">
<% live_redirect to: "/tracks/new",
class: "rounded-md py-2 px-3 text-sm font-medium text-white hover:bg-orange-600" do %>
upload
<%= live_redirect to: "/tracks/new",
class: "rounded-md py-2 px-3 text-sm font-medium text-white hover:bg-orange-600" do %>upload
<% end %>
</div>

Expand Down
2 changes: 1 addition & 1 deletion test/rauversion/mp3_converter_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Rauversion.Services.Mp3ConverterTest do
use Rauversion.DataCase

alias Rauversion.Playlists
# alias Rauversion.Playlists

describe "peaks generator" do
test "peaks gen" do
Expand Down
14 changes: 5 additions & 9 deletions test/rauversion/peak_genenerator_test.exs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
defmodule Rauversion.PeaksGeneratorTest do
use Rauversion.DataCase

alias Rauversion.Playlists
# alias Rauversion.Playlists

describe "peaks generator" do
test "peaks gen" do
assert [hd | rest] =
@tag skip: "this test is incomplete - decide on final biz logic and assert"
test "peaks gen with audiowebsurfer" do
assert [_hd | rest] =
Rauversion.Services.PeaksGenerator.run_audiowaveform("./test/files/audio.mp3", 3)

IO.inspect(rest)
IO.inspect("qty: #{rest |> length}")
end

test "peaks gen ffprobe" do
a = Rauversion.Services.PeaksGenerator.run_ffprobe("./test/files/audio.mp3", 3)
require IEx
IEx.pry()
assert [_ | _] = Rauversion.Services.PeaksGenerator.run_ffprobe("./test/files/audio.mp3", 3)
end

test "desired pixels" do
Expand All @@ -24,9 +23,6 @@ defmodule Rauversion.PeaksGeneratorTest do

pixels_per_second =
Rauversion.Services.PeaksGenerator.desired_pixels_per_second(desired_pixels, duration)

require IEx
IEx.pry()
end
end
end
4 changes: 2 additions & 2 deletions test/rauversion/playlist_likes_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ defmodule Rauversion.PlaylistLikesTest do
} do
valid_attrs = %{user_id: user.id, playlist_id: playlist.id}

assert {:ok, %PlaylistLike{} = playlist_like} =
assert {:ok, %PlaylistLike{} = _playlist_like} =
PlaylistLikes.create_playlist_like(valid_attrs)
end

Expand All @@ -52,7 +52,7 @@ defmodule Rauversion.PlaylistLikesTest do
playlist_like = playlist_like_fixture(%{user_id: user.id, playlist_id: playlist.id})
update_attrs = %{}

assert {:ok, %PlaylistLike{} = playlist_like} =
assert {:ok, %PlaylistLike{} = _playlist_like} =
PlaylistLikes.update_playlist_like(playlist_like, update_attrs)
end

Expand Down
2 changes: 1 addition & 1 deletion test/rauversion/playlists_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ defmodule Rauversion.PlaylistsTest do
track_playlists: [%{track_id: track.id}]
})

length(result.track_playlists) == 1
assert length(result.track_playlists) == 1
end
end
end
6 changes: 3 additions & 3 deletions test/rauversion/reposts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule Rauversion.RepostsTest do
def valid_repost() do
user = user_fixture(%{username: "miki"})
track = track_fixture(%{user_id: user.id})
repost = repost_fixture(%{user_id: user.id, track_id: track.id})
repost_fixture(%{user_id: user.id, track_id: track.id})
end

test "list_reposts/0 returns all reposts" do
Expand All @@ -37,7 +37,7 @@ defmodule Rauversion.RepostsTest do
track = track_fixture(%{user_id: user.id})
valid_attrs = %{user_id: user.id, track_id: track.id}

assert {:ok, %Repost{} = repost} = Reposts.create_repost(valid_attrs)
assert {:ok, %Repost{} = _repost} = Reposts.create_repost(valid_attrs)
end

test "create_repost/1 with invalid data returns error changeset" do
Expand All @@ -48,7 +48,7 @@ defmodule Rauversion.RepostsTest do
repost = valid_repost()
update_attrs = %{}

assert {:ok, %Repost{} = repost} = Reposts.update_repost(repost, update_attrs)
assert {:ok, %Repost{} = _repost} = Reposts.update_repost(repost, update_attrs)
end

test "update_repost/2 with invalid data returns error changeset" do
Expand Down
2 changes: 1 addition & 1 deletion test/rauversion/track_comments_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Rauversion.TrackCommentsTest do
alias Rauversion.TrackComments.TrackComment

import Rauversion.{
RepostsFixtures,
# RepostsFixtures,
TracksFixtures,
AccountsFixtures,
TrackCommentsFixtures
Expand Down
6 changes: 3 additions & 3 deletions test/rauversion/track_likes_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Rauversion.TrackLikesTest do

import Rauversion.{
TrackLikesFixtures,
RepostsFixtures,
# RepostsFixtures,
TracksFixtures,
AccountsFixtures
}
Expand All @@ -34,7 +34,7 @@ defmodule Rauversion.TrackLikesTest do
test "create_track_like/1 with valid data creates a track_like", %{user: user, track: track} do
valid_attrs = %{user_id: user.id, track_id: track.id}

assert {:ok, %TrackLike{} = track_like} = TrackLikes.create_track_like(valid_attrs)
assert {:ok, %TrackLike{} = _track_like} = TrackLikes.create_track_like(valid_attrs)
end

test "create_track_like/1 with invalid data returns error changeset" do
Expand All @@ -45,7 +45,7 @@ defmodule Rauversion.TrackLikesTest do
track_like = track_like_fixture(%{user_id: user.id, track_id: track.id})
update_attrs = %{}

assert {:ok, %TrackLike{} = track_like} =
assert {:ok, %TrackLike{} = _track_like} =
TrackLikes.update_track_like(track_like, update_attrs)
end

Expand Down
4 changes: 2 additions & 2 deletions test/rauversion/user_follows_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule Rauversion.UserFollowsTest do
following_id: user2.id
}

assert {:ok, %UserFollow{} = user_follow} = UserFollows.create_user_follow(valid_attrs)
assert {:ok, %UserFollow{} = _user_follow} = UserFollows.create_user_follow(valid_attrs)
end

test "create_user_follow/1 with invalid data returns error changeset" do
Expand All @@ -68,7 +68,7 @@ defmodule Rauversion.UserFollowsTest do

update_attrs = %{}

assert {:ok, %UserFollow{} = user_follow} =
assert {:ok, %UserFollow{} = _user_follow} =
UserFollows.update_user_follow(user_follow, update_attrs)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule RauversionWeb.UserRegistrationControllerTest do
test "renders registration page", %{conn: conn} do
conn = get(conn, Routes.user_registration_path(conn, :new))
response = html_response(conn, 200)
assert response =~ "<h1>Register</h1>"
assert response =~ "Register"
assert response =~ "Log in</a>"
assert response =~ "Register</a>"
end
Expand Down Expand Up @@ -46,7 +46,7 @@ defmodule RauversionWeb.UserRegistrationControllerTest do
})

response = html_response(conn, 200)
assert response =~ "<h1>Register</h1>"
assert response =~ "Register"
assert response =~ "must have the @ sign and no spaces"
assert response =~ "should be at least 12 character"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule RauversionWeb.UserResetPasswordControllerTest do
test "renders the reset password page", %{conn: conn} do
conn = get(conn, Routes.user_reset_password_path(conn, :new))
response = html_response(conn, 200)
assert response =~ "<h1>Forgot your password?</h1>"
assert response =~ "Forgot your password?"
end
end

Expand Down Expand Up @@ -54,7 +54,7 @@ defmodule RauversionWeb.UserResetPasswordControllerTest do

test "renders reset password", %{conn: conn, token: token} do
conn = get(conn, Routes.user_reset_password_path(conn, :edit, token))
assert html_response(conn, 200) =~ "<h1>Reset password</h1>"
assert html_response(conn, 200) =~ "Reset password"
end

test "does not render reset password with invalid token", %{conn: conn} do
Expand Down Expand Up @@ -99,7 +99,7 @@ defmodule RauversionWeb.UserResetPasswordControllerTest do
})

response = html_response(conn, 200)
assert response =~ "<h1>Reset password</h1>"
assert response =~ "Reset password"
assert response =~ "should be at least 12 character(s)"
assert response =~ "does not match password"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule RauversionWeb.UserSessionControllerTest do
test "renders log in page", %{conn: conn} do
conn = get(conn, Routes.user_session_path(conn, :new))
response = html_response(conn, 200)
assert response =~ "<h1>Log in</h1>"
assert response =~ "Sign in to your account"
assert response =~ "Register</a>"
assert response =~ "Forgot your password?</a>"
end
Expand Down Expand Up @@ -75,7 +75,7 @@ defmodule RauversionWeb.UserSessionControllerTest do
})

response = html_response(conn, 200)
assert response =~ "<h1>Log in</h1>"
assert response =~ "Log in"
assert response =~ "Invalid email or password"
end
end
Expand Down
Loading

0 comments on commit fb7286a

Please sign in to comment.