-
-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
exclude properties from partial responses (#622)
- Loading branch information
Showing
3 changed files
with
75 additions
and
3 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 |
---|---|---|
|
@@ -256,6 +256,29 @@ public function test_xhr_partial_response(): void | |
$this->assertSame('123', $page->version); | ||
} | ||
|
||
public function test_exclude_props_from_partial_response(): void | ||
{ | ||
$request = Request::create('/user/123', 'GET'); | ||
$request->headers->add(['X-Inertia' => 'true']); | ||
$request->headers->add(['X-Inertia-Partial-Component' => 'User/Edit']); | ||
$request->headers->add(['X-Inertia-Partial-Except' => 'user']); | ||
|
||
$user = (object) ['name' => 'Jonathan']; | ||
$response = new Response('User/Edit', ['user' => $user, 'partial' => 'partial-data'], 'app', '123'); | ||
$response = $response->toResponse($request); | ||
$page = $response->getData(); | ||
|
||
$props = get_object_vars($page->props); | ||
|
||
$this->assertInstanceOf(JsonResponse::class, $response); | ||
$this->assertSame('User/Edit', $page->component); | ||
$this->assertFalse(isset($props['user'])); | ||
$this->assertCount(1, $props); | ||
$this->assertSame('partial-data', $page->props->partial); | ||
$this->assertSame('/user/123', $page->url); | ||
$this->assertSame('123', $page->version); | ||
} | ||
|
||
public function test_nested_partial_props(): void | ||
{ | ||
$request = Request::create('/user/123', 'GET'); | ||
|
@@ -275,8 +298,8 @@ public function test_nested_partial_props(): void | |
'token' => 'value', | ||
], | ||
'shared' => [ | ||
'flash' => 'Value', | ||
] | ||
'flash' => 'value', | ||
], | ||
]; | ||
|
||
$response = new Response('User/Edit', $props); | ||
|
@@ -290,6 +313,38 @@ public function test_nested_partial_props(): void | |
$this->assertSame('value', $page->props->auth->refresh_token); | ||
} | ||
|
||
public function test_exclude_nested_props_from_partial_response(): void | ||
{ | ||
$request = Request::create('/user/123', 'GET'); | ||
$request->headers->add(['X-Inertia' => 'true']); | ||
$request->headers->add(['X-Inertia-Partial-Component' => 'User/Edit']); | ||
$request->headers->add(['X-Inertia-Partial-Data' => 'auth']); | ||
$request->headers->add(['X-Inertia-Partial-Except' => 'auth.user']); | ||
|
||
$props = [ | ||
'auth' => [ | ||
'user' => new LazyProp(function () { | ||
return [ | ||
'name' => 'Jonathan Reinink', | ||
'email' => '[email protected]', | ||
]; | ||
}), | ||
'refresh_token' => 'value', | ||
], | ||
'shared' => [ | ||
'flash' => 'value', | ||
], | ||
]; | ||
|
||
$response = new Response('User/Edit', $props); | ||
$response = $response->toResponse($request); | ||
$page = $response->getData(); | ||
|
||
$this->assertFalse(isset($page->props->auth->user)); | ||
$this->assertFalse(isset($page->props->shared)); | ||
$this->assertSame('value', $page->props->auth->refresh_token); | ||
} | ||
|
||
public function test_lazy_props_are_not_included_by_default(): void | ||
{ | ||
$request = Request::create('/users', 'GET'); | ||
|