livebook/test/livebook_teams/hubs_test.exs

57 lines
1.6 KiB
Elixir
Raw Normal View History

defmodule Livebook.HubsTest do
2023-07-13 19:42:27 +08:00
use Livebook.TeamsIntegrationCase, async: true
alias Livebook.Hubs
2023-07-13 19:29:36 +08:00
2023-08-09 03:03:01 +08:00
test "get_hubs/0 returns a list of persisted hubs", %{user: user, node: node} do
team = create_team_hub(user, node)
assert team in Hubs.get_hubs()
2023-08-09 03:03:01 +08:00
Hubs.delete_hub(team.id)
refute team in Hubs.get_hubs()
end
2023-08-09 03:03:01 +08:00
test "get_metadatas/0 returns a list of persisted hubs normalized", %{user: user, node: node} do
team = create_team_hub(user, node)
metadata = Hubs.Provider.to_metadata(team)
assert metadata in Hubs.get_metadatas()
2023-08-09 03:03:01 +08:00
Hubs.delete_hub(team.id)
refute metadata in Hubs.get_metadatas()
end
2023-08-09 03:03:01 +08:00
test "fetch_hub!/1 returns one persisted team", %{user: user, node: node} do
assert_raise Livebook.Storage.NotFoundError,
2023-08-09 03:03:01 +08:00
~s/could not find entry in "hubs" with ID "nonexistent"/,
fn ->
2023-08-09 03:03:01 +08:00
Hubs.fetch_hub!("nonexistent")
end
2023-08-09 03:03:01 +08:00
team = create_team_hub(user, node)
2023-08-09 03:03:01 +08:00
assert Hubs.fetch_hub!(team.id) == team
end
2023-08-09 03:03:01 +08:00
test "hub_exists?/1", %{user: user, node: node} do
team = build_team_hub(user, node)
refute Hubs.hub_exists?(team.id)
Hubs.save_hub(team)
assert Hubs.hub_exists?(team.id)
end
2023-08-09 03:03:01 +08:00
test "save_hub/1 persists hub", %{user: user, node: node} do
team = build_team_hub(user, node)
Hubs.save_hub(team)
2023-08-09 03:03:01 +08:00
assert Hubs.fetch_hub!(team.id) == team
end
2023-08-09 03:03:01 +08:00
test "save_hub/1 updates hub", %{user: user, node: node} do
team = create_team_hub(user, node)
Hubs.save_hub(%{team | hub_emoji: "🐈"})
2023-08-09 03:03:01 +08:00
assert Hubs.fetch_hub!(team.id).hub_emoji == "🐈"
end
end