Add registration_from and registration_until to frontend api
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
3e563f8390
commit
57b1efb065
|
@ -7,6 +7,7 @@ use App\Form\Models\Form;
|
||||||
use App\Form\Models\Participant;
|
use App\Form\Models\Participant;
|
||||||
use App\Member\Member;
|
use App\Member\Member;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
use Lorisleiva\Actions\ActionRequest;
|
use Lorisleiva\Actions\ActionRequest;
|
||||||
use Lorisleiva\Actions\Concerns\AsAction;
|
use Lorisleiva\Actions\Concerns\AsAction;
|
||||||
|
|
||||||
|
@ -19,6 +20,10 @@ class RegisterAction
|
||||||
*/
|
*/
|
||||||
public function handle(Form $form, array $input): Participant
|
public function handle(Form $form, array $input): Participant
|
||||||
{
|
{
|
||||||
|
if (!$form->canRegister()) {
|
||||||
|
throw ValidationException::withMessages(['event' => 'Anmeldung zzt nicht möglich.']);
|
||||||
|
}
|
||||||
|
|
||||||
$memberQuery = FieldCollection::fromRequest($form, $input)
|
$memberQuery = FieldCollection::fromRequest($form, $input)
|
||||||
->withNamiType()
|
->withNamiType()
|
||||||
->reduce(fn ($query, $field) => $field->namiType->performQuery($query, $field->value), (new Member())->newQuery());
|
->reduce(fn ($query, $field) => $field->namiType->performQuery($query, $field->value), (new Member())->newQuery());
|
||||||
|
|
|
@ -188,4 +188,17 @@ class Form extends Model implements HasMedia
|
||||||
{
|
{
|
||||||
return Sorting::from($this->meta['sorting']);
|
return Sorting::from($this->meta['sorting']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function canRegister(): bool
|
||||||
|
{
|
||||||
|
if ($this->registration_from && $this->registration_from->gt(now())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->registration_until && $this->registration_until->lt(now())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ class FormApiResource extends JsonResource
|
||||||
'image' => $this->getMedia('headerImage')->first()->getFullUrl('square'),
|
'image' => $this->getMedia('headerImage')->first()->getFullUrl('square'),
|
||||||
'is_active' => $this->is_active,
|
'is_active' => $this->is_active,
|
||||||
'is_private' => $this->is_private,
|
'is_private' => $this->is_private,
|
||||||
|
'can_register' => $this->getModel()->canRegister(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ use App\Form\Models\Form;
|
||||||
use App\Lib\Editor\Condition;
|
use App\Lib\Editor\Condition;
|
||||||
use Database\Factories\Traits\FakesMedia;
|
use Database\Factories\Traits\FakesMedia;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
use Tests\Feature\Form\FormtemplateFieldRequest;
|
use Tests\Feature\Form\FormtemplateFieldRequest;
|
||||||
use Tests\Feature\Form\FormtemplateSectionRequest;
|
use Tests\Feature\Form\FormtemplateSectionRequest;
|
||||||
use Tests\RequestFactories\EditorRequestFactory;
|
use Tests\RequestFactories\EditorRequestFactory;
|
||||||
|
@ -48,8 +49,8 @@ class FormFactory extends Factory
|
||||||
'config' => ['sections' => []],
|
'config' => ['sections' => []],
|
||||||
'from' => $this->faker->dateTimeBetween('+1 week', '+4 weeks')->format('Y-m-d H:i:s'),
|
'from' => $this->faker->dateTimeBetween('+1 week', '+4 weeks')->format('Y-m-d H:i:s'),
|
||||||
'to' => $this->faker->dateTimeBetween('+1 week', '+4 weeks')->format('Y-m-d H:i:s'),
|
'to' => $this->faker->dateTimeBetween('+1 week', '+4 weeks')->format('Y-m-d H:i:s'),
|
||||||
'registration_from' => $this->faker->dateTimeBetween('-2 weeks', 'now')->format('Y-m-d H:i:s'),
|
'registration_from' => $this->faker->dateTimeBetween(Carbon::parse('-2 weeks'), now())->format('Y-m-d H:i:s'),
|
||||||
'registration_until' => $this->faker->dateTimeBetween('now', '+2 weeks')->format('Y-m-d H:i:s'),
|
'registration_until' => $this->faker->dateTimeBetween(now(), Carbon::parse('+2 weeks'))->format('Y-m-d H:i:s'),
|
||||||
'mail_top' => EditorRequestFactory::new()->toData(),
|
'mail_top' => EditorRequestFactory::new()->toData(),
|
||||||
'mail_bottom' => EditorRequestFactory::new()->toData(),
|
'mail_bottom' => EditorRequestFactory::new()->toData(),
|
||||||
'is_active' => true,
|
'is_active' => true,
|
||||||
|
|
|
@ -3,14 +3,12 @@
|
||||||
namespace Tests\EndToEnd\Form;
|
namespace Tests\EndToEnd\Form;
|
||||||
|
|
||||||
use App\Form\Models\Form;
|
use App\Form\Models\Form;
|
||||||
use App\Membership\TestersBlock;
|
|
||||||
use App\Subactivity;
|
use App\Subactivity;
|
||||||
use Carbon\Carbon;
|
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Tests\Feature\Form\FormtemplateSectionRequest;
|
use Tests\Feature\Form\FormtemplateSectionRequest;
|
||||||
use Tests\RequestFactories\EditorRequestFactory;
|
use Tests\RequestFactories\EditorRequestFactory;
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
uses(FormTestCase::class);
|
uses(FormTestCase::class);
|
||||||
uses(DatabaseTransactions::class);
|
uses(DatabaseTransactions::class);
|
||||||
|
@ -42,11 +40,24 @@ it('testItDisplaysForms', function () {
|
||||||
->assertJsonPath('data.0.dates', '05.05.2023 - 07.06.2023')
|
->assertJsonPath('data.0.dates', '05.05.2023 - 07.06.2023')
|
||||||
->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('data.0.can_register', true)
|
||||||
->assertJsonPath('meta.per_page', 15)
|
->assertJsonPath('meta.per_page', 15)
|
||||||
->assertJsonPath('meta.base_url', url(''))
|
->assertJsonPath('meta.base_url', url(''))
|
||||||
->assertJsonPath('meta.total', 1);
|
->assertJsonPath('meta.total', 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('displays registration not possible', function () {
|
||||||
|
Storage::fake('temp');
|
||||||
|
$this->loginNami()->withoutExceptionHandling();
|
||||||
|
Form::factory()
|
||||||
|
->registrationFrom(now()->addDay())
|
||||||
|
->withImage('headerImage', 'lala-2.jpg')
|
||||||
|
->create();
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
$this->get('/api/form?perPage=15')->assertJsonPath('data.0.can_register', false);
|
||||||
|
});
|
||||||
|
|
||||||
it('testItDisplaysDefaultValueOfField', function () {
|
it('testItDisplaysDefaultValueOfField', function () {
|
||||||
Storage::fake('temp');
|
Storage::fake('temp');
|
||||||
$this->loginNami()->withoutExceptionHandling();
|
$this->loginNami()->withoutExceptionHandling();
|
||||||
|
|
|
@ -55,6 +55,22 @@ class FormRegisterActionTest extends FormTestCase
|
||||||
$this->assertEquals('Abraham', $participants->first()->data['spitzname']);
|
$this->assertEquals('Abraham', $participants->first()->data['spitzname']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItCannotRegisterWhenRegistrationFromReached(): void
|
||||||
|
{
|
||||||
|
$this->login()->loginNami();
|
||||||
|
$form = Form::factory()->registrationFrom(now()->addDay())->create();
|
||||||
|
|
||||||
|
$this->register($form, [])->assertJsonValidationErrors(['event' => 'Anmeldung zzt nicht möglich.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItCannotRegisterWhenRegistrationUntilReached(): void
|
||||||
|
{
|
||||||
|
$this->login()->loginNami();
|
||||||
|
$form = Form::factory()->registrationUntil(now()->subDay())->create();
|
||||||
|
|
||||||
|
$this->register($form, [])->assertJsonValidationErrors(['event' => 'Anmeldung zzt nicht möglich.']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testItSendsEmailToParticipant(): void
|
public function testItSendsEmailToParticipant(): void
|
||||||
{
|
{
|
||||||
$this->login()->loginNami()->withoutExceptionHandling();
|
$this->login()->loginNami()->withoutExceptionHandling();
|
||||||
|
|
Loading…
Reference in New Issue