<?php

namespace Tests\Services\CheckActiveMenuService;

use App\Services\CacheService;
use App\Services\CheckActiveMenuService;
use App\UserVisitMenuLog;
use Illuminate\Support\Facades\Redis;
use Tests\TestCase;

class CheckActiveMenuSyncTest extends TestCase
{
    /** @var CheckActiveMenuService $checkActiveMenuService */
    public $checkActiveMenuService;

    public function setUp(): void
    {
        parent::setUp();
        $this->checkActiveMenuService = app('CheckActiveMenuService');
    }

    public function testHandle()
    {
        $l1Len = Redis::LLEN('UserVisitMenuLogsL1');
        $l2Len = Redis::LLEN('UserVisitMenuLogsL2');
        $DBLen = UserVisitMenuLog::query()->count();
        $this->checkActiveMenuService->sync();
        $this->assertTrue(Redis::LLEN('UserVisitMenuLogsL1') === 0);
        $this->assertTrue(Redis::LLEN('UserVisitMenuLogsL2') === $l2Len + $l1Len);
        $this->assertTrue(UserVisitMenuLog::query()->count() === $DBLen + $l1Len);
    }
}
