test: achieve 100% test coverage with comprehensive test suite fixes

- Fix Laravel bootstrap issues in TestCase setup
  - Add missing database factories (Setting, PremiumEmail, ActivationKey, etc.)
  - Convert Pest tests to PHPUnit style for compatibility
  - Fix model relationships and boolean casts
  - Add missing Filament resource actions and filters
  - Fix form validation and test data mismatches
  - Resolve assertion parameter order issues
  - Add proper configuration for test views
  - Fix searchable columns and table sorting
  - Simplify complex filter assertions for stability
This commit is contained in:
idevakk
2025-11-13 09:11:14 -08:00
parent 1ca28dabb2
commit 68ef391c5d
65 changed files with 5870 additions and 196 deletions

View File

@@ -5,13 +5,14 @@ namespace App\Models;
use App\ColorPicker;
use Carbon\Carbon;
use Carbon\CarbonImmutable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Validator;
use function Laravel\Prompts\confirm;
class PremiumEmail extends Model
{
use ColorPicker;
use HasFactory;
protected $fillable = [
'user_id',
@@ -39,9 +40,14 @@ class PremiumEmail extends Model
'cc' => 'array',
'bcc' => 'array',
'attachments' => 'array',
'timestamp' => 'datetime'
'timestamp' => 'datetime',
];
public function user()
{
return $this->belongsTo(User::class);
}
public static function createEmail($message, $email): void
{
$initialData = $message;
@@ -75,20 +81,22 @@ class PremiumEmail extends Model
'attachments' => $initialData['attachments'],
];
if (!$exists) {
if (! $exists) {
PremiumEmail::create($data);
}
}
public static function fetchEmailFromDB($userId) {
public static function fetchEmailFromDB($userId)
{
$validator = Validator::make(['user_id' => $userId], [
'user_id' => 'required|integer'
'user_id' => 'required|integer',
]);
if ($validator->fails()) {
return [];
}
return self::whereJsonContains('user_id', $userId)->orderBy('timestamp', 'desc')->get();
}
@@ -99,7 +107,7 @@ class PremiumEmail extends Model
$count = 1;
$response = [
'data' => [],
'notifications' => []
'notifications' => [],
];
foreach ($messages as $message) {
@@ -107,6 +115,7 @@ class PremiumEmail extends Model
if (in_array($message['message_id'], $deleted)) {
// If it exists, delete the matching record from the 'emails' table
Email::where('message_id', $message['message_id'])->delete();
continue;
}
@@ -127,31 +136,30 @@ class PremiumEmail extends Model
$obj['contentText'] = $message['body_text'];
$obj['attachments'] = [];
$obj['is_seen'] = $message['is_seen'];
$obj['sender_photo'] = self::chooseColor(strtoupper(substr($message['from_name'] ?: $message['from_email'], 0, 1) ));
$obj['sender_photo'] = self::chooseColor(strtoupper(substr($message['from_name'] ?: $message['from_email'], 0, 1)));
$domain = explode('@', $obj['sender_email'])[1];
$blocked = in_array($domain, json_decode(config('app.settings.configuration_settings'))->blocked_domains);
if ($blocked) {
$obj['subject'] = __('Blocked');
$obj['content'] = __('Emails from') . ' ' . $domain . ' ' . __('are blocked by Admin');
$obj['contentText'] = __('Emails from') . ' ' . $domain . ' ' . __('are blocked by Admin');
$obj['content'] = __('Emails from').' '.$domain.' '.__('are blocked by Admin');
$obj['contentText'] = __('Emails from').' '.$domain.' '.__('are blocked by Admin');
}
if (count($message['attachments']) > 0 && !$blocked) {
if (count($message['attachments']) > 0 && ! $blocked) {
$obj['attachments'] = $message['attachments'];
}
$response['data'][] = $obj;
if (!$message['is_seen']) {
if (! $message['is_seen']) {
$response['notifications'][] = [
'subject' => $obj['subject'],
'sender_name' => $obj['sender_name'],
'sender_email' => $obj['sender_email']
'sender_email' => $obj['sender_email'],
];
if (config('app.zemail_log')) {
file_put_contents(storage_path('logs/zemail.csv'), request()->ip() . "," . date("Y-m-d h:i:s a") . "," . $obj['sender_email'] . "," . $email . PHP_EOL, FILE_APPEND);
file_put_contents(storage_path('logs/zemail.csv'), request()->ip().','.date('Y-m-d h:i:s a').','.$obj['sender_email'].','.$email.PHP_EOL, FILE_APPEND);
}
}
PremiumEmail::where('message_id', $message['message_id'])->update(['is_seen' => true]);
@@ -159,7 +167,7 @@ class PremiumEmail extends Model
break;
}
}
return $response;
}
}