memEx/test/support/fixtures/contexts_fixtures.ex

28 lines
668 B
Elixir
Raw Normal View History

2022-07-25 20:11:08 -04:00
defmodule Memex.ContextsFixtures do
@moduledoc """
This module defines test helpers for creating
entities via the `Memex.Contexts` context.
"""
2022-11-26 14:51:18 -05:00
import Memex.Fixtures
2022-11-24 12:44:34 -05:00
alias Memex.{Accounts.User, Contexts, Contexts.Context}
2022-07-25 20:11:08 -04:00
@doc """
Generate a context.
"""
2022-11-24 12:44:34 -05:00
@spec context_fixture(User.t()) :: Context.t()
@spec context_fixture(attrs :: map(), User.t()) :: Context.t()
def context_fixture(attrs \\ %{}, user) do
2022-07-25 20:11:08 -04:00
{:ok, context} =
attrs
|> Enum.into(%{
content: "some content",
2022-11-27 21:10:54 -05:00
tags: [],
2022-11-26 14:51:18 -05:00
slug: random_slug(),
2022-11-24 12:44:34 -05:00
visibility: :private
2022-07-25 20:11:08 -04:00
})
2022-11-24 12:44:34 -05:00
|> Contexts.create_context(user)
2022-07-25 20:11:08 -04:00
context
end
end