166 lines
6.3 KiB
Elixir
166 lines
6.3 KiB
Elixir
defmodule Bright.PlatformsTest do
|
|
use Bright.DataCase
|
|
|
|
alias Bright.Platforms
|
|
alias Bright.Platforms.Platform
|
|
|
|
describe "platforms" do
|
|
import Bright.PlatformsFixtures
|
|
|
|
@invalid_attrs %{name: 7, url: 7}
|
|
|
|
test "list_platforms/0 returns all platforms" do
|
|
platform = platform_fixture()
|
|
assert Platforms.list_platforms() |> length === 1
|
|
end
|
|
|
|
test "get_platform!/1 returns the platform with given id" do
|
|
platform = platform_fixture(%{name: "Chaturbate"})
|
|
assert Platforms.get_platform!(platform.id).name == platform.name
|
|
end
|
|
|
|
test "create_platform/1 with valid data creates a platform" do
|
|
valid_attrs = %{name: "some name", url: "some url", slug: "some_slug", nsfw: true}
|
|
|
|
assert {:ok, %Platform{} = platform} = Platforms.create_platform(valid_attrs)
|
|
assert platform.name == "some name"
|
|
assert platform.url == "some url"
|
|
end
|
|
|
|
test "create_platform/1 with invalid data returns error changeset" do
|
|
assert {:error, %Ecto.Changeset{}} = Platforms.create_platform(@invalid_attrs)
|
|
end
|
|
|
|
test "update_platform/2 with valid data updates the platform" do
|
|
platform = platform_fixture()
|
|
|
|
update_attrs = %{
|
|
name: "some updated name",
|
|
url: "https://example.com"
|
|
}
|
|
|
|
assert {:ok, %Platform{} = platform} = Platforms.update_platform(platform, update_attrs)
|
|
assert platform.name == "some updated name"
|
|
assert platform.url == "https://example.com"
|
|
end
|
|
|
|
test "update_platform/2 with invalid data returns error changeset" do
|
|
platform = platform_fixture()
|
|
assert {:error, %Ecto.Changeset{}} = platform |> Platforms.update_platform(@invalid_attrs)
|
|
end
|
|
|
|
test "delete_platform/1 deletes the platform" do
|
|
platform = platform_fixture()
|
|
assert {:ok, %Platform{}} = Platforms.delete_platform(platform)
|
|
assert_raise Ecto.NoResultsError, fn -> Platforms.get_platform!(platform.id) end
|
|
end
|
|
|
|
test "change_platform/1 returns a platform changeset" do
|
|
platform = platform_fixture()
|
|
assert %Ecto.Changeset{} = Platforms.change_platform(platform)
|
|
end
|
|
end
|
|
|
|
describe "match_platform?/2" do
|
|
test "compares a platform with another and returns true if the two are the same platform" do
|
|
platformA = %Platform{name: "Twitch", url: "https://twitch.tv"}
|
|
platformB = %Platform{name: "Chaturbate", url: "https://chaturbate.com"}
|
|
platformC = %Platform{name: "Twitch", url: "https://twitch.tv"}
|
|
assert Platforms.match_platform?(platformA, platformC)
|
|
assert not Platforms.match_platform?(platformA, platformB)
|
|
end
|
|
end
|
|
|
|
describe "contains_platform?/2" do
|
|
@tag :unit
|
|
test "accepts a list of platforms and returns true if one of them match any of a list of given platform" do
|
|
platformA = %Platform{name: "Twitch", url: "https://twitch.tv"}
|
|
platformB = %Platform{name: "Chaturbate", url: "https://chaturbate.com"}
|
|
platformC = %Platform{name: "Twitch", url: "https://twitch.tv"}
|
|
assert Platforms.contains_platform?([platformA], [platformB, platformC])
|
|
assert not Platforms.contains_platform?([platformA], [platformB])
|
|
end
|
|
|
|
@tag :unit
|
|
test "returns true if configured to return true for SFW platforms" do
|
|
platformA = %Platform{name: "Twitch", url: "https://twitch.tv"}
|
|
platformB = %Platform{name: "YouTube", url: "https://youtube.com"}
|
|
assert Platforms.contains_platform?([platformA], [platformB, platformA])
|
|
end
|
|
|
|
@tag :unit
|
|
test "returns false if matching against an empty list" do
|
|
platformA = %Platform{name: "Twitch", url: "https://twitch.tv"}
|
|
assert not Platforms.contains_platform?([platformA], [])
|
|
assert not Platforms.contains_platform?([], [platformA])
|
|
end
|
|
end
|
|
|
|
describe "platform_aliases" do
|
|
alias Bright.Platforms.PlatformAlias
|
|
|
|
import Bright.PlatformsFixtures
|
|
|
|
@invalid_attrs %{url: nil}
|
|
|
|
test "list_platform_aliases/0 returns all platform_aliases" do
|
|
platform = platform_fixture()
|
|
platform_alias = platform_alias_fixture(%{platform_id: platform.id}).preload([:platform])
|
|
assert Platforms.list_platform_aliases() == [platform_alias]
|
|
end
|
|
|
|
test "get_platform_alias!/1 returns the platform_alias with given id" do
|
|
platform = platform_fixture()
|
|
platform_alias = platform_alias_fixture(%{platform_id: platform.id})
|
|
assert Platforms.get_platform_alias!(platform_alias.id) == platform_alias
|
|
end
|
|
|
|
test "create_platform_alias/1 with valid data creates a platform_alias" do
|
|
platform = platform_fixture()
|
|
valid_attrs = %{url: "some url", platform_id: platform.id}
|
|
|
|
assert {:ok, %PlatformAlias{} = platform_alias} =
|
|
Platforms.create_platform_alias(valid_attrs)
|
|
|
|
assert platform_alias.url == "some url"
|
|
end
|
|
|
|
test "create_platform_alias/1 with invalid data returns error changeset" do
|
|
assert {:error, %Ecto.Changeset{}} = Platforms.create_platform_alias(@invalid_attrs)
|
|
end
|
|
|
|
test "update_platform_alias/2 with valid data updates the platform_alias" do
|
|
platform = platform_fixture()
|
|
platform_alias = platform_alias_fixture(%{platform_id: platform.id})
|
|
update_attrs = %{url: "some updated url"}
|
|
|
|
assert {:ok, %PlatformAlias{} = platform_alias} =
|
|
Platforms.update_platform_alias(platform_alias, update_attrs)
|
|
|
|
assert platform_alias.url == "some updated url"
|
|
end
|
|
|
|
test "update_platform_alias/2 with invalid data returns error changeset" do
|
|
platform = platform_fixture()
|
|
platform_alias = platform_alias_fixture(%{platform_id: platform.id})
|
|
|
|
assert {:error, %Ecto.Changeset{}} =
|
|
Platforms.update_platform_alias(platform_alias, @invalid_attrs)
|
|
|
|
assert platform_alias == Platforms.get_platform_alias!(platform_alias.id)
|
|
end
|
|
|
|
test "delete_platform_alias/1 deletes the platform_alias" do
|
|
platform_alias = platform_alias_fixture()
|
|
assert {:ok, %PlatformAlias{}} = Platforms.delete_platform_alias(platform_alias)
|
|
assert_raise Ecto.NoResultsError, fn -> Platforms.get_platform_alias!(platform_alias.id) end
|
|
end
|
|
|
|
test "change_platform_alias/1 returns a platform_alias changeset" do
|
|
platform = platform_fixture()
|
|
platform_alias = platform_alias_fixture(%{platform_id: platform.id})
|
|
assert %Ecto.Changeset{} = Platforms.change_platform_alias(platform_alias)
|
|
end
|
|
end
|
|
end
|