feat: Phase 3 - public registration pages and Mailwizz config
This commit is contained in:
56
tests/Feature/MailwizzConfigUiTest.php
Normal file
56
tests/Feature/MailwizzConfigUiTest.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\PreregistrationPage;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
class MailwizzConfigUiTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_owner_can_view_mailwizz_wizard(): void
|
||||
{
|
||||
$user = User::factory()->create(['role' => 'user']);
|
||||
$page = $this->makePageForUser($user);
|
||||
|
||||
$response = $this->actingAs($user)->get(route('admin.pages.mailwizz.edit', $page));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertSee('Mailwizz', escape: false);
|
||||
}
|
||||
|
||||
public function test_other_user_cannot_view_mailwizz_wizard(): void
|
||||
{
|
||||
$owner = User::factory()->create(['role' => 'user']);
|
||||
$intruder = User::factory()->create(['role' => 'user']);
|
||||
$page = $this->makePageForUser($owner);
|
||||
|
||||
$response = $this->actingAs($intruder)->get(route('admin.pages.mailwizz.edit', $page));
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
private function makePageForUser(User $user): PreregistrationPage
|
||||
{
|
||||
return PreregistrationPage::query()->create([
|
||||
'slug' => (string) Str::uuid(),
|
||||
'user_id' => $user->id,
|
||||
'title' => 'Fest',
|
||||
'heading' => 'Join',
|
||||
'intro_text' => null,
|
||||
'thank_you_message' => null,
|
||||
'expired_message' => null,
|
||||
'ticketshop_url' => null,
|
||||
'start_date' => now()->addDay(),
|
||||
'end_date' => now()->addMonth(),
|
||||
'phone_enabled' => false,
|
||||
'is_active' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
135
tests/Feature/PublicPageTest.php
Normal file
135
tests/Feature/PublicPageTest.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\PreregistrationPage;
|
||||
use App\Models\Subscriber;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PublicPageTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_show_returns_ok_for_active_public_page(): void
|
||||
{
|
||||
$page = $this->makePage([
|
||||
'start_date' => now()->addDay(),
|
||||
'end_date' => now()->addMonth(),
|
||||
]);
|
||||
|
||||
$response = $this->get(route('public.page', ['publicPage' => $page->slug]));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertSee($page->heading, escape: false);
|
||||
}
|
||||
|
||||
public function test_show_returns_not_found_when_page_is_inactive(): void
|
||||
{
|
||||
$page = $this->makePage([
|
||||
'is_active' => false,
|
||||
'start_date' => now()->subHour(),
|
||||
'end_date' => now()->addMonth(),
|
||||
]);
|
||||
|
||||
$response = $this->get(route('public.page', ['publicPage' => $page->slug]));
|
||||
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_subscribe_returns_json_success_and_creates_subscriber(): void
|
||||
{
|
||||
$page = $this->makePage([
|
||||
'thank_you_message' => 'Custom thanks',
|
||||
'start_date' => now()->subHour(),
|
||||
'end_date' => now()->addMonth(),
|
||||
'phone_enabled' => false,
|
||||
]);
|
||||
|
||||
$response = $this->postJson(route('public.subscribe', ['publicPage' => $page->slug]), [
|
||||
'first_name' => 'Ada',
|
||||
'last_name' => 'Lovelace',
|
||||
'email' => 'ada@example.com',
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson([
|
||||
'success' => true,
|
||||
'message' => 'Custom thanks',
|
||||
]);
|
||||
$this->assertDatabaseHas('subscribers', [
|
||||
'preregistration_page_id' => $page->id,
|
||||
'email' => 'ada@example.com',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_subscribe_returns_friendly_message_for_duplicate_email(): void
|
||||
{
|
||||
$page = $this->makePage([
|
||||
'start_date' => now()->subHour(),
|
||||
'end_date' => now()->addMonth(),
|
||||
]);
|
||||
|
||||
Subscriber::query()->create([
|
||||
'preregistration_page_id' => $page->id,
|
||||
'first_name' => 'A',
|
||||
'last_name' => 'B',
|
||||
'email' => 'dup@example.com',
|
||||
]);
|
||||
|
||||
$response = $this->postJson(route('public.subscribe', ['publicPage' => $page->slug]), [
|
||||
'first_name' => 'C',
|
||||
'last_name' => 'D',
|
||||
'email' => 'dup@example.com',
|
||||
]);
|
||||
|
||||
$response->assertStatus(422);
|
||||
$response->assertJson([
|
||||
'success' => false,
|
||||
'message' => 'You are already registered for this event.',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_subscribe_forbidden_outside_registration_window(): void
|
||||
{
|
||||
$page = $this->makePage([
|
||||
'start_date' => now()->addDay(),
|
||||
'end_date' => now()->addMonth(),
|
||||
]);
|
||||
|
||||
$response = $this->postJson(route('public.subscribe', ['publicPage' => $page->slug]), [
|
||||
'first_name' => 'A',
|
||||
'last_name' => 'B',
|
||||
'email' => 'a@example.com',
|
||||
]);
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $overrides
|
||||
*/
|
||||
private function makePage(array $overrides = []): PreregistrationPage
|
||||
{
|
||||
$user = User::factory()->create(['role' => 'user']);
|
||||
|
||||
return PreregistrationPage::query()->create(array_merge([
|
||||
'slug' => (string) Str::uuid(),
|
||||
'user_id' => $user->id,
|
||||
'title' => 'Test page',
|
||||
'heading' => 'Join us',
|
||||
'intro_text' => null,
|
||||
'thank_you_message' => null,
|
||||
'expired_message' => null,
|
||||
'ticketshop_url' => null,
|
||||
'start_date' => now()->subHour(),
|
||||
'end_date' => now()->addMonth(),
|
||||
'phone_enabled' => false,
|
||||
'is_active' => true,
|
||||
], $overrides));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user