Add some tests
This commit is contained in:
parent
a1444b69db
commit
e9c14e1450
4 changed files with 41 additions and 6 deletions
|
|
@ -25,7 +25,6 @@ defmodule Pinchflat.Settings do
|
||||||
|
|
||||||
Returns {:ok, %Setting{}} | {:error, %Ecto.Changeset{}}
|
Returns {:ok, %Setting{}} | {:error, %Ecto.Changeset{}}
|
||||||
"""
|
"""
|
||||||
# TODO: test
|
|
||||||
def update_setting(%Setting{} = setting, attrs) do
|
def update_setting(%Setting{} = setting, attrs) do
|
||||||
setting
|
setting
|
||||||
|> Setting.changeset(attrs)
|
|> Setting.changeset(attrs)
|
||||||
|
|
@ -76,7 +75,6 @@ defmodule Pinchflat.Settings do
|
||||||
@doc """
|
@doc """
|
||||||
Returns `%Ecto.Changeset{}`
|
Returns `%Ecto.Changeset{}`
|
||||||
"""
|
"""
|
||||||
# TODO: test
|
|
||||||
def change_setting(%Setting{} = setting, attrs \\ %{}) do
|
def change_setting(%Setting{} = setting, attrs \\ %{}) do
|
||||||
Setting.changeset(setting, attrs)
|
Setting.changeset(setting, attrs)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,8 @@
|
||||||
defmodule PinchflatWeb.Settings.SettingController do
|
defmodule PinchflatWeb.Settings.SettingController do
|
||||||
use PinchflatWeb, :controller
|
use PinchflatWeb, :controller
|
||||||
|
|
||||||
# import Ecto.Query, warn: false
|
|
||||||
|
|
||||||
# alias Pinchflat.Repo
|
|
||||||
alias Pinchflat.Settings
|
alias Pinchflat.Settings
|
||||||
|
|
||||||
# TODO: test
|
|
||||||
def show(conn, _params) do
|
def show(conn, _params) do
|
||||||
setting = Settings.record()
|
setting = Settings.record()
|
||||||
changeset = Settings.change_setting(setting)
|
changeset = Settings.change_setting(setting)
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,16 @@ defmodule Pinchflat.SettingsTest do
|
||||||
end
|
end
|
||||||
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
|
describe "set/1" do
|
||||||
test "updates the setting" do
|
test "updates the setting" do
|
||||||
assert {:ok, true} = Settings.set(onboarding: true)
|
assert {:ok, true} = Settings.set(onboarding: true)
|
||||||
|
|
@ -60,4 +70,12 @@ defmodule Pinchflat.SettingsTest do
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
23
test/pinchflat_web/controllers/setting_controller_test.exs
Normal file
23
test/pinchflat_web/controllers/setting_controller_test.exs
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
defmodule PinchflatWeb.SettingControllerTest do
|
||||||
|
use PinchflatWeb.ConnCase
|
||||||
|
|
||||||
|
describe "show settings" do
|
||||||
|
test "renders the page", %{conn: conn} do
|
||||||
|
conn = get(conn, ~p"/settings")
|
||||||
|
|
||||||
|
assert html_response(conn, 200) =~ "Settings"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "update settings" do
|
||||||
|
test "saves and redirects when data is valid", %{conn: conn} do
|
||||||
|
update_attrs = %{apprise_server: "test://server"}
|
||||||
|
|
||||||
|
conn = put(conn, ~p"/settings", setting: update_attrs)
|
||||||
|
assert redirected_to(conn) == ~p"/settings"
|
||||||
|
|
||||||
|
conn = get(conn, ~p"/settings")
|
||||||
|
assert html_response(conn, 200) =~ update_attrs[:apprise_server]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue