2022-08-18 21:34:27 +08:00
|
|
|
defmodule Livebook.HubsTest do
|
2023-07-13 19:42:27 +08:00
|
|
|
use Livebook.TeamsIntegrationCase, async: true
|
2022-08-18 21:34:27 +08:00
|
|
|
|
|
|
|
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)
|
2023-05-27 02:40:45 +08:00
|
|
|
assert team in Hubs.get_hubs()
|
2022-08-18 21:34:27 +08:00
|
|
|
|
2023-08-09 03:03:01 +08:00
|
|
|
Hubs.delete_hub(team.id)
|
2023-05-27 02:40:45 +08:00
|
|
|
refute team in Hubs.get_hubs()
|
2022-08-18 21:34:27 +08:00
|
|
|
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)
|
2023-05-27 02:40:45 +08:00
|
|
|
metadata = Hubs.Provider.to_metadata(team)
|
2022-08-18 21:34:27 +08:00
|
|
|
|
2023-02-14 04:18:06 +08:00
|
|
|
assert metadata in Hubs.get_metadatas()
|
2022-08-18 21:34:27 +08:00
|
|
|
|
2023-08-09 03:03:01 +08:00
|
|
|
Hubs.delete_hub(team.id)
|
2023-02-14 04:18:06 +08:00
|
|
|
refute metadata in Hubs.get_metadatas()
|
2022-08-18 21:34:27 +08:00
|
|
|
end
|
|
|
|
|
2023-08-09 03:03:01 +08:00
|
|
|
test "fetch_hub!/1 returns one persisted team", %{user: user, node: node} do
|
2022-10-07 01:53:37 +08:00
|
|
|
assert_raise Livebook.Storage.NotFoundError,
|
2023-08-09 03:03:01 +08:00
|
|
|
~s/could not find entry in "hubs" with ID "nonexistent"/,
|
2022-08-18 21:34:27 +08:00
|
|
|
fn ->
|
2023-08-09 03:03:01 +08:00
|
|
|
Hubs.fetch_hub!("nonexistent")
|
2022-08-18 21:34:27 +08:00
|
|
|
end
|
|
|
|
|
2023-08-09 03:03:01 +08:00
|
|
|
team = create_team_hub(user, node)
|
2022-08-18 21:34:27 +08:00
|
|
|
|
2023-08-09 03:03:01 +08:00
|
|
|
assert Hubs.fetch_hub!(team.id) == team
|
2022-08-18 21:34:27 +08:00
|
|
|
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)
|
2022-08-18 21:34:27 +08:00
|
|
|
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)
|
2023-05-27 02:40:45 +08:00
|
|
|
Hubs.save_hub(team)
|
2022-08-18 21:34:27 +08:00
|
|
|
|
2023-08-09 03:03:01 +08:00
|
|
|
assert Hubs.fetch_hub!(team.id) == team
|
2022-08-18 21:34:27 +08:00
|
|
|
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)
|
2023-05-27 02:40:45 +08:00
|
|
|
Hubs.save_hub(%{team | hub_emoji: "🐈"})
|
2022-08-18 21:34:27 +08:00
|
|
|
|
2023-08-09 03:03:01 +08:00
|
|
|
assert Hubs.fetch_hub!(team.id).hub_emoji == "🐈"
|
2022-08-18 21:34:27 +08:00
|
|
|
end
|
|
|
|
end
|