3
3
namespace SkoreLabs \JsonApi \Tests ;
4
4
5
5
use Illuminate \Support \Facades \Route ;
6
- use SkoreLabs \JsonApi \Http \ Resources \ JsonApiResource ;
6
+ use SkoreLabs \JsonApi \Support \ JsonApi ;
7
7
use SkoreLabs \JsonApi \Testing \Assert ;
8
8
use SkoreLabs \JsonApi \Tests \Fixtures \Post ;
9
9
10
10
class JsonApiResourceTest extends TestCase
11
11
{
12
12
public function testResourcesMayBeConvertedToJsonApi ()
13
13
{
14
+ $ this ->bypassPolicies ();
15
+
14
16
Route::get ('/ ' , function () {
15
- return new JsonApiResource (new Post ([
17
+ return JsonApi:: format (new Post ([
16
18
'id ' => 5 ,
17
19
'title ' => 'Test Title ' ,
18
20
'abstract ' => 'Test abstract ' ,
19
- ]), true );
21
+ ]));
20
22
});
21
23
22
24
$ response = $ this ->get ('/ ' , ['Accept ' => 'application/json ' ]);
@@ -37,12 +39,14 @@ public function testResourcesMayBeConvertedToJsonApi()
37
39
38
40
public function testResourcesHasIdentifier ()
39
41
{
42
+ $ this ->bypassPolicies ();
43
+
40
44
Route::get ('/ ' , function () {
41
- return new JsonApiResource (new Post ([
45
+ return JsonApi:: format (new Post ([
42
46
'id ' => 5 ,
43
47
'title ' => 'Test Title ' ,
44
48
'abstract ' => 'Test abstract ' ,
45
- ]), true );
49
+ ]));
46
50
});
47
51
48
52
$ this ->get ('/ ' , ['Accept ' => 'application/json ' ])->assertJsonApi (function (Assert $ json ) {
@@ -52,12 +56,14 @@ public function testResourcesHasIdentifier()
52
56
53
57
public function testResourcesHasAttribute ()
54
58
{
59
+ $ this ->bypassPolicies ();
60
+
55
61
Route::get ('/ ' , function () {
56
- return new JsonApiResource (new Post ([
62
+ return JsonApi:: format (new Post ([
57
63
'id ' => 5 ,
58
64
'title ' => 'Test Title ' ,
59
65
'abstract ' => 'Test abstract ' ,
60
- ]), true );
66
+ ]));
61
67
});
62
68
63
69
$ this ->get ('/ ' , ['Accept ' => 'application/json ' ])->assertJsonApi (function (Assert $ json ) {
@@ -67,12 +73,14 @@ public function testResourcesHasAttribute()
67
73
68
74
public function testResourcesHasAttributes ()
69
75
{
76
+ $ this ->bypassPolicies ();
77
+
70
78
Route::get ('/ ' , function () {
71
- return new JsonApiResource (new Post ([
79
+ return JsonApi:: format (new Post ([
72
80
'id ' => 5 ,
73
81
'title ' => 'Test Title ' ,
74
82
'abstract ' => 'Test abstract ' ,
75
- ]), true );
83
+ ]));
76
84
});
77
85
78
86
$ this ->get ('/ ' , ['Accept ' => 'application/json ' ])->assertJsonApi (function (Assert $ json ) {
@@ -86,7 +94,7 @@ public function testResourcesHasAttributes()
86
94
// FIXME: Not available in Laravel 6, wait to support removal
87
95
// public function testResourcesMayBeConvertedToJsonApiWithToJsonMethod()
88
96
// {
89
- // $resource = new JsonApiResource (new Post([
97
+ // $resource = JsonApi::format (new Post([
90
98
// 'id' => 5,
91
99
// 'title' => 'Test Title',
92
100
// 'abstract' => 'Test abstract',
@@ -97,6 +105,8 @@ public function testResourcesHasAttributes()
97
105
98
106
public function testResourcesWithRelationshipsMayBeConvertedToJsonApi ()
99
107
{
108
+ $ this ->bypassPolicies ();
109
+
100
110
Route::get ('/ ' , function () {
101
111
$ post = new Post ([
102
112
'id ' => 5 ,
@@ -109,7 +119,7 @@ public function testResourcesWithRelationshipsMayBeConvertedToJsonApi()
109
119
'title ' => 'Test Parent Title ' ,
110
120
]));
111
121
112
- return new JsonApiResource ($ post, true );
122
+ return JsonApi:: format ($ post );
113
123
});
114
124
115
125
$ response = $ this ->get ('/ ' , ['Accept ' => 'application/json ' ]);
@@ -147,6 +157,8 @@ public function testResourcesWithRelationshipsMayBeConvertedToJsonApi()
147
157
148
158
public function testResourcesHasRelationshipWith ()
149
159
{
160
+ $ this ->bypassPolicies ();
161
+
150
162
Route::get ('/ ' , function () {
151
163
$ post = new Post ([
152
164
'id ' => 5 ,
@@ -159,7 +171,7 @@ public function testResourcesHasRelationshipWith()
159
171
'title ' => 'Test Parent Title ' ,
160
172
]));
161
173
162
- return new JsonApiResource ($ post, true );
174
+ return JsonApi:: format ($ post );
163
175
});
164
176
165
177
$ this ->get ('/ ' , ['Accept ' => 'application/json ' ])->assertJsonApi (function (Assert $ json ) {
@@ -172,6 +184,8 @@ public function testResourcesHasRelationshipWith()
172
184
173
185
public function testResourcesAtRelationHasAttribute ()
174
186
{
187
+ $ this ->bypassPolicies ();
188
+
175
189
Route::get ('/ ' , function () {
176
190
$ post = new Post ([
177
191
'id ' => 5 ,
@@ -184,7 +198,7 @@ public function testResourcesAtRelationHasAttribute()
184
198
'title ' => 'Test Parent Title ' ,
185
199
]));
186
200
187
- return new JsonApiResource ($ post, true );
201
+ return JsonApi:: format ($ post );
188
202
});
189
203
190
204
$ this ->get ('/ ' , ['Accept ' => 'application/json ' ])->assertJsonApi (function (Assert $ json ) {
@@ -198,7 +212,7 @@ public function testResourcesAtRelationHasAttribute()
198
212
public function testResourcesMayNotBeConvertedToJsonApiWithoutPermissions ()
199
213
{
200
214
Route::get ('/ ' , function () {
201
- return new JsonApiResource (new Post ([
215
+ return JsonApi:: format (new Post ([
202
216
'id ' => 5 ,
203
217
'title ' => 'Test Title ' ,
204
218
]));
0 commit comments