complete story 8.2 with qa tests
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Mail\WelcomeEmail;
|
||||
use App\Models\User;
|
||||
use App\Notifications\WelcomeAccountNotification;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
@@ -131,52 +132,49 @@ test('welcome email contains correct password for company client', function () {
|
||||
|
||||
test('welcome email uses arabic subject for arabic preference', function () {
|
||||
$user = User::factory()->individual()->create(['preferred_language' => 'ar']);
|
||||
$notification = new WelcomeAccountNotification('password123');
|
||||
|
||||
$mailMessage = $notification->toMail($user);
|
||||
$mailable = new WelcomeEmail($user, 'password123');
|
||||
$envelope = $mailable->envelope();
|
||||
|
||||
expect($mailMessage->subject)->toBe('مرحباً بك في مكتب ليبرا للمحاماة');
|
||||
expect($envelope->subject)->toBe('مرحباً بك في مكتب ليبرا للمحاماة');
|
||||
});
|
||||
|
||||
test('welcome email uses english subject for english preference', function () {
|
||||
$user = User::factory()->individual()->create(['preferred_language' => 'en']);
|
||||
$notification = new WelcomeAccountNotification('password123');
|
||||
|
||||
$mailMessage = $notification->toMail($user);
|
||||
$mailable = new WelcomeEmail($user, 'password123');
|
||||
$envelope = $mailable->envelope();
|
||||
|
||||
expect($mailMessage->subject)->toBe('Welcome to Libra Law Firm');
|
||||
expect($envelope->subject)->toBe('Welcome to Libra Law Firm');
|
||||
});
|
||||
|
||||
test('welcome email defaults to arabic when notification receives user without language', function () {
|
||||
test('welcome email defaults to arabic when preferred_language is null', function () {
|
||||
$user = User::factory()->individual()->create(['preferred_language' => 'ar']);
|
||||
// Simulate a scenario where preferred_language could be null in memory
|
||||
$user->preferred_language = null;
|
||||
|
||||
$mailable = new WelcomeEmail($user, 'password123');
|
||||
$envelope = $mailable->envelope();
|
||||
|
||||
expect($envelope->subject)->toBe('مرحباً بك في مكتب ليبرا للمحاماة');
|
||||
});
|
||||
|
||||
test('welcome email uses correct arabic template', function () {
|
||||
$user = User::factory()->individual()->create(['preferred_language' => 'ar']);
|
||||
|
||||
// Simulate a scenario where preferred_language could be missing
|
||||
// by creating a mock object that returns null for preferred_language
|
||||
$mockUser = new class($user)
|
||||
{
|
||||
public $preferred_language = null;
|
||||
$mailable = new WelcomeEmail($user, 'password123');
|
||||
$content = $mailable->content();
|
||||
|
||||
private $user;
|
||||
expect($content->markdown)->toBe('emails.welcome.ar');
|
||||
});
|
||||
|
||||
public function __construct($user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
test('welcome email uses correct english template', function () {
|
||||
$user = User::factory()->individual()->create(['preferred_language' => 'en']);
|
||||
|
||||
public function __get($name)
|
||||
{
|
||||
if ($name === 'preferred_language') {
|
||||
return null;
|
||||
}
|
||||
$mailable = new WelcomeEmail($user, 'password123');
|
||||
$content = $mailable->content();
|
||||
|
||||
return $this->user->$name;
|
||||
}
|
||||
};
|
||||
|
||||
$notification = new WelcomeAccountNotification('password123');
|
||||
$mailMessage = $notification->toMail($mockUser);
|
||||
|
||||
expect($mailMessage->subject)->toBe('مرحباً بك في مكتب ليبرا للمحاماة');
|
||||
expect($content->markdown)->toBe('emails.welcome.en');
|
||||
});
|
||||
|
||||
// ===========================================
|
||||
@@ -190,12 +188,12 @@ test('welcome email passes correct data to view', function () {
|
||||
'preferred_language' => 'en',
|
||||
]);
|
||||
|
||||
$notification = new WelcomeAccountNotification('testPassword123');
|
||||
$mailMessage = $notification->toMail($user);
|
||||
$mailable = new WelcomeEmail($user, 'testPassword123');
|
||||
$content = $mailable->content();
|
||||
|
||||
expect($mailMessage->viewData['user']->id)->toBe($user->id);
|
||||
expect($mailMessage->viewData['password'])->toBe('testPassword123');
|
||||
expect($mailMessage->viewData['locale'])->toBe('en');
|
||||
expect($content->with['user']->id)->toBe($user->id);
|
||||
expect($content->with['password'])->toBe('testPassword123');
|
||||
expect($content->with['loginUrl'])->toBe(route('login'));
|
||||
});
|
||||
|
||||
test('welcome email passes company name for company clients', function () {
|
||||
@@ -204,11 +202,51 @@ test('welcome email passes company name for company clients', function () {
|
||||
'preferred_language' => 'ar',
|
||||
]);
|
||||
|
||||
$notification = new WelcomeAccountNotification('companyPass');
|
||||
$mailMessage = $notification->toMail($user);
|
||||
$mailable = new WelcomeEmail($user, 'companyPass');
|
||||
$content = $mailable->content();
|
||||
|
||||
expect($mailMessage->viewData['user']->company_name)->toBe('Test Company Ltd');
|
||||
expect($mailMessage->viewData['locale'])->toBe('ar');
|
||||
expect($content->with['user']->company_name)->toBe('Test Company Ltd');
|
||||
expect($content->markdown)->toBe('emails.welcome.ar');
|
||||
});
|
||||
|
||||
test('arabic template renders correctly', function () {
|
||||
$user = User::factory()->individual()->create([
|
||||
'full_name' => 'محمد أحمد',
|
||||
'email' => 'mohammad@example.com',
|
||||
'preferred_language' => 'ar',
|
||||
]);
|
||||
|
||||
$mailable = new WelcomeEmail($user, 'password123');
|
||||
|
||||
$mailable->assertSeeInHtml('مرحباً بك في مكتب ليبرا للمحاماة');
|
||||
$mailable->assertSeeInHtml('محمد أحمد');
|
||||
$mailable->assertSeeInHtml('mohammad@example.com');
|
||||
$mailable->assertSeeInHtml('password123');
|
||||
$mailable->assertSeeInHtml('تسجيل الدخول');
|
||||
});
|
||||
|
||||
test('english template renders correctly', function () {
|
||||
$user = User::factory()->individual()->create([
|
||||
'full_name' => 'John Doe',
|
||||
'email' => 'john@example.com',
|
||||
'preferred_language' => 'en',
|
||||
]);
|
||||
|
||||
$mailable = new WelcomeEmail($user, 'password456');
|
||||
|
||||
$mailable->assertSeeInHtml('Welcome to Libra Law Firm');
|
||||
$mailable->assertSeeInHtml('John Doe');
|
||||
$mailable->assertSeeInHtml('john@example.com');
|
||||
$mailable->assertSeeInHtml('password456');
|
||||
$mailable->assertSeeInHtml('Login Now');
|
||||
});
|
||||
|
||||
test('welcome email contains login url', function () {
|
||||
$user = User::factory()->individual()->create(['preferred_language' => 'en']);
|
||||
|
||||
$mailable = new WelcomeEmail($user, 'password123');
|
||||
|
||||
$mailable->assertSeeInHtml(route('login'));
|
||||
});
|
||||
|
||||
// ===========================================
|
||||
@@ -227,6 +265,28 @@ test('welcome notification uses queueable trait', function () {
|
||||
expect($traits)->toContain(\Illuminate\Bus\Queueable::class);
|
||||
});
|
||||
|
||||
test('welcome email mailable implements should queue interface', function () {
|
||||
$user = User::factory()->individual()->create();
|
||||
$mailable = new WelcomeEmail($user, 'password');
|
||||
|
||||
expect($mailable)->toBeInstanceOf(\Illuminate\Contracts\Queue\ShouldQueue::class);
|
||||
});
|
||||
|
||||
test('welcome email mailable uses queueable trait', function () {
|
||||
$traits = class_uses(WelcomeEmail::class);
|
||||
|
||||
expect($traits)->toContain(\Illuminate\Bus\Queueable::class);
|
||||
});
|
||||
|
||||
test('notification returns welcome email mailable', function () {
|
||||
$user = User::factory()->individual()->create();
|
||||
$notification = new WelcomeAccountNotification('password123');
|
||||
|
||||
$mailable = $notification->toMail($user);
|
||||
|
||||
expect($mailable)->toBeInstanceOf(WelcomeEmail::class);
|
||||
});
|
||||
|
||||
// ===========================================
|
||||
// Admin Exclusion Tests
|
||||
// ===========================================
|
||||
|
||||
Reference in New Issue
Block a user