<?php

use App\Domains\Translation\Models\Translation;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Redis;

beforeEach(function () {
    Redis::del('lang:*:de:auth');
    app('translator')->setLoaded([]);
});

afterEach(function () {
    app('translator')->setLoaded([]);
    Redis::del('lang:*:de:auth');
});

it('loads translation from database via __()', function () {
    Translation::create([
        'locale' => 'de',
        'namespace' => '*',
        'group' => 'auth',
        'key' => 'login',
        'value' => 'Anmelden',
    ]);

    App::setLocale('de');
    // Force reload
    app('translator')->setLoaded([]);

    expect(__('auth.login'))->toBe('Anmelden');
});
