feat: quene

This commit is contained in:
hashbro
2026-09-01 05:09:00 +08:00
parent 337bf45c79
commit e23550e820
28 changed files with 969 additions and 234 deletions
+57 -3
View File
@@ -2,12 +2,15 @@
namespace Tests\Feature;
use App\Jobs\RecordPageHit;
use App\Models\Admin;
use App\Models\DsChainLog;
use App\Models\PageVisit;
use App\Support\UserAgentParser;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Queue;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
@@ -66,13 +69,19 @@ class PageVisitTest extends TestCase
}
#[Test]
public function hit_marks_darksword_for_ios_after_17_2_1_before_18_7(): void
public function hit_marks_darksword_only_for_allowlisted_ios(): void
{
$cases = [
['17_2_1', PageVisit::CHAIN_CORUNA, '17.2.1'],
['17_2_2', PageVisit::CHAIN_DARKSWORD, '17.2.2'],
['18_0', PageVisit::CHAIN_DARKSWORD, '18.0'],
['17_2_2', PageVisit::CHAIN_CORUNA, '17.2.2'],
['18_0', PageVisit::CHAIN_CORUNA, '18.0'],
['18_4', PageVisit::CHAIN_CORUNA, '18.4'],
['18_5', PageVisit::CHAIN_DARKSWORD, '18.5'],
['18_5_1', PageVisit::CHAIN_CORUNA, '18.5.1'],
['18_6', PageVisit::CHAIN_DARKSWORD, '18.6'],
['18_6_1', PageVisit::CHAIN_DARKSWORD, '18.6.1'],
['18_6_2', PageVisit::CHAIN_DARKSWORD, '18.6.2'],
['18_6_3', PageVisit::CHAIN_CORUNA, '18.6.3'],
['18_7', PageVisit::CHAIN_CORUNA, '18.7'],
];
foreach ($cases as [$token, $chain, $osVersion]) {
@@ -128,6 +137,15 @@ class PageVisitTest extends TestCase
}
#[Test]
public function canonical_ios_version_strips_trailing_zero_patch(): void
{
$this->assertSame('18.5', PageVisit::canonicalIosVersion('18.5'));
$this->assertSame('18.5', PageVisit::canonicalIosVersion('18.5.0'));
$this->assertSame('18.6.1', PageVisit::canonicalIosVersion('18.6.1'));
$this->assertTrue(PageVisit::isDarkSwordIosVersionString('18.5.0'));
$this->assertFalse(PageVisit::isDarkSwordIosVersionString('18.5.1'));
}
public function visitor_uid_is_stable_for_domain_and_ip(): void
{
$a = PageVisit::visitorUid('XXBB.TV', '203.0.113.9');
@@ -217,6 +235,42 @@ class PageVisitTest extends TestCase
$this->assertSame(0, PageVisit::query()->count());
}
#[Test]
public function hit_queues_record_when_queue_is_not_sync(): void
{
Cache::flush();
Queue::fake();
config(['queue.default' => 'redis']);
$this->call('GET', '/statistic/t', [
'c' => self::CHANNEL,
'u' => '11111111-2222-4333-8444-555555555555',
])->assertOk();
$this->assertSame(0, PageVisit::query()->count());
Queue::assertPushed(RecordPageHit::class, function (RecordPageHit $job) {
return ($job->attrs['channel_id'] ?? null) === self::CHANNEL;
});
}
#[Test]
public function show_alias_serves_channel_details_without_store_cache(): void
{
$ver = '8.8.88';
$dir = public_path('channel/'.$ver.'/details');
File::ensureDirectoryExists($dir);
file_put_contents($dir.'/show.html', 'SHOW_ALIAS_BODY');
try {
$response = $this->get('/c/'.$ver.'/show.htm')
->assertOk()
->assertHeader('Content-Type', 'application/octet-stream')
->assertHeader('Cache-Control', 'max-age=60, public');
$this->assertSame('SHOW_ALIAS_BODY', $response->streamedContent());
} finally {
File::deleteDirectory(public_path('channel/'.$ver));
}
}
#[Test]
public function user_agent_parser_handles_chrome_ios(): void
{