blob: 4457048bf6b22154ce53df98bbad8a4200299a64 [file] [log] [blame]
Akron30e7bc72021-02-16 17:05:41 +01001use Mojolicious::Lite;
2use Test::More tests => 17;
3use Mojolicious::Controller;
4
5use_ok('Kalamar::Request');
6
7my $req = Kalamar::Request->new(
8 url => 'http://www.example.com',
9 method => 'POST',
10 controller => Mojolicious::Controller->new
11)->param('x', 'y');
12
13is($req->method, 'POST');
14is($req->url, 'http://www.example.com');
15ok($req->controller);
16is_deeply($req->param, ['x','y'], 'Compare');
17
18my $err;
19$req->start->catch(
20 sub {
21 $err = shift
22 })->finally(
23 sub {
24 is($err,'No useragent defined','Error');
25 })->wait;
26
27my $c = $req->controller;
28$c->app(app);
29ok($req->controller(undef),'Set controller');
30
31$req->start->catch(
32 sub {
33 $err = shift
34 })->finally(
35 sub {
36 is($err,'No controller defined','Error');
37 })->wait;
38
39ok($req->url(undef),'Set URL');
40
41$req->start->catch(
42 sub {
43 $err = shift
44 })->finally(
45 sub {
46 is($err,'No URL defined','Error');
47 })->wait;
48
49put '/test' => sub {
50 shift->render(text => 'Hallo')
51};
52
53# Set UA
54ok($req->ua(Mojo::UserAgent->new));
55$req->ua->server->app->log->level('fatal');
56ok($req->controller($c));
57ok($req->method('put'));
58ok($req->url('/test'));
59ok($req->param(undef));
60
61$err = undef;
62$req->start->then(
63 sub {
64 my $tx = shift;
65 is($tx->res->body,'Hallo');
66 })->catch(
67 sub {
68 $err = shift;
69 })->finally(
70 sub {
71 ok(!$err);
72 })->wait;
73
74done_testing;
75__END__
76
771;