22
22
use App \Models \Tag ;
23
23
use App \Models \Video ;
24
24
use App \Tests \Api \V1 \TestCase ;
25
- use App \Models \User ;
26
25
use Illuminate \Database \Eloquent \Collection as EloquentCollection ;
27
26
use LaravelJsonApi \Core \Document \ResourceObject ;
28
27
@@ -54,7 +53,7 @@ public function test(): void
54
53
55
54
$ response = $ this
56
55
->withoutExceptionHandling ()
57
- ->actingAs ($ user = User:: factory ()-> create () )
56
+ ->actingAs ($ user = $ video -> owner )
58
57
->jsonApi ('videos ' )
59
58
->withData ($ data )
60
59
->post ('/api/v1/videos ' );
@@ -96,7 +95,7 @@ public function testClientId(): void
96
95
97
96
$ response = $ this
98
97
->withoutExceptionHandling ()
99
- ->actingAs (User:: factory ()-> create () )
98
+ ->actingAs ($ video -> owner )
100
99
->jsonApi ('videos ' )
101
100
->withData ($ data )
102
101
->post ('/api/v1/videos ' );
@@ -112,6 +111,29 @@ public function testClientId(): void
112
111
$ this ->assertDatabaseCount ('taggables ' , 2 );
113
112
}
114
113
114
+ public function testClientIdAlreadyExists (): void
115
+ {
116
+ $ video = Video::factory ()->make ();
117
+ $ existing = Video::factory ()->create ();
118
+
119
+ $ data = $ this
120
+ ->serialize ($ video )
121
+ ->withId ($ id = $ existing ->getRouteKey ());
122
+
123
+ $ response = $ this
124
+ ->actingAs ($ video ->owner )
125
+ ->jsonApi ('videos ' )
126
+ ->withData ($ data )
127
+ ->post ('/api/v1/videos ' );
128
+
129
+ $ response ->assertExactErrorStatus ([
130
+ 'detail ' => "Resource {$ id } already exists. " ,
131
+ 'source ' => ['pointer ' => '/data/id ' ],
132
+ 'status ' => '409 ' ,
133
+ 'title ' => 'Conflict ' ,
134
+ ]);
135
+ }
136
+
115
137
public function testInvalidClientId (): void
116
138
{
117
139
$ video = Video::factory ()->make ();
@@ -121,7 +143,7 @@ public function testInvalidClientId(): void
121
143
->withId ('123456 ' );
122
144
123
145
$ response = $ this
124
- ->actingAs (User:: factory ()-> create () )
146
+ ->actingAs ($ video -> owner )
125
147
->jsonApi ('videos ' )
126
148
->withData ($ data )
127
149
->post ('/api/v1/videos ' );
0 commit comments