15
15
* limitations under the License.
16
16
*/
17
17
18
- namespace CloudCreativity \LaravelJsonApi \Tests \Integration ;
18
+ namespace CloudCreativity \LaravelJsonApi \Tests \Integration \ Routing ;
19
19
20
+ use CloudCreativity \LaravelJsonApi \Routing \RouteRegistrar ;
21
+ use CloudCreativity \LaravelJsonApi \Tests \Integration \TestCase ;
20
22
use DummyApp \Post ;
21
23
use DummyApp \User ;
22
- use Illuminate \Support \Facades \Route ;
23
24
24
25
/**
25
26
* Class SubDomainTest
@@ -38,24 +39,43 @@ class SubDomainTest extends TestCase
38
39
*/
39
40
protected $ resourceType = 'posts ' ;
40
41
42
+ /**
43
+ * @var bool
44
+ */
45
+ protected $ appRoutes = false ;
46
+
47
+ /**
48
+ * @return void
49
+ */
50
+ protected function setUp (): void
51
+ {
52
+ parent ::setUp ();
53
+
54
+ $ this ->withFluentRoutes ()->domain ('{wildcard}.example.com ' )->routes (function (RouteRegistrar $ api ) {
55
+ $ api ->resource ('posts ' )->relationships (function ($ relations ) {
56
+ $ relations ->hasOne ('author ' );
57
+ });
58
+ });
59
+ }
60
+
41
61
public function testRead ()
42
62
{
43
63
$ post = factory (Post::class)->create ();
44
- $ uri = route ( ' api:v1: posts.read ' , [ ' foo ' , $ post]) ;
64
+ $ uri = " http://foo.example.com/api/v1/ posts/ { $ post-> getRouteKey ()}" ;
45
65
46
66
$ this ->getJsonApi ($ uri )->assertFetchedOne ([
47
67
'type ' => 'posts ' ,
48
68
'id ' => (string ) $ post ->getRouteKey (),
49
69
'links ' => [
50
- 'self ' => " http://foo.example.com/api/v1/posts/ { $ post -> getRouteKey ()}" ,
70
+ 'self ' => $ uri ,
51
71
],
52
72
]);
53
73
}
54
74
55
75
public function testUpdate ()
56
76
{
57
77
$ post = factory (Post::class)->create ();
58
- $ uri = route ( ' api:v1: posts.update ' , [ ' foo ' , $ post]) ;
78
+ $ uri = " http://foo.example.com/api/v1/ posts/ { $ post-> getRouteKey ()}" ;
59
79
60
80
$ data = [
61
81
'type ' => 'posts ' ,
@@ -71,23 +91,23 @@ public function testUpdate()
71
91
public function testDelete ()
72
92
{
73
93
$ post = factory (Post::class)->create ();
74
- $ uri = route ( ' api:v1: posts.delete ' , [ ' foo ' , $ post]) ;
94
+ $ uri = " http://foo.example.com/api/v1/ posts/ { $ post-> getRouteKey ()}" ;
75
95
76
96
$ this ->deleteJsonApi ($ uri )->assertStatus (204 );
77
97
}
78
98
79
99
public function testReadRelated ()
80
100
{
81
101
$ post = factory (Post::class)->create ();
82
- $ uri = route ( ' api:v1:posts.relationships.author ' , [ ' foo ' , $ post]) ;
102
+ $ uri = " http://foo.example.com/api/v1/posts/ { $ post-> getRouteKey ()} /author " ;
83
103
84
104
$ this ->getJsonApi ($ uri )->assertStatus (200 );
85
105
}
86
106
87
107
public function testReadRelationship ()
88
108
{
89
109
$ post = factory (Post::class)->create ();
90
- $ uri = route ( ' api:v1:posts.relationships.author.read ' , [ ' foo ' , $ post]) ;
110
+ $ uri = " http://foo.example.com/api/v1/posts/ { $ post-> getRouteKey ()} /relationships/author " ;
91
111
92
112
$ this ->getJsonApi ($ uri )->assertStatus (200 );
93
113
}
@@ -96,7 +116,7 @@ public function testReplaceRelationship()
96
116
{
97
117
$ post = factory (Post::class)->create ();
98
118
$ user = factory (User::class)->create ();
99
- $ uri = route ( ' api:v1:posts.relationships.author.replace ' , [ ' foo ' , $ post]) ;
119
+ $ uri = " http://foo.example.com/api/v1/posts/ { $ post-> getRouteKey ()} /relationships/author " ;
100
120
101
121
$ data = [
102
122
'type ' => 'users ' ,
@@ -106,15 +126,4 @@ public function testReplaceRelationship()
106
126
$ this ->patchJsonApi ($ uri , [], compact ('data ' ))->assertStatus (204 );
107
127
}
108
128
109
- /**
110
- * @return $this|void
111
- */
112
- protected function withAppRoutes ()
113
- {
114
- Route::group ([
115
- 'domain ' => '{wildcard}.example.com ' ,
116
- ], function () {
117
- parent ::withAppRoutes ();
118
- });
119
- }
120
129
}
0 commit comments