2022-07-25 20:12:11 -04:00
|
|
|
defmodule Memex.PipelinesTest do
|
|
|
|
use Memex.DataCase
|
2022-11-24 14:31:16 -05:00
|
|
|
import Memex.PipelinesFixtures
|
|
|
|
alias Memex.{Pipelines, Pipelines.Pipeline}
|
|
|
|
@moduletag :pipelines_test
|
|
|
|
@invalid_attrs %{description: nil, tag: nil, title: nil, visibility: nil}
|
2022-07-25 20:12:11 -04:00
|
|
|
|
|
|
|
describe "pipelines" do
|
2022-11-24 14:31:16 -05:00
|
|
|
setup do
|
|
|
|
[user: user_fixture()]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "list_pipelines/1 returns all pipelines for a user", %{user: user} do
|
|
|
|
pipeline_a = pipeline_fixture(%{title: "a", visibility: :public}, user)
|
|
|
|
pipeline_b = pipeline_fixture(%{title: "b", visibility: :unlisted}, user)
|
|
|
|
pipeline_c = pipeline_fixture(%{title: "c", visibility: :private}, user)
|
|
|
|
assert Pipelines.list_pipelines(user) == [pipeline_a, pipeline_b, pipeline_c]
|
|
|
|
end
|
2022-07-25 20:12:11 -04:00
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
test "list_public_pipelines/0 returns public pipelines", %{user: user} do
|
|
|
|
public_pipeline = pipeline_fixture(%{visibility: :public}, user)
|
|
|
|
pipeline_fixture(%{visibility: :unlisted}, user)
|
|
|
|
pipeline_fixture(%{visibility: :private}, user)
|
|
|
|
assert Pipelines.list_public_pipelines() == [public_pipeline]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "get_pipeline!/1 returns the pipeline with given id", %{user: user} do
|
|
|
|
pipeline = pipeline_fixture(%{visibility: :public}, user)
|
|
|
|
assert Pipelines.get_pipeline!(pipeline.id, user) == pipeline
|
2022-07-25 20:12:11 -04:00
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
pipeline = pipeline_fixture(%{visibility: :unlisted}, user)
|
|
|
|
assert Pipelines.get_pipeline!(pipeline.id, user) == pipeline
|
2022-07-25 20:12:11 -04:00
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
pipeline = pipeline_fixture(%{visibility: :private}, user)
|
|
|
|
assert Pipelines.get_pipeline!(pipeline.id, user) == pipeline
|
2022-07-25 20:12:11 -04:00
|
|
|
end
|
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
test "get_pipeline!/1 only returns unlisted or public pipelines for other users", %{
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
another_user = user_fixture()
|
|
|
|
pipeline = pipeline_fixture(%{visibility: :public}, another_user)
|
|
|
|
assert Pipelines.get_pipeline!(pipeline.id, user) == pipeline
|
|
|
|
|
|
|
|
pipeline = pipeline_fixture(%{visibility: :unlisted}, another_user)
|
|
|
|
assert Pipelines.get_pipeline!(pipeline.id, user) == pipeline
|
|
|
|
|
|
|
|
pipeline = pipeline_fixture(%{visibility: :private}, another_user)
|
|
|
|
|
|
|
|
assert_raise Ecto.NoResultsError, fn ->
|
|
|
|
Pipelines.get_pipeline!(pipeline.id, user)
|
|
|
|
end
|
2022-07-25 20:12:11 -04:00
|
|
|
end
|
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
test "create_pipeline/1 with valid data creates a pipeline", %{user: user} do
|
|
|
|
valid_attrs = %{
|
|
|
|
"description" => "some description",
|
|
|
|
"tags_string" => "tag1,tag2",
|
|
|
|
"title" => "some title",
|
|
|
|
"visibility" => :public
|
|
|
|
}
|
2022-07-25 20:12:11 -04:00
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
assert {:ok, %Pipeline{} = pipeline} = Pipelines.create_pipeline(valid_attrs, user)
|
2022-07-25 20:12:11 -04:00
|
|
|
assert pipeline.description == "some description"
|
2022-11-24 14:31:16 -05:00
|
|
|
assert pipeline.tags == ["tag1", "tag2"]
|
2022-07-25 20:12:11 -04:00
|
|
|
assert pipeline.title == "some title"
|
|
|
|
assert pipeline.visibility == :public
|
|
|
|
end
|
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
test "create_pipeline/1 with invalid data returns error changeset", %{user: user} do
|
|
|
|
assert {:error, %Ecto.Changeset{}} = Pipelines.create_pipeline(@invalid_attrs, user)
|
2022-07-25 20:12:11 -04:00
|
|
|
end
|
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
test "update_pipeline/2 with valid data updates the pipeline", %{user: user} do
|
|
|
|
pipeline = pipeline_fixture(user)
|
2022-07-25 22:05:54 -04:00
|
|
|
|
|
|
|
update_attrs = %{
|
2022-11-24 14:31:16 -05:00
|
|
|
"description" => "some updated description",
|
|
|
|
"tags_string" => "tag1,tag2",
|
|
|
|
"title" => "some updated title",
|
|
|
|
"visibility" => :private
|
2022-07-25 22:05:54 -04:00
|
|
|
}
|
2022-07-25 20:12:11 -04:00
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
assert {:ok, %Pipeline{} = pipeline} =
|
|
|
|
Pipelines.update_pipeline(pipeline, update_attrs, user)
|
|
|
|
|
2022-07-25 20:12:11 -04:00
|
|
|
assert pipeline.description == "some updated description"
|
2022-11-24 14:31:16 -05:00
|
|
|
assert pipeline.tags == ["tag1", "tag2"]
|
2022-07-25 20:12:11 -04:00
|
|
|
assert pipeline.title == "some updated title"
|
|
|
|
assert pipeline.visibility == :private
|
|
|
|
end
|
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
test "update_pipeline/2 with invalid data returns error changeset", %{user: user} do
|
|
|
|
pipeline = pipeline_fixture(user)
|
|
|
|
|
|
|
|
assert {:error, %Ecto.Changeset{}} =
|
|
|
|
Pipelines.update_pipeline(pipeline, @invalid_attrs, user)
|
|
|
|
|
|
|
|
assert pipeline == Pipelines.get_pipeline!(pipeline.id, user)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "delete_pipeline/1 deletes the pipeline", %{user: user} do
|
|
|
|
pipeline = pipeline_fixture(user)
|
|
|
|
assert {:ok, %Pipeline{}} = Pipelines.delete_pipeline(pipeline, user)
|
|
|
|
assert_raise Ecto.NoResultsError, fn -> Pipelines.get_pipeline!(pipeline.id, user) end
|
2022-07-25 20:12:11 -04:00
|
|
|
end
|
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
test "delete_pipeline/1 deletes the pipeline for an admin user", %{user: user} do
|
|
|
|
admin_user = admin_fixture()
|
|
|
|
pipeline = pipeline_fixture(user)
|
|
|
|
assert {:ok, %Pipeline{}} = Pipelines.delete_pipeline(pipeline, admin_user)
|
|
|
|
assert_raise Ecto.NoResultsError, fn -> Pipelines.get_pipeline!(pipeline.id, user) end
|
2022-07-25 20:12:11 -04:00
|
|
|
end
|
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
test "change_pipeline/1 returns a pipeline changeset", %{user: user} do
|
|
|
|
pipeline = pipeline_fixture(user)
|
|
|
|
assert %Ecto.Changeset{} = Pipelines.change_pipeline(pipeline, user)
|
2022-07-25 20:12:11 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|