File tree Expand file tree Collapse file tree 3 files changed +40
-18
lines changed Expand file tree Collapse file tree 3 files changed +40
-18
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ public function definition()
3131 'slug ' => Str::slug ($ name ),
3232 'description ' => $ this ->faker ->realText (320 ),
3333 'price ' => $ this ->faker ->numberBetween (100 , 1000 ),
34+ 'imageUrl ' => $ this ->faker ->imageUrl (400 , 400 ),
3435 ];
3536 }
3637}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Tests \Unit ;
4+
5+ use Illuminate \Foundation \Testing \RefreshDatabase ;
6+ use Tests \TestCase ;
7+ use App \Models \Product ;
8+
9+ class ProductTest extends TestCase
10+ {
11+ use RefreshDatabase;
12+
13+ /**
14+ * Test the /api/products endpoint.
15+ *
16+ * This test sends a GET request to the /api/products endpoint and checks if
17+ * the response has a 200 status code and contains the correct product data.
18+ *
19+ * @return void
20+ */
21+ public function testApiProductsEndpoint ()
22+ {
23+ // Create a sample product
24+ $ product = Product::factory ()->create ();
25+
26+ // Send a GET request to the /api/products endpoint
27+ $ response = $ this ->get ('/api/products ' );
28+
29+ // Check that the response has a 200 status code
30+ $ response ->assertStatus (200 );
31+
32+ // Check that the response contains the sample product data
33+ $ response ->assertJsonPath ('0.id ' , $ product ->id );
34+ $ response ->assertJsonPath ('0.name ' , $ product ->name );
35+ $ response ->assertJsonPath ('0.imageUrl ' , $ product ->imageUrl );
36+ $ response ->assertJsonPath ('0.slug ' , $ product ->slug );
37+ $ response ->assertJsonPath ('0.price ' , $ product ->price );
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments