From fca0d92528a098640fcbbc171e7663aba1979596 Mon Sep 17 00:00:00 2001 From: Damien Labat <labat@datakode.fr> Date: Tue, 8 Nov 2022 14:21:21 +0100 Subject: [PATCH] test: Add export evaluation & organizations features tests --- tests/Feature/ExportControllerTest.php | 49 ++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/Feature/ExportControllerTest.php diff --git a/tests/Feature/ExportControllerTest.php b/tests/Feature/ExportControllerTest.php new file mode 100644 index 00000000..38b57984 --- /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]); + } +} -- GitLab