pinchflat/test/pinchflat/settings_test.exs
Kieran 4994e70652
[Bugfix] Partially revert custom codec selection (#279)
* Removed and re-added codec preference columns

* Removed custom codec work from download options builder

* Updated settings UI

* Made codec preferences non-optional fields
2024-06-04 09:19:37 -07:00

81 lines
2.1 KiB
Elixir

defmodule Pinchflat.SettingsTest do
use Pinchflat.DataCase
alias Pinchflat.Settings
alias Pinchflat.Settings.Setting
# NOTE: We're treating some of these tests differently
# than in other modules because certain settings
# are always created on app boot (including in the test env),
# so we can't treat these like a clean slate.
setup do
# Ensure we have a clean slate
Settings.set(onboarding: false)
Settings.set(pro_enabled: false)
Settings.set(yt_dlp_version: nil)
:ok
end
describe "record/0" do
test "returns the only setting" do
assert %Setting{} = Settings.record()
end
end
describe "update_setting/2" do
test "updates the setting" do
setting = Settings.record()
assert {:ok, false} = Settings.get(:onboarding)
assert {:ok, %Setting{}} = Settings.update_setting(setting, %{onboarding: true})
assert {:ok, true} = Settings.get(:onboarding)
end
end
describe "set/1" do
test "updates the setting" do
assert {:ok, true} = Settings.set(onboarding: true)
assert {:ok, true} = Settings.get(:onboarding)
end
test "returns an error if the setting key doesn't exist" do
assert {:error, :invalid_key} = Settings.set(foo: "bar")
end
test "returns an error if the setting value is invalid" do
assert {:error, %Ecto.Changeset{}} = Settings.set(onboarding: "bar")
end
end
describe "get/1" do
test "returns the setting value" do
assert {:ok, false} = Settings.get(:onboarding)
end
test "returns an error if the setting key doesn't exist" do
assert {:error, :invalid_key} = Settings.get(:foo)
end
end
describe "get!/1" do
test "returns the setting value" do
assert Settings.get!(:onboarding) == false
end
test "raises an error if the setting key doesn't exist" do
assert_raise RuntimeError, "Setting `foo` not found", fn ->
Settings.get!(:foo)
end
end
end
describe "change_setting/2" do
test "returns a changeset" do
setting = Settings.record()
assert %Ecto.Changeset{} = Settings.change_setting(setting, %{onboarding: true})
end
end
end