Last active
August 26, 2021 19:02
-
-
Save nicklleite/2bbc1272e33faec1b1d093caeedcf513 to your computer and use it in GitHub Desktop.
Feature Test | Valid json structure from paginated data - #laravel/tests
This file contains hidden or 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
<?php | |
/** | |
* The company model is just an exemple. | |
*/ | |
namespace Tests\Feature; | |
use Illuminate\Testing\Fluent\AssertableJson; | |
use Tests\TestCase; | |
use App\Models\Company; | |
class CompanyTest extends TestCase { | |
/** @test */ | |
public function test_companies_json_structure_with_no_data() { | |
$response = $this->getJson($this->endpoint)->assertJsonStructure([ | |
'data' => [], | |
'links' => [ | |
"first", | |
"last", | |
"prev", | |
"next", | |
], | |
'meta' => [ | |
"current_page", | |
"from", | |
"path", | |
"per_page", | |
"to", | |
], | |
]); | |
} | |
/** @test */ | |
public function test_companies_json_structure_with_data() { | |
// Create 25 Companies in the database | |
Company::factory()->count(25)->create(); | |
// Get all Comapnies (Paginated) | |
$response = $this->getJson($this->endpoint)->assertJsonStructure([ | |
'data' => [ | |
'*' => [ | |
"access_token", | |
"company_name", | |
"trading_name", | |
"employer_identification_number", | |
"created_at", | |
] | |
], | |
'links' => [ | |
"first", | |
"last", | |
"prev", | |
"next", | |
], | |
'meta' => [ | |
"current_page", | |
"from", | |
"path", | |
"per_page", | |
"to", | |
], | |
]); | |
} | |
} | |
// EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment