1 defmodule Pleroma.RepoTest do
6 describe "find_resource/1" do
9 query = from(t in User, where: t.id == ^user.id)
10 assert Repo.find_resource(query) == {:ok, user}
13 test "returns not_found" do
14 query = from(t in User, where: t.id == ^"9gBuXNpD2NyDmmxxdw")
15 assert Repo.find_resource(query) == {:error, :not_found}
19 describe "get_assoc/2" do
20 test "get assoc from preloaded data" do
21 user = %User{name: "Agent Smith"}
22 token = %Pleroma.Web.OAuth.Token{insert(:oauth_token) | user: user}
23 assert Repo.get_assoc(token, :user) == {:ok, user}
26 test "get one-to-one assoc from repo" do
27 user = insert(:user, name: "Jimi Hendrix")
28 token = refresh_record(insert(:oauth_token, user: user))
30 assert Repo.get_assoc(token, :user) == {:ok, user}
33 test "get one-to-many assoc from repo" do
35 notification = refresh_record(insert(:notification, user: user))
37 assert Repo.get_assoc(user, :notifications) == {:ok, [notification]}
40 test "return error if has not assoc " do
41 token = insert(:oauth_token, user: nil)
42 assert Repo.get_assoc(token, :user) == {:error, :not_found}