use Mojo::Base -strict;

use Test::More;
use Test::Mojo;

my $t = Test::Mojo->new('AnchorBackend');
$t->post_ok('/api/check' => { Origin => 'http://localhost:5173' })
	->status_is(200)
	->header_is('Access-Control-Allow-Origin' => 'http://localhost:5173')
	->header_is('Access-Control-Allow-Credentials' => 'true')
	->json_is('/status' => 'success');

$t->options_ok('/api/check' => {
	Origin                           => 'http://localhost:5173',
	'Access-Control-Request-Method'  => 'POST',
	'Access-Control-Request-Headers' => 'Authorization, Content-Type',
})
	->status_is(204)
	->header_is('Access-Control-Allow-Origin' => 'http://localhost:5173')
	->header_is('Access-Control-Allow-Methods' => 'POST, OPTIONS')
	->header_is('Access-Control-Allow-Headers' => 'Content-Type, Authorization');

$t->post_ok('/api/auth/change-password' => json => {
	current_password => 'wrong-password',
	new_password     => 'NewPassword123'
})
	->status_is(401)
	->json_is('/status' => 'error')
	->json_is('/message' => 'Authentication required');

done_testing();
