Step 6: Pest integration tests for webhook ingestion and background job

This commit is contained in:
idevakk
2026-03-05 14:57:40 +05:30
parent ac9e7227e6
commit 4d8f808d97
3 changed files with 185 additions and 9 deletions

View File

@@ -107,10 +107,16 @@ class ProcessIncomingEmail implements ShouldQueue
}
if (! empty($bodyHtml)) {
$stripped = strip_tags($bodyHtml);
$stripped = preg_replace('/\s+/', ' ', $stripped);
// Replace all HTML tags with spaces to prevent words from running together
$html = preg_replace('/<[^>]*>/', ' ', $bodyHtml);
return mb_substr(trim($stripped), 0, 500);
// Decode HTML entities (e.g. &nbsp;, &amp;)
$decoded = html_entity_decode($html ?? '', ENT_QUOTES | ENT_HTML5, 'UTF-8');
// Collapse multiple spaces into a single space
$stripped = preg_replace('/\s+/', ' ', $decoded);
return mb_substr(trim($stripped ?? ''), 0, 500);
}
return '';
@@ -126,12 +132,13 @@ class ProcessIncomingEmail implements ShouldQueue
Cache::rememberForever('mongodb_ttl_index_ensured', function () {
$ttlSeconds = config('services.mailops.email_body_ttl_seconds', 259200);
/** @var Collection $collection */
$collection = (new EmailBody)->getCollection();
$collection->createIndex(
['created_at' => 1],
['expireAfterSeconds' => $ttlSeconds, 'name' => 'ttl_created_at']
);
EmailBody::raw(function ($collection) use ($ttlSeconds) {
/* @var \MongoDB\Collection $collection */
$collection->createIndex(
['created_at' => 1],
['expireAfterSeconds' => $ttlSeconds, 'name' => 'ttl_created_at']
);
});
return true;
});