Skip to content

Commit

Permalink
fixup 5
Browse files Browse the repository at this point in the history
  • Loading branch information
electronicbites committed Nov 13, 2024
1 parent f74d4f4 commit 77fd320
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/radiator/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ defmodule Radiator.Accounts do
%{data: data} = service ->
data =
Map.update!(data, :collection_mappings, fn mappings ->
Map.put(mappings, show_id, collection_id)
Map.put(mappings, show_id_to_collection_id(show_id), collection_id)
end)
|> Map.from_struct()

Expand All @@ -323,6 +323,9 @@ defmodule Radiator.Accounts do
end
end

defp show_id_to_collection_id(show_id) when is_integer(show_id), do: Integer.to_string(show_id)
defp show_id_to_collection_id(show_id), do: show_id

## Session

@doc """
Expand Down
33 changes: 33 additions & 0 deletions test/radiator/accounts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -711,5 +711,38 @@ defmodule Radiator.AccountsTest do
service = Accounts.get_raindrop_tokens(web_service.user_id)
assert service.data.collection_mappings == %{"#{show.id}" => 42}
end

test "can add multiple shows", %{
web_service: web_service,
show: show
} do
Accounts.connect_show_with_raindrop(web_service.user_id, show.id, 42)

second_show = PodcastFixtures.show_fixture()
third_show = PodcastFixtures.show_fixture()

Accounts.connect_show_with_raindrop(web_service.user_id, second_show.id, 23)
Accounts.connect_show_with_raindrop(web_service.user_id, third_show.id, 666)

service = Accounts.get_raindrop_tokens(web_service.user_id)

assert service.data.collection_mappings == %{
"#{show.id}" => 42,
"#{second_show.id}" => 23,
"#{third_show.id}" => 666
}
end

test "can override show", %{
web_service: web_service,
show: show
} do
Accounts.connect_show_with_raindrop(web_service.user_id, show.id, 42)

Accounts.connect_show_with_raindrop(web_service.user_id, show.id, 23)
service = Accounts.get_raindrop_tokens(web_service.user_id)

assert service.data.collection_mappings == %{"#{show.id}" => 23}
end
end
end

0 comments on commit 77fd320

Please sign in to comment.