You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.4 KiB
46 lines
1.4 KiB
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use App\Models\SystemSetting;
|
|
use App\Services\WechatHomeVisitService;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class WechatHomeVisitServiceTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
Carbon::setTestNow();
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function test_today_offset_only_applies_on_saved_date(): void
|
|
{
|
|
Carbon::setTestNow(Carbon::parse('2026-07-06 10:00:00', 'Asia/Shanghai'));
|
|
|
|
SystemSetting::setInt(WechatHomeVisitService::KEY_TODAY_OFFSET, 400);
|
|
SystemSetting::setString(WechatHomeVisitService::KEY_TODAY_OFFSET_DATE, '2026-07-06');
|
|
|
|
$service = app(WechatHomeVisitService::class);
|
|
$this->assertSame(400, $service->todayOffset());
|
|
|
|
Carbon::setTestNow(Carbon::parse('2026-07-07 09:00:00', 'Asia/Shanghai'));
|
|
$this->assertSame(0, $service->todayOffset());
|
|
}
|
|
|
|
public function test_update_display_values_stamps_today_offset_date(): void
|
|
{
|
|
Carbon::setTestNow(Carbon::parse('2026-07-06 15:30:00', 'Asia/Shanghai'));
|
|
|
|
$service = app(WechatHomeVisitService::class);
|
|
$service->updateDisplayValues(1000, 88);
|
|
|
|
$this->assertSame('2026-07-06', SystemSetting::getString(WechatHomeVisitService::KEY_TODAY_OFFSET_DATE));
|
|
$this->assertSame(88, $service->todayVisits());
|
|
}
|
|
}
|