From 58bd69332b5e48079cfda79bfe1104292d88561b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Pr=C3=A1?= Date: Wed, 30 Oct 2019 18:41:38 +0100 Subject: [PATCH] Add missing test to FieldAuthorization and remove unnecessary code from ObjectScope --- .DS_Store | Bin 0 -> 6148 bytes lib/middlewares/object_scope_authorization.ex | 6 ----- test/middlewares/field_authorization_test.exs | 21 ++++++++++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ebc01a8233fb3c80df2ab82f51a94388082d2b06 GIT binary patch literal 6148 zcmeHKI|>3Z5S{S@f{mqRuHX%V=n1@lpkgBmg4SDkE|2D$PqQrBt%dRiCNG)HOUNsB zc0@$ikK;;YAtE!lp}cJ9n(do+Y?KiN!g0p^xw~I4x9ho++ZQnIR1R{Jr<_`R+o4eb zDnJFO02QDDLo1LKb~YdSV4g<>sKC!FVBd!VH>` {:ok, %{phone: "123456"}} end end + + field :not_struct, :user do + resolve fn _args, _ -> {:ok, %{id: 1}} end + end end object :user do @@ -183,6 +187,12 @@ defmodule Rajska.FieldAuthorizationTest do end end + test "Raises when source object is not a struct" do + assert_raise RuntimeError, ~r/Expected a Struct for source object in field \"phone\", got %{id: 1}/, fn -> + Absinthe.run(not_struct_query(), __MODULE__.Schema, context(:user, 2)) + end + end + defp get_user_query(id, is_email_public) do """ { @@ -217,5 +227,16 @@ defmodule Rajska.FieldAuthorizationTest do """ end + defp not_struct_query do + """ + { + notStruct { + name + phone + } + } + """ + end + defp context(role, id), do: [context: %{current_user: %{role: role, id: id}}] end