2
2
3
3
namespace Orion \Tests \Feature ;
4
4
5
- use Carbon \Carbon ;
6
5
use Illuminate \Support \Facades \Gate ;
7
- use Orion \Tests \Fixtures \App \Models \Company ;
8
6
use Orion \Tests \Fixtures \App \Models \Post ;
9
- use Orion \Tests \Fixtures \App \Models \Team ;
10
- use Orion \Tests \Fixtures \App \Models \User ;
11
7
use Orion \Tests \Fixtures \App \Policies \GreenPolicy ;
12
8
13
9
class StandardIndexNestedFilteringOperationsTest extends TestCase
@@ -24,11 +20,13 @@ public function getting_a_list_of_resources_nested_filtered_by_model_field_using
24
20
'/api/posts/search ' ,
25
21
[
26
22
'filters ' => [
27
- ['field ' => 'title ' , 'operator ' => 'in ' ,'value ' => ['match ' , 'not_match ' ]],
28
- ['nested ' => [
29
- ['field ' => 'title ' , 'value ' => 'match ' ],
30
- ['field ' => 'title ' , 'operator ' => '!= ' , 'value ' => 'not match ' ]
31
- ]],
23
+ ['field ' => 'title ' , 'operator ' => 'in ' , 'value ' => ['match ' , 'not_match ' ]],
24
+ [
25
+ 'nested ' => [
26
+ ['field ' => 'title ' , 'value ' => 'match ' ],
27
+ ['field ' => 'title ' , 'operator ' => '!= ' , 'value ' => 'not match ' ],
28
+ ],
29
+ ],
32
30
],
33
31
]
34
32
);
@@ -53,9 +51,12 @@ public function getting_a_list_of_resources_nested_filtered_by_model_field_using
53
51
[
54
52
'filters ' => [
55
53
['field ' => 'title ' , 'operator ' => '= ' , 'value ' => 'match ' ],
56
- ['type ' => 'or ' , 'nested ' => [
57
- ['field ' => 'position ' , 'operator ' => '= ' , 'value ' => 3 ],
58
- ]],
54
+ [
55
+ 'type ' => 'or ' ,
56
+ 'nested ' => [
57
+ ['field ' => 'position ' , 'operator ' => '= ' , 'value ' => 3 ],
58
+ ],
59
+ ],
59
60
],
60
61
]
61
62
);
@@ -66,6 +67,36 @@ public function getting_a_list_of_resources_nested_filtered_by_model_field_using
66
67
);
67
68
}
68
69
70
+ /** @test */
71
+ public function getting_a_list_of_resources_nested_filtered_by_model_field_using_in_operator (): void
72
+ {
73
+ $ matchingPost = factory (Post::class)->create (['title ' => 'match ' ])->fresh ();
74
+ factory (Post::class)->create (['title ' => 'not match ' ])->fresh ();
75
+
76
+ Gate::policy (Post::class, GreenPolicy::class);
77
+
78
+ $ response = $ this ->post (
79
+ '/api/posts/search ' ,
80
+ [
81
+ 'filters ' => [
82
+
83
+ ['field ' => 'title ' , 'operator ' => '!= ' , 'value ' => 'not match ' ],
84
+ [
85
+ 'nested ' => [
86
+ ['field ' => 'title ' , 'operator ' => 'in ' , 'value ' => ['match ' ]],
87
+ ['field ' => 'title ' , 'operator ' => '!= ' , 'value ' => 'not match ' ],
88
+ ],
89
+ ],
90
+ ],
91
+ ]
92
+ );
93
+
94
+ $ this ->assertResourcesPaginated (
95
+ $ response ,
96
+ $ this ->makePaginator ([$ matchingPost ], 'posts/search ' )
97
+ );
98
+ }
99
+
69
100
/** @test */
70
101
public function getting_a_list_of_resources_nested_filtered_by_model_field_using_not_equal_operator (): void
71
102
{
@@ -78,9 +109,11 @@ public function getting_a_list_of_resources_nested_filtered_by_model_field_using
78
109
'/api/posts/search ' ,
79
110
[
80
111
'filters ' => [
81
- ['nested ' => [
82
- ['field ' => 'position ' , 'operator ' => '!= ' , 'value ' => 5 ]
83
- ]],
112
+ [
113
+ 'nested ' => [
114
+ ['field ' => 'position ' , 'operator ' => '!= ' , 'value ' => 5 ],
115
+ ],
116
+ ],
84
117
],
85
118
]
86
119
);
@@ -103,9 +136,11 @@ public function getting_a_list_of_resources_nested_filtered_by_not_whitelisted_f
103
136
'/api/posts/search ' ,
104
137
[
105
138
'filters ' => [
106
- ['nested ' => [
107
- ['field ' => 'body ' , 'operator ' => '= ' , 'value ' => 'match ' ]
108
- ]],
139
+ [
140
+ 'nested ' => [
141
+ ['field ' => 'body ' , 'operator ' => '= ' , 'value ' => 'match ' ],
142
+ ],
143
+ ],
109
144
],
110
145
]
111
146
);
0 commit comments