Don't create online team hubs in off-hub tests (#2307)

This commit is contained in:
Jonatan Kłosko 2023-10-25 14:12:17 +02:00 committed by GitHub
parent e2eba37ea7
commit e1b9e931cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 33 deletions

View file

@ -104,13 +104,9 @@ defmodule Livebook.Hubs do
:ok
end
@spec unset_default_hub(String.t()) :: :ok
def unset_default_hub(id) do
with {:ok, _hub} <- fetch_hub(id) do
:ok = Storage.delete(:default_hub, "default_hub")
end
:ok
@spec unset_default_hub() :: :ok
def unset_default_hub() do
:ok = Storage.delete(:default_hub, "default_hub")
end
@spec get_default_hub() :: Provider.t()
@ -124,7 +120,7 @@ defmodule Livebook.Hubs do
end
defp maybe_unset_default_hub(hub_id) do
if get_default_hub().id == hub_id, do: unset_default_hub(hub_id), else: :ok
if get_default_hub().id == hub_id, do: unset_default_hub(), else: :ok
end
defp disconnect_hub(hub) do

View file

@ -433,7 +433,7 @@ defmodule LivebookWeb.Hub.Edit.TeamComponent do
end
def handle_event("remove_as_default", _, socket) do
Hubs.unset_default_hub(socket.assigns.hub.id)
Hubs.unset_default_hub()
{:noreply, push_navigate(socket, to: ~p"/hub/#{socket.assigns.hub.id}")}
end

View file

@ -749,7 +749,7 @@ defmodule Livebook.LiveMarkdown.ImportTest do
end
test "imports notebook hub id when exists" do
%{id: hub_id} = Livebook.Factory.insert_hub(:team)
%{id: hub_id} = Livebook.HubHelpers.offline_hub()
markdown = """
<!-- livebook:{"hub_id":"#{hub_id}"} -->
@ -1216,7 +1216,7 @@ defmodule Livebook.LiveMarkdown.ImportTest do
end
test "sets :teams_enabled to true when the teams hub exist regardless the stamp" do
%{id: hub_id} = Livebook.Factory.insert_hub(:team)
%{id: hub_id} = Livebook.HubHelpers.offline_hub()
markdown = """
<!-- livebook:{"hub_id":"#{hub_id}"} -->

View file

@ -1913,31 +1913,35 @@ defmodule Livebook.SessionTest do
describe "default hub for new notebooks" do
test "use the default hub as default for new notebooks" do
hub = Livebook.Factory.insert_hub(:team)
hub = Livebook.HubHelpers.offline_hub()
Livebook.Hubs.set_default_hub(hub.id)
notebook = Livebook.Session.default_notebook()
assert notebook.hub_id == hub.id
Livebook.Hubs.delete_hub(hub.id)
Livebook.Hubs.unset_default_hub()
end
test "fallback to personal-hub when there's no default" do
hub = Livebook.Factory.insert_hub(:team)
Livebook.Hubs.unset_default_hub(hub.id)
hub = Livebook.HubHelpers.offline_hub()
Livebook.Hubs.set_default_hub(hub.id)
Livebook.Hubs.unset_default_hub()
notebook = Livebook.Session.default_notebook()
assert notebook.hub_id == "personal-hub"
Livebook.Hubs.delete_hub(hub.id)
end
test "fallback to personal-hub when the default doesn't exist" do
hub = Livebook.Factory.insert_hub(:team)
hub = Livebook.Factory.build(:team)
Livebook.Hubs.save_hub(hub)
Livebook.Hubs.set_default_hub(hub.id)
Livebook.Hubs.delete_hub(hub.id)
notebook = Livebook.Session.default_notebook()
refute Livebook.Hubs.hub_exists?(hub.id)
assert notebook.hub_id == "personal-hub"
Livebook.Hubs.unset_default_hub()
end
end
end

View file

@ -205,20 +205,13 @@ defmodule LivebookWeb.HomeLiveTest do
end
describe "hubs" do
test "renders sidebar section", %{conn: conn} do
{:ok, view, _} = live(conn, ~p"/")
assert render(view) =~ "HUBS"
assert render(view) =~ "Add Organization"
end
test "renders sidebar persisted hubs", %{conn: conn} do
team = insert_hub(:team, id: "team-foo-bar-id")
test "renders persisted hubs in the sidebar", %{conn: conn} do
team = Livebook.HubHelpers.offline_hub()
{:ok, view, _} = live(conn, ~p"/")
assert render(view) =~ "HUBS"
assert render(view) =~ team.hub_name
Livebook.Hubs.delete_hub("team-foo-bar-id")
assert render(view) =~ "Add Organization"
end
end

View file

@ -89,12 +89,6 @@ defmodule Livebook.Factory do
factory_name |> build() |> struct!(attrs) |> Map.from_struct()
end
def insert_hub(factory_name, attrs \\ %{}) do
factory_name
|> build(attrs)
|> Livebook.Hubs.save_hub()
end
def insert_secret(attrs \\ %{}) do
secret = build(:secret, attrs)
hub = Livebook.Hubs.fetch_hub!(secret.hub_id)