<?php

declare(strict_types=1);

use App\Http\Api\Query\Query;
use App\Http\Resources\Auth\Resource\UserJsonResource;
use App\Models\Auth\User;
use Laravel\Sanctum\Sanctum;

use function Pest\Laravel\get;

uses(Illuminate\Foundation\Testing\WithFaker::class);

test('protected', function () {
    $response = get(route('api.me.show'));

    $response->assertUnauthorized();
});

test('default', function () {
    $user = User::factory()->createOne();

    Sanctum::actingAs($user);

    $response = get(route('api.me.show'));

    $response->assertJson(
        json_decode(
            json_encode(
                new UserJsonResource($user, new Query())
                    ->response()
                    ->getData()
            ),
            true
        )
    );
});
