[WIP] renamed current settings module and tables to have backup suffix
This commit is contained in:
parent
d9053fff0c
commit
4ff2cc445f
20 changed files with 108 additions and 101 deletions
2
.iex.exs
2
.iex.exs
|
|
@ -11,7 +11,7 @@ alias Pinchflat.Tasks
|
|||
alias Pinchflat.Media
|
||||
alias Pinchflat.Profiles
|
||||
alias Pinchflat.Sources
|
||||
alias Pinchflat.Settings
|
||||
alias Pinchflat.SettingsBackup
|
||||
|
||||
alias Pinchflat.Downloading.MediaDownloader
|
||||
alias Pinchflat.YtDlp.Media, as: YtDlpMedia
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ defmodule Pinchflat.Boot.PreJobStartupTasks do
|
|||
require Logger
|
||||
|
||||
alias Pinchflat.Repo
|
||||
alias Pinchflat.Settings
|
||||
alias Pinchflat.SettingsBackup
|
||||
alias Pinchflat.YtDlp.CommandRunner
|
||||
alias Pinchflat.Filesystem.FilesystemHelpers
|
||||
|
||||
|
|
@ -65,8 +65,8 @@ defmodule Pinchflat.Boot.PreJobStartupTasks do
|
|||
defp apply_default_settings do
|
||||
{:ok, yt_dlp_version} = CommandRunner.version()
|
||||
|
||||
Settings.fetch!(:onboarding, true)
|
||||
Settings.fetch!(:pro_enabled, false)
|
||||
Settings.set!(:yt_dlp_version, yt_dlp_version)
|
||||
SettingsBackup.fetch!(:onboarding, true)
|
||||
SettingsBackup.fetch!(:pro_enabled, false)
|
||||
SettingsBackup.set!(:yt_dlp_version, yt_dlp_version)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
defmodule Pinchflat.Settings.Setting do
|
||||
defmodule Pinchflat.SettingsBackup.SettingBackup do
|
||||
@moduledoc """
|
||||
A Setting is a key-value pair with a datatype used to track user-level settings.
|
||||
"""
|
||||
|
|
@ -6,7 +6,7 @@ defmodule Pinchflat.Settings.Setting do
|
|||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "settings" do
|
||||
schema "settings_backup" do
|
||||
field :name, :string
|
||||
field :value, :string
|
||||
field :datatype, Ecto.Enum, values: ~w(boolean string integer float)a
|
||||
|
|
@ -1,20 +1,20 @@
|
|||
defmodule Pinchflat.Settings do
|
||||
defmodule Pinchflat.SettingsBackup do
|
||||
@moduledoc """
|
||||
The Settings context.
|
||||
The SettingsBackup context.
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
alias Pinchflat.Repo
|
||||
|
||||
alias Pinchflat.Settings.Setting
|
||||
alias Pinchflat.SettingsBackup.SettingBackup
|
||||
|
||||
@doc """
|
||||
Returns the list of settings.
|
||||
|
||||
Returns [%Setting{}, ...]
|
||||
Returns [%SettingBackup{}, ...]
|
||||
"""
|
||||
def list_settings do
|
||||
Repo.all(Setting)
|
||||
Repo.all(SettingBackup)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
@ -30,7 +30,7 @@ defmodule Pinchflat.Settings do
|
|||
|
||||
def set!(name, value, datatype) do
|
||||
# Only create if doesn't exist
|
||||
case Repo.get_by(Setting, name: to_string(name)) do
|
||||
case Repo.get_by(SettingBackup, name: to_string(name)) do
|
||||
nil -> create_setting!(name, value, datatype)
|
||||
setting -> update_setting!(setting, value, datatype)
|
||||
end
|
||||
|
|
@ -42,7 +42,7 @@ defmodule Pinchflat.Settings do
|
|||
Returns value in type of `Ecto.Enum.mappings(Setting, :datatype)`
|
||||
"""
|
||||
def get!(name) do
|
||||
Setting
|
||||
SettingBackup
|
||||
|> Repo.get_by!(name: to_string(name))
|
||||
|> read_setting()
|
||||
end
|
||||
|
|
@ -59,18 +59,18 @@ defmodule Pinchflat.Settings do
|
|||
end
|
||||
|
||||
def fetch!(name, value, datatype) do
|
||||
case Repo.get_by(Setting, name: to_string(name)) do
|
||||
case Repo.get_by(SettingBackup, name: to_string(name)) do
|
||||
nil -> create_setting!(name, value, datatype)
|
||||
setting -> read_setting(setting)
|
||||
end
|
||||
end
|
||||
|
||||
defp change_setting(setting, attrs) do
|
||||
Setting.changeset(setting, attrs)
|
||||
SettingBackup.changeset(setting, attrs)
|
||||
end
|
||||
|
||||
defp create_setting!(name, value, datatype) do
|
||||
%Setting{}
|
||||
%SettingBackup{}
|
||||
|> change_setting(%{name: to_string(name), value: to_string(value), datatype: datatype})
|
||||
|> Repo.insert!()
|
||||
|> read_setting()
|
||||
|
|
@ -45,7 +45,7 @@ defmodule PinchflatWeb do
|
|||
import Plug.Conn
|
||||
import PinchflatWeb.Gettext
|
||||
|
||||
alias Pinchflat.Settings
|
||||
alias Pinchflat.SettingsBackup
|
||||
alias PinchflatWeb.Layouts
|
||||
|
||||
unquote(verified_routes())
|
||||
|
|
@ -58,7 +58,7 @@ defmodule PinchflatWeb do
|
|||
|
||||
use Phoenix.LiveView
|
||||
|
||||
alias Pinchflat.Settings
|
||||
alias Pinchflat.SettingsBackup
|
||||
|
||||
unquote(html_helpers())
|
||||
end
|
||||
|
|
@ -68,7 +68,7 @@ defmodule PinchflatWeb do
|
|||
quote do
|
||||
use Phoenix.LiveComponent
|
||||
|
||||
alias Pinchflat.Settings
|
||||
alias Pinchflat.SettingsBackup
|
||||
|
||||
unquote(html_helpers())
|
||||
end
|
||||
|
|
@ -82,7 +82,7 @@ defmodule PinchflatWeb do
|
|||
import Phoenix.Controller,
|
||||
only: [get_csrf_token: 0, view_module: 1, view_template: 1]
|
||||
|
||||
alias Pinchflat.Settings
|
||||
alias Pinchflat.SettingsBackup
|
||||
|
||||
# Include general helpers for rendering HTML
|
||||
unquote(html_helpers())
|
||||
|
|
@ -101,7 +101,7 @@ defmodule PinchflatWeb do
|
|||
import PinchflatWeb.CustomComponents.TableComponents
|
||||
import PinchflatWeb.CustomComponents.ButtonComponents
|
||||
|
||||
alias Pinchflat.Settings
|
||||
alias Pinchflat.SettingsBackup
|
||||
alias Pinchflat.Utils.StringUtils
|
||||
|
||||
# Shortcut for generating JS commands
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@
|
|||
Pinchflat v<%= Application.spec(:pinchflat)[:vsn] %>
|
||||
</span>
|
||||
<span class="group relative flex items-center gap-2.5 px-4 text-sm">
|
||||
yt-dlp <%= Settings.get!(:yt_dlp_version) %>
|
||||
yt-dlp <%= SettingsBackup.get!(:yt_dlp_version) %>
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ defmodule Pinchflat.UpgradeButtonLive do
|
|||
|> String.downcase()
|
||||
|
||||
if normalized_text == "got it!" do
|
||||
Settings.set!(:pro_enabled, true)
|
||||
SettingsBackup.set!(:pro_enabled, true)
|
||||
|
||||
{:noreply, update(socket, :button_disabled, fn _ -> false end)}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@
|
|||
<body
|
||||
x-data={"{
|
||||
sidebarVisible: false,
|
||||
proEnabled: #{Settings.get!(:pro_enabled)},
|
||||
onboarding: #{Settings.get!(:onboarding)}
|
||||
proEnabled: #{SettingsBackup.get!(:pro_enabled)},
|
||||
onboarding: #{SettingsBackup.get!(:onboarding)}
|
||||
}"}
|
||||
class="dark text-bodydark bg-boxdark-2"
|
||||
>
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ defmodule PinchflatWeb.MediaProfiles.MediaProfileController do
|
|||
case Profiles.create_media_profile(media_profile_params) do
|
||||
{:ok, media_profile} ->
|
||||
redirect_location =
|
||||
if Settings.get!(:onboarding), do: ~p"/?onboarding=1", else: ~p"/media_profiles/#{media_profile}"
|
||||
if SettingsBackup.get!(:onboarding), do: ~p"/?onboarding=1", else: ~p"/media_profiles/#{media_profile}"
|
||||
|
||||
conn
|
||||
|> put_flash(:info, "Media profile created successfully.")
|
||||
|
|
@ -89,7 +89,7 @@ defmodule PinchflatWeb.MediaProfiles.MediaProfileController do
|
|||
end
|
||||
|
||||
defp get_onboarding_layout do
|
||||
if Settings.get!(:onboarding) do
|
||||
if SettingsBackup.get!(:onboarding) do
|
||||
{Layouts, :onboarding}
|
||||
else
|
||||
{Layouts, :app}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<div class="mb-6 flex gap-3 flex-row items-center">
|
||||
<.link :if={!Settings.get!(:onboarding)} href={~p"/media_profiles"}>
|
||||
<.link :if={!SettingsBackup.get!(:onboarding)} href={~p"/media_profiles"}>
|
||||
<.icon name="hero-arrow-left" class="w-10 h-10 hover:dark:text-white" />
|
||||
</.link>
|
||||
<h2 class="text-title-md2 font-bold text-black dark:text-white ml-4">New Media Profile</h2>
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ defmodule PinchflatWeb.Pages.PageController do
|
|||
done_onboarding = params["onboarding"] == "0"
|
||||
force_onboarding = params["onboarding"] == "1"
|
||||
|
||||
if done_onboarding, do: Settings.set!(:onboarding, false)
|
||||
if done_onboarding, do: SettingsBackup.set!(:onboarding, false)
|
||||
|
||||
if force_onboarding || Settings.get!(:onboarding) do
|
||||
if force_onboarding || SettingsBackup.get!(:onboarding) do
|
||||
render_onboarding_page(conn)
|
||||
else
|
||||
render_home_page(conn)
|
||||
|
|
@ -30,7 +30,7 @@ defmodule PinchflatWeb.Pages.PageController do
|
|||
end
|
||||
|
||||
defp render_onboarding_page(conn) do
|
||||
Settings.set!(:onboarding, true)
|
||||
SettingsBackup.set!(:onboarding, true)
|
||||
|
||||
conn
|
||||
|> render(:onboarding_checklist,
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ defmodule PinchflatWeb.Sources.SourceController do
|
|||
case Sources.create_source(source_params) do
|
||||
{:ok, source} ->
|
||||
redirect_location =
|
||||
if Settings.get!(:onboarding), do: ~p"/?onboarding=1", else: ~p"/sources/#{source}"
|
||||
if SettingsBackup.get!(:onboarding), do: ~p"/?onboarding=1", else: ~p"/sources/#{source}"
|
||||
|
||||
conn
|
||||
|> put_flash(:info, "Source created successfully.")
|
||||
|
|
@ -159,7 +159,7 @@ defmodule PinchflatWeb.Sources.SourceController do
|
|||
end
|
||||
|
||||
defp get_onboarding_layout do
|
||||
if Settings.get!(:onboarding) do
|
||||
if SettingsBackup.get!(:onboarding) do
|
||||
{Layouts, :onboarding}
|
||||
else
|
||||
{Layouts, :app}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<div class="mb-6 flex gap-3 flex-row items-center">
|
||||
<.link :if={!Settings.get!(:onboarding)} href={~p"/sources"}>
|
||||
<.link :if={!SettingsBackup.get!(:onboarding)} href={~p"/sources"}>
|
||||
<.icon name="hero-arrow-left" class="w-10 h-10 hover:dark:text-white" />
|
||||
</.link>
|
||||
<h2 class="text-title-md2 font-bold text-black dark:text-white ml-4">New Source</h2>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
defmodule Pinchflat.Repo.Migrations.CreateSettings do
|
||||
defmodule Pinchflat.Repo.Migrations.CreateSettingsBackup do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
defmodule Pinchflat.Repo.Migrations.RenameSettingsBackupTable do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
rename table(:settings), to: table(:settings_backup)
|
||||
end
|
||||
end
|
||||
|
|
@ -1,25 +1,25 @@
|
|||
defmodule Pinchflat.Boot.PreJobStartupTasksTest do
|
||||
use Pinchflat.DataCase
|
||||
|
||||
alias Pinchflat.Settings
|
||||
alias Pinchflat.Settings.Setting
|
||||
alias Pinchflat.SettingsBackup
|
||||
alias Pinchflat.SettingsBackup.SettingBackup
|
||||
alias Pinchflat.Boot.PreJobStartupTasks
|
||||
|
||||
describe "apply_default_settings" do
|
||||
setup do
|
||||
Repo.delete_all(Setting)
|
||||
Repo.delete_all(SettingBackup)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
test "sets default settings" do
|
||||
assert_raise Ecto.NoResultsError, fn -> Settings.get!(:onboarding) end
|
||||
assert_raise Ecto.NoResultsError, fn -> Settings.get!(:pro_enabled) end
|
||||
assert_raise Ecto.NoResultsError, fn -> SettingsBackup.get!(:onboarding) end
|
||||
assert_raise Ecto.NoResultsError, fn -> SettingsBackup.get!(:pro_enabled) end
|
||||
|
||||
PreJobStartupTasks.start_link()
|
||||
|
||||
assert Settings.get!(:onboarding)
|
||||
refute Settings.get!(:pro_enabled)
|
||||
assert SettingsBackup.get!(:onboarding)
|
||||
refute SettingsBackup.get!(:pro_enabled)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
defmodule Pinchflat.SettingsTest do
|
||||
defmodule Pinchflat.SettingsBackupTest do
|
||||
use Pinchflat.DataCase
|
||||
|
||||
alias Pinchflat.Settings
|
||||
alias Pinchflat.Settings.Setting
|
||||
alias Pinchflat.SettingsBackup
|
||||
alias Pinchflat.SettingsBackup.SettingBackup
|
||||
|
||||
# NOTE: We're treating some of these tests differently
|
||||
# than in other modules because certain settings
|
||||
|
|
@ -11,98 +11,98 @@ defmodule Pinchflat.SettingsTest do
|
|||
|
||||
describe "list_settings/0" do
|
||||
test "returns all settings" do
|
||||
Settings.set!("foo", "bar")
|
||||
results = Settings.list_settings()
|
||||
SettingsBackup.set!("foo", "bar")
|
||||
results = SettingsBackup.list_settings()
|
||||
|
||||
assert Enum.all?(results, fn setting -> match?(%Setting{}, setting) end)
|
||||
assert Enum.all?(results, fn setting -> match?(%SettingBackup{}, setting) end)
|
||||
end
|
||||
end
|
||||
|
||||
describe "set/2" do
|
||||
test "creates a new setting if one does not exist" do
|
||||
original = Repo.aggregate(Setting, :count, :id)
|
||||
Settings.set!("foo", "bar")
|
||||
assert Repo.aggregate(Setting, :count, :id) == original + 1
|
||||
original = Repo.aggregate(SettingBackup, :count, :id)
|
||||
SettingsBackup.set!("foo", "bar")
|
||||
assert Repo.aggregate(SettingBackup, :count, :id) == original + 1
|
||||
end
|
||||
|
||||
test "updates an existing setting if one exists" do
|
||||
Settings.set!("foo", "bar")
|
||||
original = Repo.aggregate(Setting, :count, :id)
|
||||
Settings.set!("foo", "baz")
|
||||
assert Repo.aggregate(Setting, :count, :id) == original
|
||||
assert Settings.get!("foo") == "baz"
|
||||
SettingsBackup.set!("foo", "bar")
|
||||
original = Repo.aggregate(SettingBackup, :count, :id)
|
||||
SettingsBackup.set!("foo", "baz")
|
||||
assert Repo.aggregate(SettingBackup, :count, :id) == original
|
||||
assert SettingsBackup.get!("foo") == "baz"
|
||||
end
|
||||
|
||||
test "returns the parsed value" do
|
||||
assert Settings.set!("foo", true) == true
|
||||
assert Settings.set!("foo", false) == false
|
||||
assert Settings.set!("foo", 123) == 123
|
||||
assert Settings.set!("foo", 12.34) == 12.34
|
||||
assert Settings.set!("foo", "bar") == "bar"
|
||||
assert SettingsBackup.set!("foo", true) == true
|
||||
assert SettingsBackup.set!("foo", false) == false
|
||||
assert SettingsBackup.set!("foo", 123) == 123
|
||||
assert SettingsBackup.set!("foo", 12.34) == 12.34
|
||||
assert SettingsBackup.set!("foo", "bar") == "bar"
|
||||
end
|
||||
|
||||
test "allows for atom keys" do
|
||||
assert Settings.set!(:foo, "bar") == "bar"
|
||||
assert SettingsBackup.set!(:foo, "bar") == "bar"
|
||||
end
|
||||
|
||||
test "blows up when an unsupported datatype is used" do
|
||||
assert_raise FunctionClauseError, fn ->
|
||||
Settings.set!("foo", nil)
|
||||
SettingsBackup.set!("foo", nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "set/3" do
|
||||
test "allows manual specification of datatype" do
|
||||
assert Settings.set!("foo", "true", :boolean) == true
|
||||
assert Settings.set!("foo", "false", :boolean) == false
|
||||
assert Settings.set!("foo", "123", :integer) == 123
|
||||
assert Settings.set!("foo", "12.34", :float) == 12.34
|
||||
assert SettingsBackup.set!("foo", "true", :boolean) == true
|
||||
assert SettingsBackup.set!("foo", "false", :boolean) == false
|
||||
assert SettingsBackup.set!("foo", "123", :integer) == 123
|
||||
assert SettingsBackup.set!("foo", "12.34", :float) == 12.34
|
||||
end
|
||||
end
|
||||
|
||||
describe "get/1" do
|
||||
test "returns the value of the setting" do
|
||||
Settings.set!("str", "bar")
|
||||
Settings.set!("bool", true)
|
||||
Settings.set!("int", 123)
|
||||
Settings.set!("float", 12.34)
|
||||
SettingsBackup.set!("str", "bar")
|
||||
SettingsBackup.set!("bool", true)
|
||||
SettingsBackup.set!("int", 123)
|
||||
SettingsBackup.set!("float", 12.34)
|
||||
|
||||
assert Settings.get!("str") == "bar"
|
||||
assert Settings.get!("bool") == true
|
||||
assert Settings.get!("int") == 123
|
||||
assert Settings.get!("float") == 12.34
|
||||
assert SettingsBackup.get!("str") == "bar"
|
||||
assert SettingsBackup.get!("bool") == true
|
||||
assert SettingsBackup.get!("int") == 123
|
||||
assert SettingsBackup.get!("float") == 12.34
|
||||
end
|
||||
|
||||
test "allows for atom keys" do
|
||||
Settings.set!("str", "bar")
|
||||
assert Settings.get!(:str) == "bar"
|
||||
SettingsBackup.set!("str", "bar")
|
||||
assert SettingsBackup.get!(:str) == "bar"
|
||||
end
|
||||
|
||||
test "blows up when the setting does not exist" do
|
||||
assert_raise Ecto.NoResultsError, fn ->
|
||||
Settings.get!("foo")
|
||||
SettingsBackup.get!("foo")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "fetch/2" do
|
||||
test "creates a setting if one doesn't exist" do
|
||||
original = Repo.aggregate(Setting, :count, :id)
|
||||
assert Settings.fetch!("foo", "bar") == "bar"
|
||||
assert Repo.aggregate(Setting, :count, :id) == original + 1
|
||||
original = Repo.aggregate(SettingBackup, :count, :id)
|
||||
assert SettingsBackup.fetch!("foo", "bar") == "bar"
|
||||
assert Repo.aggregate(SettingBackup, :count, :id) == original + 1
|
||||
end
|
||||
|
||||
test "returns an existing setting if one does exist" do
|
||||
Settings.set!("foo", "bar")
|
||||
SettingsBackup.set!("foo", "bar")
|
||||
|
||||
assert Settings.fetch!("foo", "baz") == "bar"
|
||||
assert SettingsBackup.fetch!("foo", "baz") == "bar"
|
||||
end
|
||||
end
|
||||
|
||||
describe "fetch/3" do
|
||||
test "allows manual specification of datatype" do
|
||||
assert Settings.fetch!("foo", "true", :boolean) == true
|
||||
assert SettingsBackup.fetch!("foo", "true", :boolean) == true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ defmodule PinchflatWeb.MediaProfileControllerTest do
|
|||
import Pinchflat.ProfilesFixtures
|
||||
|
||||
alias Pinchflat.Repo
|
||||
alias Pinchflat.Settings
|
||||
alias Pinchflat.SettingsBackup
|
||||
|
||||
@create_attrs %{name: "some name", output_path_template: "output_template.{{ ext }}"}
|
||||
@update_attrs %{
|
||||
|
|
@ -16,7 +16,7 @@ defmodule PinchflatWeb.MediaProfileControllerTest do
|
|||
@invalid_attrs %{name: nil, output_path_template: nil}
|
||||
|
||||
setup do
|
||||
Settings.set!(:onboarding, false)
|
||||
SettingsBackup.set!(:onboarding, false)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
|
@ -35,7 +35,7 @@ defmodule PinchflatWeb.MediaProfileControllerTest do
|
|||
end
|
||||
|
||||
test "renders correct layout when onboarding", %{conn: conn} do
|
||||
Settings.set!(:onboarding, true)
|
||||
SettingsBackup.set!(:onboarding, true)
|
||||
conn = get(conn, ~p"/media_profiles/new")
|
||||
|
||||
refute html_response(conn, 200) =~ "MENU"
|
||||
|
|
@ -59,14 +59,14 @@ defmodule PinchflatWeb.MediaProfileControllerTest do
|
|||
end
|
||||
|
||||
test "redirects to onboarding when onboarding", %{conn: conn} do
|
||||
Settings.set!(:onboarding, true)
|
||||
SettingsBackup.set!(:onboarding, true)
|
||||
conn = post(conn, ~p"/media_profiles", media_profile: @create_attrs)
|
||||
|
||||
assert redirected_to(conn) == ~p"/?onboarding=1"
|
||||
end
|
||||
|
||||
test "renders correct layout on error when onboarding", %{conn: conn} do
|
||||
Settings.set!(:onboarding, true)
|
||||
SettingsBackup.set!(:onboarding, true)
|
||||
conn = post(conn, ~p"/media_profiles", media_profile: @invalid_attrs)
|
||||
|
||||
refute html_response(conn, 200) =~ "MENU"
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
defmodule PinchflatWeb.PageControllerTest do
|
||||
use PinchflatWeb.ConnCase
|
||||
|
||||
alias Pinchflat.Settings
|
||||
alias Pinchflat.SettingsBackup
|
||||
|
||||
describe "GET / when testing onboarding" do
|
||||
test "sets the onboarding setting to true when onboarding", %{conn: conn} do
|
||||
_conn = get(conn, ~p"/")
|
||||
assert Settings.get!(:onboarding)
|
||||
assert SettingsBackup.get!(:onboarding)
|
||||
end
|
||||
|
||||
test "displays the onboarding page when onboarding is forced", %{conn: conn} do
|
||||
Settings.set!(:onboarding, false)
|
||||
SettingsBackup.set!(:onboarding, false)
|
||||
|
||||
conn = get(conn, ~p"/?onboarding=1")
|
||||
assert html_response(conn, 200) =~ "Welcome to Pinchflat"
|
||||
|
|
@ -18,14 +18,14 @@ defmodule PinchflatWeb.PageControllerTest do
|
|||
|
||||
test "sets the onboarding setting to false if you pass the corrent query param", %{conn: conn} do
|
||||
conn = get(conn, ~p"/")
|
||||
assert Settings.get!(:onboarding)
|
||||
assert SettingsBackup.get!(:onboarding)
|
||||
|
||||
_conn = get(conn, ~p"/?onboarding=0")
|
||||
refute Settings.get!(:onboarding)
|
||||
refute SettingsBackup.get!(:onboarding)
|
||||
end
|
||||
|
||||
test "displays the home page when not onboarding", %{conn: conn} do
|
||||
Settings.set!(:onboarding, false)
|
||||
SettingsBackup.set!(:onboarding, false)
|
||||
|
||||
conn = get(conn, ~p"/")
|
||||
assert html_response(conn, 200) =~ "MENU"
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ defmodule PinchflatWeb.SourceControllerTest do
|
|||
import Pinchflat.ProfilesFixtures
|
||||
|
||||
alias Pinchflat.Repo
|
||||
alias Pinchflat.Settings
|
||||
alias Pinchflat.SettingsBackup
|
||||
alias Pinchflat.Downloading.MediaDownloadWorker
|
||||
alias Pinchflat.SlowIndexing.MediaCollectionIndexingWorker
|
||||
|
||||
setup do
|
||||
media_profile = media_profile_fixture()
|
||||
Settings.set!(:onboarding, false)
|
||||
SettingsBackup.set!(:onboarding, false)
|
||||
|
||||
{
|
||||
:ok,
|
||||
|
|
@ -47,7 +47,7 @@ defmodule PinchflatWeb.SourceControllerTest do
|
|||
end
|
||||
|
||||
test "renders correct layout when onboarding", %{conn: conn} do
|
||||
Settings.set!(:onboarding, true)
|
||||
SettingsBackup.set!(:onboarding, true)
|
||||
conn = get(conn, ~p"/sources/new")
|
||||
|
||||
refute html_response(conn, 200) =~ "MENU"
|
||||
|
|
@ -74,14 +74,14 @@ defmodule PinchflatWeb.SourceControllerTest do
|
|||
test "redirects to onboarding when onboarding", %{conn: conn, create_attrs: create_attrs} do
|
||||
expect(YtDlpRunnerMock, :run, 1, &runner_function_mock/3)
|
||||
|
||||
Settings.set!(:onboarding, true)
|
||||
SettingsBackup.set!(:onboarding, true)
|
||||
conn = post(conn, ~p"/sources", source: create_attrs)
|
||||
|
||||
assert redirected_to(conn) == ~p"/?onboarding=1"
|
||||
end
|
||||
|
||||
test "renders correct layout on error when onboarding", %{conn: conn, invalid_attrs: invalid_attrs} do
|
||||
Settings.set!(:onboarding, true)
|
||||
SettingsBackup.set!(:onboarding, true)
|
||||
conn = post(conn, ~p"/sources", source: invalid_attrs)
|
||||
|
||||
refute html_response(conn, 200) =~ "MENU"
|
||||
|
|
|
|||
Loading…
Reference in a new issue