-
-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow checking root model in @can directive
- Loading branch information
1 parent
2d59623
commit 362b136
Showing
3 changed files
with
62 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -281,6 +281,42 @@ public function testInjectArgsPassesClientArgumentToPolicy(): void | |
]); | ||
} | ||
|
||
public function testChecksAgainstRootModel(): void | ||
{ | ||
$this->be(new User()); | ||
|
||
$this->mockResolver(fn (): User => $this->resolveUser()); | ||
|
||
$this->schema = /** @lang GraphQL */ ' | ||
type Query { | ||
user(foo: String): User! @mock | ||
} | ||
type User { | ||
name: String @can(ability: "view", root: true) | ||
email: String @can(ability: "superAdminOnly", root: true) | ||
} | ||
'; | ||
|
||
$this->graphQL(/** @lang GraphQL */ ' | ||
{ | ||
user(foo: "bar") { | ||
name | ||
} | ||
} | ||
')->assertJson([ | ||
'data' => [ | ||
'user' => [ | ||
'name' => 'foo', | ||
'email' => null, | ||
], | ||
], | ||
])->assertJsonFragment([ | ||
'message' => 'Only super admins allowed', | ||
]); | ||
} | ||
|
||
public function testInjectedArgsAndStaticArgs(): void | ||
{ | ||
$this->be(new User()); | ||
|
@@ -322,6 +358,7 @@ public static function resolveUser(): User | |
{ | ||
$user = new User(); | ||
$user->name = 'foo'; | ||
$user->email = '[email protected]'; | ||
|
||
return $user; | ||
} | ||
|