@@ -14,7 +14,8 @@ class PonudaTest extends TestCase
1414{
1515 use RefreshDatabase;
1616
17- // Pomoćna metoda koja pravi auth header (Bearer token) za korisnika sa datom ulogom (bez factory-ja)
17+ private ?User $ authUser = null ;
18+
1819 private function authHeader (string $ uloga = 'agent ' ): array
1920 {
2021 $ user = User::create ([
@@ -25,6 +26,8 @@ private function authHeader(string $uloga = 'agent'): array
2526 'uloga ' => $ uloga ,
2627 ]);
2728
29+ $ this ->authUser = $ user ;
30+
2831 $ token = $ user ->createToken ('test-token ' )->plainTextToken ;
2932
3033 return [
@@ -33,7 +36,6 @@ private function authHeader(string $uloga = 'agent'): array
3336 ];
3437 }
3538
36- // Pomoćna metoda koja kreira kupca i nekretninu da bi store validacija (exists) prošla
3739 private function seedKupacINekretnina (): array
3840 {
3941 $ kupac = Kupac::create ([
@@ -57,7 +59,6 @@ private function seedKupacINekretnina(): array
5759 return [$ kupac , $ nekretnina ];
5860 }
5961
60- // Test da index vraća listu ponuda (za prijavljenog korisnika)
6162 public function test_index_returns_list_of_ponude ()
6263 {
6364 $ headers = $ this ->authHeader ('agent ' );
@@ -68,8 +69,7 @@ public function test_index_returns_list_of_ponude()
6869 'nekretnina_id ' => $ nekretnina ->id ,
6970 'iznos ' => 95000 ,
7071 'status ' => 'u_toku ' ,
71- 'napomena ' => 'Ponuda 1 ' ,
72- 'korisnik_id ' => 1 ,
72+ 'korisnik_id ' => $ this ->authUser ->id ,
7373 'datum ' => '2026-02-01 ' ,
7474 ]);
7575
@@ -78,8 +78,7 @@ public function test_index_returns_list_of_ponude()
7878 'nekretnina_id ' => $ nekretnina ->id ,
7979 'iznos ' => 97000 ,
8080 'status ' => 'prihvacena ' ,
81- 'napomena ' => 'Ponuda 2 ' ,
82- 'korisnik_id ' => 1 ,
81+ 'korisnik_id ' => $ this ->authUser ->id ,
8382 'datum ' => '2026-02-02 ' ,
8483 ]);
8584
@@ -89,7 +88,6 @@ public function test_index_returns_list_of_ponude()
8988 ->assertJsonCount (2 );
9089 }
9190
92- // Test da show vraća ponudu kada postoji
9391 public function test_show_returns_single_ponuda_when_exists ()
9492 {
9593 $ headers = $ this ->authHeader ('agent ' );
@@ -100,8 +98,7 @@ public function test_show_returns_single_ponuda_when_exists()
10098 'nekretnina_id ' => $ nekretnina ->id ,
10199 'iznos ' => 99000 ,
102100 'status ' => 'u_toku ' ,
103- 'napomena ' => 'Test ponuda ' ,
104- 'korisnik_id ' => 1 ,
101+ 'korisnik_id ' => $ this ->authUser ->id ,
105102 'datum ' => '2026-02-03 ' ,
106103 ]);
107104
@@ -116,7 +113,6 @@ public function test_show_returns_single_ponuda_when_exists()
116113 ]);
117114 }
118115
119- // Test da show vraća 404 kada ponuda ne postoji
120116 public function test_show_returns_404_when_not_found ()
121117 {
122118 $ headers = $ this ->authHeader ('agent ' );
@@ -129,7 +125,6 @@ public function test_show_returns_404_when_not_found()
129125 ]);
130126 }
131127
132- // Test da store vraća 422 kada validacija ne prođe (npr. nema datum)
133128 public function test_store_returns_422_on_validation_error ()
134129 {
135130 $ headers = $ this ->authHeader ('agent ' );
@@ -145,7 +140,6 @@ public function test_store_returns_422_on_validation_error()
145140 ->assertJsonStructure (['errors ' ]);
146141 }
147142
148- // Test da guest ne može da kreira ponudu jer su rute zaštićene auth:sanctum
149143 public function test_guest_cannot_store_ponuda ()
150144 {
151145 $ response = $ this ->postJson ('/api/ponude ' , [
@@ -158,7 +152,6 @@ public function test_guest_cannot_store_ponuda()
158152 $ response ->assertStatus (401 );
159153 }
160154
161- // Test da update vraća 404 kada ponuda ne postoji
162155 public function test_update_returns_404_when_not_found ()
163156 {
164157 $ headers = $ this ->authHeader ('agent ' );
@@ -173,7 +166,6 @@ public function test_update_returns_404_when_not_found()
173166 ]);
174167 }
175168
176- // Test da update vraća 422 kada validacija ne prođe (npr. cena negativna)
177169 public function test_update_returns_422_on_validation_error ()
178170 {
179171 $ headers = $ this ->authHeader ('agent ' );
@@ -184,8 +176,7 @@ public function test_update_returns_422_on_validation_error()
184176 'nekretnina_id ' => $ nekretnina ->id ,
185177 'iznos ' => 90000 ,
186178 'status ' => 'u_toku ' ,
187- 'napomena ' => null ,
188- 'korisnik_id ' => 1 ,
179+ 'korisnik_id ' => $ this ->authUser ->id ,
189180 'datum ' => '2026-02-05 ' ,
190181 ]);
191182
@@ -197,7 +188,6 @@ public function test_update_returns_422_on_validation_error()
197188 ->assertJsonStructure (['errors ' ]);
198189 }
199190
200- // Test da destroy briše ponudu i vraća poruku o brisanju
201191 public function test_destroy_deletes_ponuda ()
202192 {
203193 $ headers = $ this ->authHeader ('agent ' );
@@ -208,8 +198,7 @@ public function test_destroy_deletes_ponuda()
208198 'nekretnina_id ' => $ nekretnina ->id ,
209199 'iznos ' => 91000 ,
210200 'status ' => 'u_toku ' ,
211- 'napomena ' => 'Brisanje ' ,
212- 'korisnik_id ' => 1 ,
201+ 'korisnik_id ' => $ this ->authUser ->id ,
213202 'datum ' => '2026-02-06 ' ,
214203 ]);
215204
@@ -225,7 +214,6 @@ public function test_destroy_deletes_ponuda()
225214 ]);
226215 }
227216
228- // Test da destroy vraća 404 kada ponuda ne postoji
229217 public function test_destroy_returns_404_when_not_found ()
230218 {
231219 $ headers = $ this ->authHeader ('agent ' );
@@ -238,7 +226,6 @@ public function test_destroy_returns_404_when_not_found()
238226 ]);
239227 }
240228
241- // Test da search vraća 422 kada proslediš nevalidan sort_by parametar
242229 public function test_search_returns_422_on_invalid_sort_by ()
243230 {
244231 $ headers = $ this ->authHeader ('agent ' );
0 commit comments