-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #917 from w3bdesign/dev
Test the /api/products endpoint with PHPunit
- Loading branch information
Showing
4 changed files
with
41 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Tests\Unit; | ||
|
||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Tests\TestCase; | ||
use App\Models\Product; | ||
|
||
class ProductTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
/** | ||
* Test the /api/products endpoint. | ||
* | ||
* This test sends a GET request to the /api/products endpoint and checks if | ||
* the response has a 200 status code and contains the correct product data. | ||
* | ||
* @return void | ||
*/ | ||
public function testApiProductsEndpoint() | ||
{ | ||
// Create a sample product | ||
$product = Product::factory()->create(); | ||
|
||
// Send a GET request to the /api/products endpoint | ||
$response = $this->get('/api/products'); | ||
|
||
// Check that the response has a 200 status code | ||
$response->assertStatus(200); | ||
|
||
// Check that the response contains the sample product data | ||
$response->assertJsonPath('0.id', $product->id); | ||
$response->assertJsonPath('0.name', $product->name); | ||
$response->assertJsonPath('0.imageUrl', $product->imageUrl); | ||
$response->assertJsonPath('0.slug', $product->slug); | ||
$response->assertJsonPath('0.price', $product->price); | ||
} | ||
} |