<?php

use Beebmx\KirbySign\Exceptions\InvalidSignatureKeyException;
use Beebmx\KirbySign\Signed;

it('can return an instance of Signed with sign helper', function () {
    App(options: ['beebmx.kirby-sign' => ['key' => 'kirby-key']]);

    expect(sign())
        ->toBeInstanceOf(Signed::class);
});

it('can set a new key with helper', function () {
    App();

    expect(sign('testing'))
        ->toBeInstanceOf(Signed::class);
});

it('throw an error if no key is set', function () {
    App();
    sign();
})->throws(InvalidSignatureKeyException::class);

it('can generate a new signed url', function () {
    App(options: ['beebmx.kirby-sign' => ['key' => 'kirby-key']]);

    expect(sign()->url('protected/page'))
        ->toBeString()
        ->toStartWith('http://example.com')
        ->toContain('signature');
});

it('can validate a signed url', function () {
    App(options: ['beebmx.kirby-sign' => ['key' => 'kirby-key']], uri: 'protected/page');

    expect(sign()->isValid())
        ->toBeBool()
        ->toBeFalse();
});
