Skip to content

Commit

Permalink
feat: add has subtitle helper
Browse files Browse the repository at this point in the history
  • Loading branch information
trueChazza committed Jun 23, 2022
1 parent fe05359 commit ea78830
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/media_server_web/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ defmodule MediaServerWeb.Helpers do
|> Enum.filter(fn item -> String.contains?(item, ".srt") end)
|> List.first()
end

def has_subtitle(path) do
!is_nil(get_subtitle(path))
end
end
16 changes: 14 additions & 2 deletions test/media_server_web/helpers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,31 @@ defmodule MediaServerWeb.HelpersTest do
@expected [".DS_Store", "Caminandes.Llama.Drama.1080p.mp4", "Caminandes.Llama.Drama.1080p.srt"]
@filtered "Caminandes.Llama.Drama.1080p.srt"

test "it should have subtitle" do
test "it should get subtitle" do
assert File.ls!(@path) == @expected

assert MediaServerWeb.Helpers.get_subtitle(@path) == @filtered
end

test "it has subtitle" do
assert File.ls!(@path) == @expected

assert MediaServerWeb.Helpers.has_subtitle(@path)
end

@path_without "fixtures/movies/Caminandes Gran Dillama (2013)"
@expected_without [".DS_Store", "Caminandes.Gran.Dillama.1080p.mp4"]
@filtered_without nil

test "it should not have subtitle" do
test "it should not get subtitle" do
assert File.ls!(@path_without) == @expected_without

assert MediaServerWeb.Helpers.get_subtitle(@path_without) == @filtered_without
end

test "it does not have subtitle" do
assert File.ls!(@path_without) == @expected_without

refute MediaServerWeb.Helpers.has_subtitle(@path_without)
end
end

0 comments on commit ea78830

Please sign in to comment.