diff --git a/tests/Feature/ExportControllerTest.php b/tests/Feature/ExportControllerTest.php new file mode 100644 index 0000000000000000000000000000000000000000..38b579849e32a6b8ef95bb8bb4fbf8fb680a46af --- /dev/null +++ b/tests/Feature/ExportControllerTest.php @@ -0,0 +1,49 @@ +<?php + +namespace Tests\Feature; + +use App\Models\User; +use Illuminate\Contracts\Auth\Authenticatable; +use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Testing\TestResponse; +use Tests\TestCase; + +class ExportControllerTest extends TestCase +{ + use RefreshDatabase; + + /** + * Test organizations export. + */ + public function testExportOrganizations(): void + { + /** @var Authenticatable $user */ + $user = User::with('organization')->first(); + $response = $this->actingAs($user)->get(route('export.organizations', ['ext' => 'json'])); + $this->_testJsonExportResponse($response); + } + + /** + * Test evaluations export. + */ + public function testExportEvaluations(): void + { + /** @var Authenticatable $user */ + $user = User::with('organization')->first(); + $response = $this->actingAs($user)->get(route('export.evaluations', ['ext' => 'json'])); + $this->_testJsonExportResponse($response); + } + + private function _testJsonExportResponse(TestResponse $response): void + { + if ($response->exception) { + dump($response->exception); + } + $response->assertOk(); + + $content = $response->json(); + self::assertGreaterThan(0, count($content['header'])); + self::assertGreaterThan(0, count($content['rows'])); + self::assertSameSize($content['header'], $content['rows'][0]); + } +}