131 lines
3.6 KiB
Elixir
131 lines
3.6 KiB
Elixir
defmodule Diffuser.AccountsTest do
|
|
use Diffuser.DataCase
|
|
|
|
alias Diffuser.Accounts
|
|
|
|
describe "users" do
|
|
alias Diffuser.Accounts.User
|
|
|
|
import Diffuser.AccountsFixtures
|
|
|
|
@invalid_attrs %{}
|
|
|
|
test "list_users/0 returns all users" do
|
|
user = user_fixture()
|
|
assert Accounts.list_users() == [user]
|
|
end
|
|
|
|
test "get_user!/1 returns the user with given id" do
|
|
user = user_fixture()
|
|
assert Accounts.get_user!(user.id) == user
|
|
end
|
|
|
|
test "create_user/1 with valid data creates a user" do
|
|
valid_attrs = %{}
|
|
|
|
assert {:ok, %User{} = user} = Accounts.create_user(valid_attrs)
|
|
end
|
|
|
|
test "create_user/1 with invalid data returns error changeset" do
|
|
assert {:error, %Ecto.Changeset{}} = Accounts.create_user(@invalid_attrs)
|
|
end
|
|
|
|
test "update_user/2 with valid data updates the user" do
|
|
user = user_fixture()
|
|
update_attrs = %{}
|
|
|
|
assert {:ok, %User{} = user} = Accounts.update_user(user, update_attrs)
|
|
end
|
|
|
|
test "update_user/2 with invalid data returns error changeset" do
|
|
user = user_fixture()
|
|
assert {:error, %Ecto.Changeset{}} = Accounts.update_user(user, @invalid_attrs)
|
|
assert user == Accounts.get_user!(user.id)
|
|
end
|
|
|
|
test "delete_user/1 deletes the user" do
|
|
user = user_fixture()
|
|
assert {:ok, %User{}} = Accounts.delete_user(user)
|
|
assert_raise Ecto.NoResultsError, fn -> Accounts.get_user!(user.id) end
|
|
end
|
|
|
|
test "change_user/1 returns a user changeset" do
|
|
user = user_fixture()
|
|
assert %Ecto.Changeset{} = Accounts.change_user(user)
|
|
end
|
|
end
|
|
|
|
describe "votes" do
|
|
alias Diffuser.Accounts.Vote
|
|
|
|
import Diffuser.AccountsFixtures
|
|
|
|
@invalid_attrs %{}
|
|
|
|
test "list_votes/0 returns all votes" do
|
|
vote = vote_fixture()
|
|
assert Accounts.list_votes() == [vote]
|
|
end
|
|
|
|
test "get_vote!/1 returns the vote with given id" do
|
|
vote = vote_fixture()
|
|
assert Accounts.get_vote!(vote.id) == vote
|
|
end
|
|
|
|
test "create_vote/1 with valid data creates a vote" do
|
|
valid_attrs = %{}
|
|
|
|
assert {:ok, %Vote{} = vote} = Accounts.create_vote(valid_attrs)
|
|
end
|
|
|
|
test "create_vote/1 with invalid data returns error changeset" do
|
|
assert {:error, %Ecto.Changeset{}} = Accounts.create_vote(@invalid_attrs)
|
|
end
|
|
|
|
test "update_vote/2 with valid data updates the vote" do
|
|
vote = vote_fixture()
|
|
update_attrs = %{}
|
|
|
|
assert {:ok, %Vote{} = vote} = Accounts.update_vote(vote, update_attrs)
|
|
end
|
|
|
|
test "update_vote/2 with invalid data returns error changeset" do
|
|
vote = vote_fixture()
|
|
assert {:error, %Ecto.Changeset{}} = Accounts.update_vote(vote, @invalid_attrs)
|
|
assert vote == Accounts.get_vote!(vote.id)
|
|
end
|
|
|
|
test "delete_vote/1 deletes the vote" do
|
|
vote = vote_fixture()
|
|
assert {:ok, %Vote{}} = Accounts.delete_vote(vote)
|
|
assert_raise Ecto.NoResultsError, fn -> Accounts.get_vote!(vote.id) end
|
|
end
|
|
|
|
test "change_vote/1 returns a vote changeset" do
|
|
vote = vote_fixture()
|
|
assert %Ecto.Changeset{} = Accounts.change_vote(vote)
|
|
end
|
|
end
|
|
|
|
describe "upvote/2" do
|
|
alias Diffuser.Accounts.Vote
|
|
|
|
import Diffuser.AccountsFixtures
|
|
import Diffuser.GeneratorFixtures
|
|
|
|
test "creates upvote and associates it to specific prompt" do
|
|
%{id: pr_id} = pr = prompt_request_fixture()
|
|
|
|
assert {:ok, %Vote{prompt_request_id: ^pr_id}} = Accounts.upvote(pr)
|
|
|
|
%{votes: votes} = Diffuser.Generator.get_prompt_request!(pr_id) |> Repo.preload(:votes)
|
|
assert votes |> length() == 1
|
|
end
|
|
|
|
test "creates upvote and associates it to current user" do
|
|
|
|
|
|
end
|
|
end
|
|
end
|