### ----------------------------------------------------
### -- Humming-Bird
### -- Licenses: MIT
### -- Authors: Rawley Fowler
### -- File: t/07-advice.rakutest
### ----------------------------------------------------
use v6.d;

use Test;

use Humming-Bird::Core;
use Humming-Bird::Glue;

plan 3;

sub custom-advice($response) {
	return $response.write('abc');
}

get('/abc', -> $request, $response {
	$response.status(204);
});

advice(&custom-advice);

# [1] because the identity function is the root advice.
is advice()[1].raku, &custom-advice.raku, 'Is advice set properly?';

my $dumby-request = Request.new(path => '/abc', method => GET, version => 'HTTP/1.1');
my $response = routes{'/'}{'abc'}{GET}($dumby-request);
my @advice = advice();
for @advice -> &advice {
    &advice($response);
}

is $response.body.decode, 'abc', 'Is body set correctly by Advice?';
is $response.status.Int, 204, 'Does response still have old values after advice?';

done-testing;


