Aggiedit/test/aggiedit/rooms_test.exs

116 lines
3.4 KiB
Elixir
Raw Permalink Normal View History

defmodule Aggiedit.RoomsTest do
use Aggiedit.DataCase
alias Aggiedit.Rooms
describe "rooms" do
alias Aggiedit.Rooms.Room
import Aggiedit.RoomsFixtures
@invalid_attrs %{domain: nil}
test "list_rooms/0 returns all rooms" do
room = room_fixture()
assert Rooms.list_rooms() == [room]
end
test "get_room!/1 returns the room with given id" do
room = room_fixture()
assert Rooms.get_room!(room.id) == room
end
test "create_room/1 with valid data creates a room" do
valid_attrs = %{domain: "some domain"}
assert {:ok, %Room{} = room} = Rooms.create_room(valid_attrs)
assert room.domain == "some domain"
end
test "create_room/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Rooms.create_room(@invalid_attrs)
end
test "update_room/2 with valid data updates the room" do
room = room_fixture()
update_attrs = %{domain: "some updated domain"}
assert {:ok, %Room{} = room} = Rooms.update_room(room, update_attrs)
assert room.domain == "some updated domain"
end
test "update_room/2 with invalid data returns error changeset" do
room = room_fixture()
assert {:error, %Ecto.Changeset{}} = Rooms.update_room(room, @invalid_attrs)
assert room == Rooms.get_room!(room.id)
end
test "delete_room/1 deletes the room" do
room = room_fixture()
assert {:ok, %Room{}} = Rooms.delete_room(room)
assert_raise Ecto.NoResultsError, fn -> Rooms.get_room!(room.id) end
end
test "change_room/1 returns a room changeset" do
room = room_fixture()
assert %Ecto.Changeset{} = Rooms.change_room(room)
end
end
describe "posts" do
alias Aggiedit.Rooms.Post
import Aggiedit.RoomsFixtures
@invalid_attrs %{body: nil, title: nil}
test "list_posts/0 returns all posts" do
post = post_fixture()
assert Rooms.list_posts() == [post]
end
test "get_post!/1 returns the post with given id" do
post = post_fixture()
assert Rooms.get_post!(post.id) == post
end
test "create_post/1 with valid data creates a post" do
valid_attrs = %{body: "some body", title: "some title"}
assert {:ok, %Post{} = post} = Rooms.create_post(valid_attrs)
assert post.body == "some body"
assert post.title == "some title"
end
test "create_post/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Rooms.create_post(@invalid_attrs)
end
test "update_post/2 with valid data updates the post" do
post = post_fixture()
update_attrs = %{body: "some updated body", title: "some updated title"}
assert {:ok, %Post{} = post} = Rooms.update_post(post, update_attrs)
assert post.body == "some updated body"
assert post.title == "some updated title"
end
test "update_post/2 with invalid data returns error changeset" do
post = post_fixture()
assert {:error, %Ecto.Changeset{}} = Rooms.update_post(post, @invalid_attrs)
assert post == Rooms.get_post!(post.id)
end
test "delete_post/1 deletes the post" do
post = post_fixture()
assert {:ok, %Post{}} = Rooms.delete_post(post)
assert_raise Ecto.NoResultsError, fn -> Rooms.get_post!(post.id) end
end
test "change_post/1 returns a post changeset" do
post = post_fixture()
assert %Ecto.Changeset{} = Rooms.change_post(post)
end
end
end