<?php

namespace MintyPHP\Tests\Unit\Module;

use MintyPHP\Module\Bookmarks\BookmarksAuthorizationPolicy;
use PHPUnit\Framework\TestCase;

final class BookmarksAuthorizationPolicyTest extends TestCase
{
    public function testSupportsBookmarksAbilityOnly(): void
    {
        $policy = new BookmarksAuthorizationPolicy();

        self::assertTrue($policy->supports(BookmarksAuthorizationPolicy::ABILITY_USE));
        self::assertFalse($policy->supports('addressbook.view'));
    }

    public function testAuthorizeAllowsAuthenticatedActors(): void
    {
        $policy = new BookmarksAuthorizationPolicy();

        $decision = $policy->authorize(BookmarksAuthorizationPolicy::ABILITY_USE, [
            'actor_user_id' => 7,
        ]);

        self::assertTrue($decision->isAllowed());
    }

    public function testAuthorizeDeniesMissingActor(): void
    {
        $policy = new BookmarksAuthorizationPolicy();

        $decision = $policy->authorize(BookmarksAuthorizationPolicy::ABILITY_USE, []);

        self::assertFalse($decision->isAllowed());
        self::assertSame(403, $decision->status());
    }
}
