diff --git a/app/Form/Models/Form.php b/app/Form/Models/Form.php index 21096be5..d42bb451 100644 --- a/app/Form/Models/Form.php +++ b/app/Form/Models/Form.php @@ -204,18 +204,6 @@ class Form extends Model implements HasMedia public function canRegister(): bool { - if (!$this->is_active) { - return false; - } - - if ($this->registration_from && $this->registration_from->gt(now())) { - return false; - } - - if ($this->registration_until && $this->registration_until->lt(now())) { - return false; - } - - return true; + return $this->is_active && $this->isInDates(); } } diff --git a/tests/EndToEnd/Form/FormIndexActionTest.php b/tests/EndToEnd/Form/FormIndexActionTest.php index cd63b410..90156f10 100644 --- a/tests/EndToEnd/Form/FormIndexActionTest.php +++ b/tests/EndToEnd/Form/FormIndexActionTest.php @@ -183,6 +183,22 @@ it('testItDoesntReturnInactiveForms', function () { $this->callFilter('form.index', ['inactive' => false])->assertInertiaCount('data.data', 2); }); +it('returns in dates', function () { + $this->withoutExceptionHandling()->login()->loginNami(); + Form::factory()->create(); + + sleep(1); + $this->callFilter('form.index', [])->assertInertiaPath('data.data.0.is_in_dates', true); +}); + +it('returns not in dates', function () { + $this->withoutExceptionHandling()->login()->loginNami(); + Form::factory()->registrationFrom(now()->addDay(2))->create(); + + sleep(1); + $this->callFilter('form.index', [])->assertInertiaPath('data.data.0.is_in_dates', false); +}); + it('testItOrdersByStartDateDesc', function () { $this->withoutExceptionHandling()->login()->loginNami(); $form1 = Form::factory()->from(now()->addDays(4))->to(now()->addYear())->create();