mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-20 06:37:59 +01:00
125 lines
4.1 KiB
Elixir
125 lines
4.1 KiB
Elixir
defmodule Philomena.ConversationsTest do
|
|
use Philomena.DataCase
|
|
|
|
alias Philomena.Conversations
|
|
|
|
describe "conversations" do
|
|
alias Philomena.Conversations.Conversation
|
|
|
|
@valid_attrs %{}
|
|
@update_attrs %{}
|
|
@invalid_attrs %{}
|
|
|
|
def conversation_fixture(attrs \\ %{}) do
|
|
{:ok, conversation} =
|
|
attrs
|
|
|> Enum.into(@valid_attrs)
|
|
|> Conversations.create_conversation()
|
|
|
|
conversation
|
|
end
|
|
|
|
test "list_conversations/0 returns all conversations" do
|
|
conversation = conversation_fixture()
|
|
assert Conversations.list_conversations() == [conversation]
|
|
end
|
|
|
|
test "get_conversation!/1 returns the conversation with given id" do
|
|
conversation = conversation_fixture()
|
|
assert Conversations.get_conversation!(conversation.id) == conversation
|
|
end
|
|
|
|
test "create_conversation/1 with valid data creates a conversation" do
|
|
assert {:ok, %Conversation{} = conversation} =
|
|
Conversations.create_conversation(@valid_attrs)
|
|
end
|
|
|
|
test "create_conversation/1 with invalid data returns error changeset" do
|
|
assert {:error, %Ecto.Changeset{}} = Conversations.create_conversation(@invalid_attrs)
|
|
end
|
|
|
|
test "update_conversation/2 with valid data updates the conversation" do
|
|
conversation = conversation_fixture()
|
|
|
|
assert {:ok, %Conversation{} = conversation} =
|
|
Conversations.update_conversation(conversation, @update_attrs)
|
|
end
|
|
|
|
test "update_conversation/2 with invalid data returns error changeset" do
|
|
conversation = conversation_fixture()
|
|
|
|
assert {:error, %Ecto.Changeset{}} =
|
|
Conversations.update_conversation(conversation, @invalid_attrs)
|
|
|
|
assert conversation == Conversations.get_conversation!(conversation.id)
|
|
end
|
|
|
|
test "delete_conversation/1 deletes the conversation" do
|
|
conversation = conversation_fixture()
|
|
assert {:ok, %Conversation{}} = Conversations.delete_conversation(conversation)
|
|
assert_raise Ecto.NoResultsError, fn -> Conversations.get_conversation!(conversation.id) end
|
|
end
|
|
|
|
test "change_conversation/1 returns a conversation changeset" do
|
|
conversation = conversation_fixture()
|
|
assert %Ecto.Changeset{} = Conversations.change_conversation(conversation)
|
|
end
|
|
end
|
|
|
|
describe "messages" do
|
|
alias Philomena.Conversations.Message
|
|
|
|
@valid_attrs %{}
|
|
@update_attrs %{}
|
|
@invalid_attrs %{}
|
|
|
|
def message_fixture(attrs \\ %{}) do
|
|
{:ok, message} =
|
|
attrs
|
|
|> Enum.into(@valid_attrs)
|
|
|> Conversations.create_message()
|
|
|
|
message
|
|
end
|
|
|
|
test "list_messages/0 returns all messages" do
|
|
message = message_fixture()
|
|
assert Conversations.list_messages() == [message]
|
|
end
|
|
|
|
test "get_message!/1 returns the message with given id" do
|
|
message = message_fixture()
|
|
assert Conversations.get_message!(message.id) == message
|
|
end
|
|
|
|
test "create_message/1 with valid data creates a message" do
|
|
assert {:ok, %Message{} = message} = Conversations.create_message(@valid_attrs)
|
|
end
|
|
|
|
test "create_message/1 with invalid data returns error changeset" do
|
|
assert {:error, %Ecto.Changeset{}} = Conversations.create_message(@invalid_attrs)
|
|
end
|
|
|
|
test "update_message/2 with valid data updates the message" do
|
|
message = message_fixture()
|
|
assert {:ok, %Message{} = message} = Conversations.update_message(message, @update_attrs)
|
|
end
|
|
|
|
test "update_message/2 with invalid data returns error changeset" do
|
|
message = message_fixture()
|
|
assert {:error, %Ecto.Changeset{}} = Conversations.update_message(message, @invalid_attrs)
|
|
assert message == Conversations.get_message!(message.id)
|
|
end
|
|
|
|
test "delete_message/1 deletes the message" do
|
|
message = message_fixture()
|
|
assert {:ok, %Message{}} = Conversations.delete_message(message)
|
|
assert_raise Ecto.NoResultsError, fn -> Conversations.get_message!(message.id) end
|
|
end
|
|
|
|
test "change_message/1 returns a message changeset" do
|
|
message = message_fixture()
|
|
assert %Ecto.Changeset{} = Conversations.change_message(message)
|
|
end
|
|
end
|
|
end
|