use slugs
This commit is contained in:
@ -3,7 +3,7 @@ defmodule Memex.ContextsTest do
|
||||
import Memex.ContextsFixtures
|
||||
alias Memex.{Contexts, Contexts.Context}
|
||||
@moduletag :contexts_test
|
||||
@invalid_attrs %{content: nil, tag: nil, title: nil, visibility: nil}
|
||||
@invalid_attrs %{content: nil, tag: nil, slug: nil, visibility: nil}
|
||||
|
||||
describe "contexts" do
|
||||
setup do
|
||||
@ -11,9 +11,9 @@ defmodule Memex.ContextsTest do
|
||||
end
|
||||
|
||||
test "list_contexts/1 returns all contexts for a user", %{user: user} do
|
||||
context_a = context_fixture(%{title: "a", visibility: :public}, user)
|
||||
context_b = context_fixture(%{title: "b", visibility: :unlisted}, user)
|
||||
context_c = context_fixture(%{title: "c", visibility: :private}, user)
|
||||
context_a = context_fixture(%{slug: "a", visibility: :public}, user)
|
||||
context_b = context_fixture(%{slug: "b", visibility: :unlisted}, user)
|
||||
context_c = context_fixture(%{slug: "c", visibility: :private}, user)
|
||||
assert Contexts.list_contexts(user) == [context_a, context_b, context_c]
|
||||
end
|
||||
|
||||
@ -50,18 +50,43 @@ defmodule Memex.ContextsTest do
|
||||
end
|
||||
end
|
||||
|
||||
test "get_context_by_slug/1 returns the context with given id", %{user: user} do
|
||||
context = context_fixture(%{slug: "a", visibility: :public}, user)
|
||||
assert Contexts.get_context_by_slug("a", user) == context
|
||||
|
||||
context = context_fixture(%{slug: "b", visibility: :unlisted}, user)
|
||||
assert Contexts.get_context_by_slug("b", user) == context
|
||||
|
||||
context = context_fixture(%{slug: "c", visibility: :private}, user)
|
||||
assert Contexts.get_context_by_slug("c", user) == context
|
||||
end
|
||||
|
||||
test "get_context_by_slug/1 only returns unlisted or public contexts for other users", %{
|
||||
user: user
|
||||
} do
|
||||
another_user = user_fixture()
|
||||
context = context_fixture(%{slug: "a", visibility: :public}, another_user)
|
||||
assert Contexts.get_context_by_slug("a", user) == context
|
||||
|
||||
context = context_fixture(%{slug: "b", visibility: :unlisted}, another_user)
|
||||
assert Contexts.get_context_by_slug("b", user) == context
|
||||
|
||||
context_fixture(%{slug: "c", visibility: :private}, another_user)
|
||||
assert Contexts.get_context_by_slug("c", user) |> is_nil()
|
||||
end
|
||||
|
||||
test "create_context/1 with valid data creates a context", %{user: user} do
|
||||
valid_attrs = %{
|
||||
"content" => "some content",
|
||||
"tags_string" => "tag1,tag2",
|
||||
"title" => "some title",
|
||||
"slug" => "some-slug",
|
||||
"visibility" => :public
|
||||
}
|
||||
|
||||
assert {:ok, %Context{} = context} = Contexts.create_context(valid_attrs, user)
|
||||
assert context.content == "some content"
|
||||
assert context.tags == ["tag1", "tag2"]
|
||||
assert context.title == "some title"
|
||||
assert context.slug == "some-slug"
|
||||
assert context.visibility == :public
|
||||
end
|
||||
|
||||
@ -75,14 +100,14 @@ defmodule Memex.ContextsTest do
|
||||
update_attrs = %{
|
||||
"content" => "some updated content",
|
||||
"tags_string" => "tag1,tag2",
|
||||
"title" => "some updated title",
|
||||
"slug" => "some-updated-slug",
|
||||
"visibility" => :private
|
||||
}
|
||||
|
||||
assert {:ok, %Context{} = context} = Contexts.update_context(context, update_attrs, user)
|
||||
assert context.content == "some updated content"
|
||||
assert context.tags == ["tag1", "tag2"]
|
||||
assert context.title == "some updated title"
|
||||
assert context.slug == "some-updated-slug"
|
||||
assert context.visibility == :private
|
||||
end
|
||||
|
||||
|
@ -3,7 +3,7 @@ defmodule Memex.NotesTest do
|
||||
import Memex.NotesFixtures
|
||||
alias Memex.{Notes, Notes.Note}
|
||||
@moduletag :notes_test
|
||||
@invalid_attrs %{content: nil, tag: nil, title: nil, visibility: nil}
|
||||
@invalid_attrs %{content: nil, tag: nil, slug: nil, visibility: nil}
|
||||
|
||||
describe "notes" do
|
||||
setup do
|
||||
@ -11,9 +11,9 @@ defmodule Memex.NotesTest do
|
||||
end
|
||||
|
||||
test "list_notes/1 returns all notes for a user", %{user: user} do
|
||||
note_a = note_fixture(%{title: "a", visibility: :public}, user)
|
||||
note_b = note_fixture(%{title: "b", visibility: :unlisted}, user)
|
||||
note_c = note_fixture(%{title: "c", visibility: :private}, user)
|
||||
note_a = note_fixture(%{slug: "a", visibility: :public}, user)
|
||||
note_b = note_fixture(%{slug: "b", visibility: :unlisted}, user)
|
||||
note_c = note_fixture(%{slug: "c", visibility: :private}, user)
|
||||
assert Notes.list_notes(user) == [note_a, note_b, note_c]
|
||||
end
|
||||
|
||||
@ -50,18 +50,43 @@ defmodule Memex.NotesTest do
|
||||
end
|
||||
end
|
||||
|
||||
test "get_note_by_slug/1 returns the note with given id", %{user: user} do
|
||||
note = note_fixture(%{slug: "a", visibility: :public}, user)
|
||||
assert Notes.get_note_by_slug("a", user) == note
|
||||
|
||||
note = note_fixture(%{slug: "b", visibility: :unlisted}, user)
|
||||
assert Notes.get_note_by_slug("b", user) == note
|
||||
|
||||
note = note_fixture(%{slug: "c", visibility: :private}, user)
|
||||
assert Notes.get_note_by_slug("c", user) == note
|
||||
end
|
||||
|
||||
test "get_note_by_slug/1 only returns unlisted or public notes for other users", %{
|
||||
user: user
|
||||
} do
|
||||
another_user = user_fixture()
|
||||
note = note_fixture(%{slug: "a", visibility: :public}, another_user)
|
||||
assert Notes.get_note_by_slug("a", user) == note
|
||||
|
||||
note = note_fixture(%{slug: "b", visibility: :unlisted}, another_user)
|
||||
assert Notes.get_note_by_slug("b", user) == note
|
||||
|
||||
note_fixture(%{slug: "c", visibility: :private}, another_user)
|
||||
assert Notes.get_note_by_slug("c", user) |> is_nil()
|
||||
end
|
||||
|
||||
test "create_note/1 with valid data creates a note", %{user: user} do
|
||||
valid_attrs = %{
|
||||
"content" => "some content",
|
||||
"tags_string" => "tag1,tag2",
|
||||
"title" => "some title",
|
||||
"slug" => "some-slug",
|
||||
"visibility" => :public
|
||||
}
|
||||
|
||||
assert {:ok, %Note{} = note} = Notes.create_note(valid_attrs, user)
|
||||
assert note.content == "some content"
|
||||
assert note.tags == ["tag1", "tag2"]
|
||||
assert note.title == "some title"
|
||||
assert note.slug == "some-slug"
|
||||
assert note.visibility == :public
|
||||
end
|
||||
|
||||
@ -75,14 +100,14 @@ defmodule Memex.NotesTest do
|
||||
update_attrs = %{
|
||||
"content" => "some updated content",
|
||||
"tags_string" => "tag1,tag2",
|
||||
"title" => "some updated title",
|
||||
"slug" => "some-updated-slug",
|
||||
"visibility" => :private
|
||||
}
|
||||
|
||||
assert {:ok, %Note{} = note} = Notes.update_note(note, update_attrs, user)
|
||||
assert note.content == "some updated content"
|
||||
assert note.tags == ["tag1", "tag2"]
|
||||
assert note.title == "some updated title"
|
||||
assert note.slug == "some-updated-slug"
|
||||
assert note.visibility == :private
|
||||
end
|
||||
|
||||
|
@ -3,7 +3,7 @@ defmodule Memex.PipelinesTest do
|
||||
import Memex.PipelinesFixtures
|
||||
alias Memex.{Pipelines, Pipelines.Pipeline}
|
||||
@moduletag :pipelines_test
|
||||
@invalid_attrs %{description: nil, tag: nil, title: nil, visibility: nil}
|
||||
@invalid_attrs %{description: nil, tag: nil, slug: nil, visibility: nil}
|
||||
|
||||
describe "pipelines" do
|
||||
setup do
|
||||
@ -11,9 +11,9 @@ defmodule Memex.PipelinesTest do
|
||||
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)
|
||||
pipeline_a = pipeline_fixture(%{slug: "a", visibility: :public}, user)
|
||||
pipeline_b = pipeline_fixture(%{slug: "b", visibility: :unlisted}, user)
|
||||
pipeline_c = pipeline_fixture(%{slug: "c", visibility: :private}, user)
|
||||
assert Pipelines.list_pipelines(user) == [pipeline_a, pipeline_b, pipeline_c]
|
||||
end
|
||||
|
||||
@ -52,18 +52,43 @@ defmodule Memex.PipelinesTest do
|
||||
end
|
||||
end
|
||||
|
||||
test "get_pipeline_by_slug/1 returns the pipeline with given id", %{user: user} do
|
||||
pipeline = pipeline_fixture(%{slug: "a", visibility: :public}, user)
|
||||
assert Pipelines.get_pipeline_by_slug("a", user) == pipeline
|
||||
|
||||
pipeline = pipeline_fixture(%{slug: "b", visibility: :unlisted}, user)
|
||||
assert Pipelines.get_pipeline_by_slug("b", user) == pipeline
|
||||
|
||||
pipeline = pipeline_fixture(%{slug: "c", visibility: :private}, user)
|
||||
assert Pipelines.get_pipeline_by_slug("c", user) == pipeline
|
||||
end
|
||||
|
||||
test "get_pipeline_by_slug/1 only returns unlisted or public pipelines for other users", %{
|
||||
user: user
|
||||
} do
|
||||
another_user = user_fixture()
|
||||
pipeline = pipeline_fixture(%{slug: "a", visibility: :public}, another_user)
|
||||
assert Pipelines.get_pipeline_by_slug("a", user) == pipeline
|
||||
|
||||
pipeline = pipeline_fixture(%{slug: "b", visibility: :unlisted}, another_user)
|
||||
assert Pipelines.get_pipeline_by_slug("b", user) == pipeline
|
||||
|
||||
pipeline_fixture(%{slug: "c", visibility: :private}, another_user)
|
||||
assert Pipelines.get_pipeline_by_slug("c", user) |> is_nil()
|
||||
end
|
||||
|
||||
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",
|
||||
"slug" => "some-slug",
|
||||
"visibility" => :public
|
||||
}
|
||||
|
||||
assert {:ok, %Pipeline{} = pipeline} = Pipelines.create_pipeline(valid_attrs, user)
|
||||
assert pipeline.description == "some description"
|
||||
assert pipeline.tags == ["tag1", "tag2"]
|
||||
assert pipeline.title == "some title"
|
||||
assert pipeline.slug == "some-slug"
|
||||
assert pipeline.visibility == :public
|
||||
end
|
||||
|
||||
@ -77,7 +102,7 @@ defmodule Memex.PipelinesTest do
|
||||
update_attrs = %{
|
||||
"description" => "some updated description",
|
||||
"tags_string" => "tag1,tag2",
|
||||
"title" => "some updated title",
|
||||
"slug" => "some-updated-slug",
|
||||
"visibility" => :private
|
||||
}
|
||||
|
||||
@ -86,7 +111,7 @@ defmodule Memex.PipelinesTest do
|
||||
|
||||
assert pipeline.description == "some updated description"
|
||||
assert pipeline.tags == ["tag1", "tag2"]
|
||||
assert pipeline.title == "some updated title"
|
||||
assert pipeline.slug == "some-updated-slug"
|
||||
assert pipeline.visibility == :private
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user