Skip to content

Commit

Permalink
test(books): rework books_test.exs a little bit (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gladear authored Jan 17, 2025
1 parent 08a005c commit ea4fbdd
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions apps/app/test/app/books_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ defmodule App.BooksTest do
alias App.Books.Book
alias App.Books.Members

@valid_book_name "A valid book name !"

## Database getters

describe "get_book_of_user/2" do
setup :book_with_creator_context
setup do
book = book_fixture()
user = user_fixture()
_member = book_member_fixture(book, user_id: user.id, role: :creator)
%{book: book, user: user}
end

test "returns the book", %{book: book, user: user} do
user_book = Books.get_book_of_user(book.id, user)
Expand All @@ -38,7 +41,12 @@ defmodule App.BooksTest do
end

describe "get_book_of_user!/2" do
setup :book_with_creator_context
setup do
book = book_fixture()
user = user_fixture()
_member = book_member_fixture(book, user_id: user.id, role: :creator)
%{book: book, user: user}
end

test "returns the book", %{book: book, user: user} do
user_book = Books.get_book_of_user!(book.id, user)
Expand Down Expand Up @@ -195,7 +203,7 @@ defmodule App.BooksTest do
book_attributes(nickname: "Creator nickname")
|> Books.create_book(user)

assert book.name == @valid_book_name
assert book.name == "A valid book name !"

assert member = Members.get_membership(book, user)
assert member.role == :creator
Expand All @@ -222,7 +230,9 @@ defmodule App.BooksTest do
## Name update

describe "update_book_name/2" do
setup :book_with_creator_context
setup do
%{book: book_fixture()}
end

test "updates the name of the book", %{book: book} do
assert {:ok, updated} =
Expand Down Expand Up @@ -253,7 +263,9 @@ defmodule App.BooksTest do
## Deletion

describe "delete_book!/2" do
setup :book_with_creator_context
setup do
%{book: book_fixture()}
end

test "deletes the book", %{book: book} do
deleted = Books.delete_book!(book)
Expand Down Expand Up @@ -355,16 +367,4 @@ defmodule App.BooksTest do
assert Books.get_book_by_invitation_token("foo") == nil
end
end

defp book_with_creator_context(_context) do
book = book_fixture()
user = user_fixture()
member = book_member_fixture(book, user_id: user.id, role: :creator)

%{
book: book,
user: user,
member: member
}
end
end

0 comments on commit ea4fbdd

Please sign in to comment.