44
55use App \Models \Post ;
66use RonasIT \Support \Tests \ModelTestState ;
7- use RonasIT \Support \Traits \AuthTestTrait ;
87
98class NovaPostTest extends TestCase
109{
11- use AuthTestTrait;
12-
13- protected static $ user ;
14- protected static $ postState ;
10+ protected static User $ user ;
11+ protected static ModelTestState $ postState ;
1512
1613 public function setUp (): void
1714 {
1815 parent ::setUp ();
1916
20- self ::$ user = 1 ;
17+ self ::$ user = User:: find ( 1 ) ;
2118 self ::$ postState ??= new ModelTestState (Post::class);
2219
2320 $ this ->skipDocumentationCollecting ();
@@ -27,7 +24,7 @@ public function testCreate(): void
2724 {
2825 $ data = $ this ->getJsonFixture ('create_post_request.json ' );
2926
30- $ response = $ this ->actingViaSession (self ::$ user )->json ('post ' , '/nova-api/posts ' , $ data );
27+ $ response = $ this ->actingAs (self ::$ user, ' web ' )->json ('post ' , '/nova-api/post-resources ' , $ data );
3128
3229 $ response ->assertCreated ();
3330
@@ -41,7 +38,7 @@ public function testCreateNoAuth(): void
4138 {
4239 $ data = $ this ->getJsonFixture ('create_post_request.json ' );
4340
44- $ response = $ this ->json ('post ' , '/nova-api/posts ' , $ data );
41+ $ response = $ this ->json ('post ' , '/nova-api/post-resources ' , $ data );
4542
4643 $ response ->assertUnauthorized ();
4744
@@ -50,7 +47,7 @@ public function testCreateNoAuth(): void
5047
5148 public function testCreateValidationError (): void
5249 {
53- $ response = $ this ->actingViaSession (self ::$ user )->json ('post ' , '/nova-api/posts ' );
50+ $ response = $ this ->actingAs (self ::$ user, ' web ' )->json ('post ' , '/nova-api/post-resources ' );
5451
5552 $ response ->assertUnprocessable ();
5653
@@ -64,7 +61,7 @@ public function testUpdate(): void
6461 {
6562 $ data = $ this ->getJsonFixture ('update_post_request.json ' );
6663
67- $ response = $ this ->actingViaSession (self ::$ user )->json ('put ' , '/nova-api/posts /1 ' , $ data );
64+ $ response = $ this ->actingAs (self ::$ user, ' web ' )->json ('put ' , '/nova-api/post-resources /1 ' , $ data );
6865
6966 $ response ->assertNoContent ();
7067
@@ -76,7 +73,7 @@ public function testUpdateNotExists(): void
7673 {
7774 $ data = $ this ->getJsonFixture ('update_post_request.json ' );
7875
79- $ response = $ this ->actingViaSession (self ::$ user )->json ('put ' , '/nova-api/posts /0 ' , $ data );
76+ $ response = $ this ->actingAs (self ::$ user, ' web ' )->json ('put ' , '/nova-api/post-resources /0 ' , $ data );
8077
8178 $ response ->assertNotFound ();
8279 }
@@ -85,14 +82,14 @@ public function testUpdateNoAuth(): void
8582 {
8683 $ data = $ this ->getJsonFixture ('update_post_request.json ' );
8784
88- $ response = $ this ->json ('put ' , '/nova-api/posts /1 ' , $ data );
85+ $ response = $ this ->json ('put ' , '/nova-api/post-resources /1 ' , $ data );
8986
9087 $ response ->assertUnauthorized ();
9188 }
9289
9390 public function testUpdateValidationError (): void
9491 {
95- $ response = $ this ->actingViaSession (self ::$ user )->json ('put ' , '/nova-api/posts /4 ' );
92+ $ response = $ this ->actingAs (self ::$ user, ' web ' )->json ('put ' , '/nova-api/post-resources /4 ' );
9693
9794 $ response ->assertUnprocessable ();
9895
@@ -102,7 +99,7 @@ public function testUpdateValidationError(): void
10299
103100 public function testGetUpdatableFields (): void
104101 {
105- $ response = $ this ->actingViaSession (self ::$ user )->json ('get ' , '/nova-api/posts /1/update-fields ' );
102+ $ response = $ this ->actingAs (self ::$ user, ' web ' )->json ('get ' , '/nova-api/post-resources /1/update-fields ' );
106103
107104 $ response ->assertOk ();
108105
@@ -112,7 +109,7 @@ public function testGetUpdatableFields(): void
112109
113110 public function testDelete (): void
114111 {
115- $ response = $ this ->actingViaSession (self ::$ user )->json ('delete ' , '/nova-api/posts ' , [
112+ $ response = $ this ->actingAs (self ::$ user, ' web ' )->json ('delete ' , '/nova-api/post-resources ' , [
116113 'resources ' => [1 , 2 ]
117114 ]);
118115
@@ -124,7 +121,7 @@ public function testDelete(): void
124121
125122 public function testDeleteNotExists (): void
126123 {
127- $ response = $ this ->actingViaSession (self ::$ user )->json ('delete ' , '/nova-api/posts ' , [
124+ $ response = $ this ->actingAs (self ::$ user, ' web ' )->json ('delete ' , '/nova-api/post-resources ' , [
128125 'resources ' => [0 ]
129126 ]);
130127
@@ -133,7 +130,7 @@ public function testDeleteNotExists(): void
133130
134131 public function testDeleteNoAuth (): void
135132 {
136- $ response = $ this ->json ('delete ' , '/nova-api/posts ' , [
133+ $ response = $ this ->json ('delete ' , '/nova-api/post-resources ' , [
137134 'resources ' => [1 , 2 ]
138135 ]);
139136
@@ -142,7 +139,7 @@ public function testDeleteNoAuth(): void
142139
143140 public function testGet (): void
144141 {
145- $ response = $ this ->actingViaSession (self ::$ user )->json ('get ' , '/nova-api/posts /1 ' );
142+ $ response = $ this ->actingAs (self ::$ user, ' web ' )->json ('get ' , '/nova-api/post-resources /1 ' );
146143
147144 $ response ->assertOk ();
148145
@@ -152,21 +149,21 @@ public function testGet(): void
152149
153150 public function testGetNotExists (): void
154151 {
155- $ response = $ this ->actingViaSession (self ::$ user )->json ('get ' , '/nova-api/posts /0 ' );
152+ $ response = $ this ->actingAs (self ::$ user, ' web ' )->json ('get ' , '/nova-api/post-resources /0 ' );
156153
157154 $ response ->assertNotFound ();
158155 }
159156
160157 public function testGetNoAuth (): void
161158 {
162- $ response = $ this ->json ('get ' , '/nova-api/posts /1 ' );
159+ $ response = $ this ->json ('get ' , '/nova-api/post-resources /1 ' );
163160
164161 $ response ->assertUnauthorized ();
165162 }
166163
167164 public function testSearchUnauthorized (): void
168165 {
169- $ response = $ this ->json ('get ' , '/nova-api/posts ' , [
166+ $ response = $ this ->json ('get ' , '/nova-api/post-resources ' , [
170167 'orderBy ' => 'id ' ,
171168 'orderByDirection ' => 'asc '
172169 ]);
@@ -176,7 +173,7 @@ public function testSearchUnauthorized(): void
176173
177174 public function testGetFieldsVisibleOnCreate (): void
178175 {
179- $ response = $ this ->actingViaSession (self ::$ user )->json ('get ' , '/nova-api/posts /creation-fields ' );
176+ $ response = $ this ->actingAs (self ::$ user, ' web ' )->json ('get ' , '/nova-api/post-resources /creation-fields ' );
180177
181178 $ response ->assertOk ();
182179
@@ -209,8 +206,7 @@ public function getRunPostActionsData(): array
209206 */
210207 public function testRunPostActions ($ action , $ request , $ postsStateFixture ): void
211208 {
212- $ request ['action ' ] = $ action ;
213- $ response = $ this ->actingViaSession (self ::$ user )->json ('post ' , "/nova-api/posts/action " , $ request );
209+ $ response = $ this ->actingAs (self ::$ user , 'web ' )->json ('post ' , "/nova-api/post-resources/action?action= {$ action }" , $ request );
214210
215211 $ response ->assertOk ();
216212
@@ -243,7 +239,7 @@ public function getPostActionsData(): array
243239 */
244240 public function testGetPostActions (array $ request , string $ responseFixture ): void
245241 {
246- $ response = $ this ->actingViaSession (self ::$ user )->json ('get ' , '/nova-api/posts /actions ' , $ request );
242+ $ response = $ this ->actingAs (self ::$ user, ' web ' )->json ('get ' , '/nova-api/post-resources /actions ' , $ request );
247243
248244 $ response ->assertOk ();
249245
@@ -274,7 +270,7 @@ public function getPostFiltersData(): array
274270 */
275271 public function testFilterPost (array $ filters , string $ responseFixture ): void
276272 {
277- $ response = $ this ->actingViaSession (self ::$ user )->json ('get ' , '/nova-api/posts ' , [
273+ $ response = $ this ->actingAs (self ::$ user, ' web ' )->json ('get ' , '/nova-api/post-resources ' , [
278274 'filters ' => base64_encode (json_encode ($ filters ))
279275 ]);
280276
0 commit comments