Add agegroups to form meta

This commit is contained in:
philipp lang 2024-02-23 01:08:13 +01:00
parent ada03a11ea
commit b806cafc8b
3 changed files with 20 additions and 4 deletions

View File

@ -4,6 +4,7 @@ namespace App\Form\Resources;
use App\Form\Models\Form; use App\Form\Models\Form;
use App\Lib\HasMeta; use App\Lib\HasMeta;
use App\Subactivity;
use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Http\Resources\Json\JsonResource;
/** /**
@ -42,6 +43,8 @@ class FormApiResource extends JsonResource
{ {
return [ return [
'base_url' => url(''), 'base_url' => url(''),
'agegroups' => Subactivity::remote()->where('is_age_group', true)->get()
->map(fn ($subactivity) => ['id' => $subactivity->nami_id, 'name' => $subactivity->name]),
]; ];
} }
} }

View File

@ -48,9 +48,9 @@ class SubactivityFactory extends Factory
return $this->state(['nami_id' => $namiId]); return $this->state(['nami_id' => $namiId]);
} }
public function ageGroup(): self public function ageGroup(bool $ageGroup = true): self
{ {
return $this->state(['is_age_group' => true]); return $this->state(['is_age_group' => $ageGroup]);
} }
public function filterable(): self public function filterable(): self

View File

@ -2,14 +2,13 @@
namespace Tests\EndToEnd\Form; namespace Tests\EndToEnd\Form;
use App\Form\Fields\TextField;
use App\Form\Models\Form; use App\Form\Models\Form;
use App\Form\Models\Formtemplate; use App\Form\Models\Formtemplate;
use App\Subactivity;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Tests\EndToEndTestCase; use Tests\EndToEndTestCase;
use Tests\Feature\Form\FormtemplateFieldRequest;
use Tests\Feature\Form\FormtemplateSectionRequest; use Tests\Feature\Form\FormtemplateSectionRequest;
class FormApiListActionTest extends EndToEndTestCase class FormApiListActionTest extends EndToEndTestCase
@ -47,9 +46,23 @@ class FormApiListActionTest extends EndToEndTestCase
->assertJsonPath('data.0.from_human', '05.05.2023') ->assertJsonPath('data.0.from_human', '05.05.2023')
->assertJsonPath('data.0.to_human', '07.06.2023') ->assertJsonPath('data.0.to_human', '07.06.2023')
->assertJsonPath('meta.per_page', 15) ->assertJsonPath('meta.per_page', 15)
->assertJsonPath('meta.base_url', url(''))
->assertJsonPath('meta.total', 1); ->assertJsonPath('meta.total', 1);
} }
public function testItDisplaysRemoteGroups(): void
{
$this->loginNami()->withoutExceptionHandling();
Subactivity::factory()->inNami(1)->name('Wölfling')->ageGroup(true)->create();
Subactivity::factory()->inNami(50)->name('Biber')->ageGroup(false)->create();
Subactivity::factory()->name('Lager')->ageGroup(true)->create();
sleep(1);
$this->get('/api/form?perPage=15')
->assertJsonPath('meta.agegroups.0', ['id' => 1, 'name' => 'Wölfling'])
->assertJsonCount(1, 'meta.agegroups');
}
public function testItDisplaysDailyForms(): void public function testItDisplaysDailyForms(): void
{ {
Carbon::setTestNow(Carbon::parse('2023-03-02')); Carbon::setTestNow(Carbon::parse('2023-03-02'));