add pipelines

This commit is contained in:
2022-07-25 20:12:11 -04:00
parent 3347b26256
commit 0fca0ead12
13 changed files with 569 additions and 0 deletions

View File

@ -0,0 +1,63 @@
defmodule Memex.PipelinesTest do
use Memex.DataCase
alias Memex.Pipelines
describe "pipelines" do
alias Memex.Pipelines.Pipeline
import Memex.PipelinesFixtures
@invalid_attrs %{description: nil, title: nil, visibility: nil}
test "list_pipelines/0 returns all pipelines" do
pipeline = pipeline_fixture()
assert Pipelines.list_pipelines() == [pipeline]
end
test "get_pipeline!/1 returns the pipeline with given id" do
pipeline = pipeline_fixture()
assert Pipelines.get_pipeline!(pipeline.id) == pipeline
end
test "create_pipeline/1 with valid data creates a pipeline" do
valid_attrs = %{description: "some description", title: "some title", visibility: :public}
assert {:ok, %Pipeline{} = pipeline} = Pipelines.create_pipeline(valid_attrs)
assert pipeline.description == "some description"
assert pipeline.title == "some title"
assert pipeline.visibility == :public
end
test "create_pipeline/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Pipelines.create_pipeline(@invalid_attrs)
end
test "update_pipeline/2 with valid data updates the pipeline" do
pipeline = pipeline_fixture()
update_attrs = %{description: "some updated description", title: "some updated title", visibility: :private}
assert {:ok, %Pipeline{} = pipeline} = Pipelines.update_pipeline(pipeline, update_attrs)
assert pipeline.description == "some updated description"
assert pipeline.title == "some updated title"
assert pipeline.visibility == :private
end
test "update_pipeline/2 with invalid data returns error changeset" do
pipeline = pipeline_fixture()
assert {:error, %Ecto.Changeset{}} = Pipelines.update_pipeline(pipeline, @invalid_attrs)
assert pipeline == Pipelines.get_pipeline!(pipeline.id)
end
test "delete_pipeline/1 deletes the pipeline" do
pipeline = pipeline_fixture()
assert {:ok, %Pipeline{}} = Pipelines.delete_pipeline(pipeline)
assert_raise Ecto.NoResultsError, fn -> Pipelines.get_pipeline!(pipeline.id) end
end
test "change_pipeline/1 returns a pipeline changeset" do
pipeline = pipeline_fixture()
assert %Ecto.Changeset{} = Pipelines.change_pipeline(pipeline)
end
end
end

View File

@ -0,0 +1,110 @@
defmodule MemexWeb.PipelineLiveTest do
use MemexWeb.ConnCase
import Phoenix.LiveViewTest
import Memex.PipelinesFixtures
@create_attrs %{description: "some description", title: "some title", visibility: :public}
@update_attrs %{description: "some updated description", title: "some updated title", visibility: :private}
@invalid_attrs %{description: nil, title: nil, visibility: nil}
defp create_pipeline(_) do
pipeline = pipeline_fixture()
%{pipeline: pipeline}
end
describe "Index" do
setup [:create_pipeline]
test "lists all pipelines", %{conn: conn, pipeline: pipeline} do
{:ok, _index_live, html} = live(conn, Routes.pipeline_index_path(conn, :index))
assert html =~ "Listing Pipelines"
assert html =~ pipeline.description
end
test "saves new pipeline", %{conn: conn} do
{:ok, index_live, _html} = live(conn, Routes.pipeline_index_path(conn, :index))
assert index_live |> element("a", "New Pipeline") |> render_click() =~
"New Pipeline"
assert_patch(index_live, Routes.pipeline_index_path(conn, :new))
assert index_live
|> form("#pipeline-form", pipeline: @invalid_attrs)
|> render_change() =~ "can't be blank"
{:ok, _, html} =
index_live
|> form("#pipeline-form", pipeline: @create_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.pipeline_index_path(conn, :index))
assert html =~ "Pipeline created successfully"
assert html =~ "some description"
end
test "updates pipeline in listing", %{conn: conn, pipeline: pipeline} do
{:ok, index_live, _html} = live(conn, Routes.pipeline_index_path(conn, :index))
assert index_live |> element("#pipeline-#{pipeline.id} a", "Edit") |> render_click() =~
"Edit Pipeline"
assert_patch(index_live, Routes.pipeline_index_path(conn, :edit, pipeline))
assert index_live
|> form("#pipeline-form", pipeline: @invalid_attrs)
|> render_change() =~ "can't be blank"
{:ok, _, html} =
index_live
|> form("#pipeline-form", pipeline: @update_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.pipeline_index_path(conn, :index))
assert html =~ "Pipeline updated successfully"
assert html =~ "some updated description"
end
test "deletes pipeline in listing", %{conn: conn, pipeline: pipeline} do
{:ok, index_live, _html} = live(conn, Routes.pipeline_index_path(conn, :index))
assert index_live |> element("#pipeline-#{pipeline.id} a", "Delete") |> render_click()
refute has_element?(index_live, "#pipeline-#{pipeline.id}")
end
end
describe "Show" do
setup [:create_pipeline]
test "displays pipeline", %{conn: conn, pipeline: pipeline} do
{:ok, _show_live, html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline))
assert html =~ "Show Pipeline"
assert html =~ pipeline.description
end
test "updates pipeline within modal", %{conn: conn, pipeline: pipeline} do
{:ok, show_live, _html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline))
assert show_live |> element("a", "Edit") |> render_click() =~
"Edit Pipeline"
assert_patch(show_live, Routes.pipeline_show_path(conn, :edit, pipeline))
assert show_live
|> form("#pipeline-form", pipeline: @invalid_attrs)
|> render_change() =~ "can't be blank"
{:ok, _, html} =
show_live
|> form("#pipeline-form", pipeline: @update_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.pipeline_show_path(conn, :show, pipeline))
assert html =~ "Pipeline updated successfully"
assert html =~ "some updated description"
end
end
end

View File

@ -0,0 +1,22 @@
defmodule Memex.PipelinesFixtures do
@moduledoc """
This module defines test helpers for creating
entities via the `Memex.Pipelines` context.
"""
@doc """
Generate a pipeline.
"""
def pipeline_fixture(attrs \\ %{}) do
{:ok, pipeline} =
attrs
|> Enum.into(%{
description: "some description",
title: "some title",
visibility: :public
})
|> Memex.Pipelines.create_pipeline()
pipeline
end
end