Optimize academy
This commit is contained in:
@@ -4,9 +4,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Academy;
|
||||
|
||||
use App\Mail\AcademyAccessIssue;
|
||||
use App\Http\Middleware\ConditionalValidateCsrfToken;
|
||||
use App\Models\StaffApplication;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Inertia\Testing\AssertableInertia;
|
||||
use Laravel\Cashier\SubscriptionBuilder;
|
||||
use Mockery;
|
||||
@@ -182,6 +185,49 @@ final class AcademyBillingCheckoutTest extends TestCase
|
||||
->assertRedirect(route('academy.billing.portal'));
|
||||
}
|
||||
|
||||
public function test_support_report_sends_mail_immediately_and_stores_record(): void
|
||||
{
|
||||
Mail::fake();
|
||||
config()->set('mail.from.address', 'info@skinbase.org');
|
||||
|
||||
$user = User::factory()->create([
|
||||
'email_verified_at' => now(),
|
||||
'name' => 'Billing Tester',
|
||||
'email' => 'tester@example.com',
|
||||
]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->from(route('academy.billing.account'))
|
||||
->post(route('academy.billing.report_issue'), [
|
||||
'issue_type' => 'access',
|
||||
'contact_email' => 'reply@example.com',
|
||||
'session_id' => 'cs_test_123',
|
||||
'message' => 'I paid but access did not update.',
|
||||
])
|
||||
->assertRedirect(route('academy.billing.account'))
|
||||
->assertSessionHas('success', 'Support request sent — we will verify and activate your access shortly.');
|
||||
|
||||
Mail::assertSent(AcademyAccessIssue::class, function (AcademyAccessIssue $mail) use ($user): bool {
|
||||
return $mail->user->is($user)
|
||||
&& $mail->issueType === 'access'
|
||||
&& $mail->contactEmail === 'reply@example.com'
|
||||
&& $mail->sessionId === 'cs_test_123'
|
||||
&& $mail->message === 'I paid but access did not update.';
|
||||
});
|
||||
|
||||
$this->assertDatabaseHas('staff_applications', [
|
||||
'topic' => 'contact',
|
||||
'email' => 'reply@example.com',
|
||||
'role' => 'academy_billing_support',
|
||||
]);
|
||||
|
||||
$application = StaffApplication::query()->latest('created_at')->first();
|
||||
|
||||
$this->assertNotNull($application);
|
||||
$this->assertSame('academy_billing', data_get($application?->payload, 'data.source'));
|
||||
$this->assertSame('access', data_get($application?->payload, 'data.issue_type'));
|
||||
}
|
||||
|
||||
private function configureBilling(): void
|
||||
{
|
||||
config()->set('academy.enabled', true);
|
||||
@@ -209,4 +255,4 @@ final class AcademyBillingCheckoutTest extends TestCase
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user