memEx/test/support/fixtures/contexts_fixtures.ex

28 lines
703 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-12-15 22:33:10 -05:00
tags: ["example-tag"],
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
2022-12-19 22:29:26 -05:00
%{context | tags_string: nil}
2022-07-25 20:11:08 -04:00
end
end