add steps
This commit is contained in:
63
test/memex/steps_test.exs
Normal file
63
test/memex/steps_test.exs
Normal file
@ -0,0 +1,63 @@
|
||||
defmodule Memex.StepsTest do
|
||||
use Memex.DataCase
|
||||
|
||||
alias Memex.Steps
|
||||
|
||||
describe "steps" do
|
||||
alias Memex.Steps.Step
|
||||
|
||||
import Memex.StepsFixtures
|
||||
|
||||
@invalid_attrs %{description: nil, position: nil, title: nil}
|
||||
|
||||
test "list_steps/0 returns all steps" do
|
||||
step = step_fixture()
|
||||
assert Steps.list_steps() == [step]
|
||||
end
|
||||
|
||||
test "get_step!/1 returns the step with given id" do
|
||||
step = step_fixture()
|
||||
assert Steps.get_step!(step.id) == step
|
||||
end
|
||||
|
||||
test "create_step/1 with valid data creates a step" do
|
||||
valid_attrs = %{description: "some description", position: 42, title: "some title"}
|
||||
|
||||
assert {:ok, %Step{} = step} = Steps.create_step(valid_attrs)
|
||||
assert step.description == "some description"
|
||||
assert step.position == 42
|
||||
assert step.title == "some title"
|
||||
end
|
||||
|
||||
test "create_step/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = Steps.create_step(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_step/2 with valid data updates the step" do
|
||||
step = step_fixture()
|
||||
update_attrs = %{description: "some updated description", position: 43, title: "some updated title"}
|
||||
|
||||
assert {:ok, %Step{} = step} = Steps.update_step(step, update_attrs)
|
||||
assert step.description == "some updated description"
|
||||
assert step.position == 43
|
||||
assert step.title == "some updated title"
|
||||
end
|
||||
|
||||
test "update_step/2 with invalid data returns error changeset" do
|
||||
step = step_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = Steps.update_step(step, @invalid_attrs)
|
||||
assert step == Steps.get_step!(step.id)
|
||||
end
|
||||
|
||||
test "delete_step/1 deletes the step" do
|
||||
step = step_fixture()
|
||||
assert {:ok, %Step{}} = Steps.delete_step(step)
|
||||
assert_raise Ecto.NoResultsError, fn -> Steps.get_step!(step.id) end
|
||||
end
|
||||
|
||||
test "change_step/1 returns a step changeset" do
|
||||
step = step_fixture()
|
||||
assert %Ecto.Changeset{} = Steps.change_step(step)
|
||||
end
|
||||
end
|
||||
end
|
22
test/support/fixtures/steps_fixtures.ex
Normal file
22
test/support/fixtures/steps_fixtures.ex
Normal file
@ -0,0 +1,22 @@
|
||||
defmodule Memex.StepsFixtures do
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `Memex.Steps` context.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Generate a step.
|
||||
"""
|
||||
def step_fixture(attrs \\ %{}) do
|
||||
{:ok, step} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
description: "some description",
|
||||
position: 42,
|
||||
title: "some title"
|
||||
})
|
||||
|> Memex.Steps.create_step()
|
||||
|
||||
step
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user