| 1 | package Tapper::API::Plugin::Unittest; | ||||||||||
| 2 | 1 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||
| 3 | 1 | $Tapper::API::Plugin::Unittest::VERSION = '5.0.2'; | |||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Mojolicious::Lite; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | put 'unit-test/:testrun' => sub { | ||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=15.0
| |||||||||||
| 11 | 1 | my $self = shift; | |||||||||
| 12 | 1 | $self->app->renderer->default_format('json'); | |||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | 1 | my $data; | |||||||||
| 16 | 1 | ▶ | if ($self->tx->req->body) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 1 | require JSON::XS; | |||||||||
| 18 | 1 | $data = eval{JSON::XS::decode_json($self->tx->req->body)}; | |||||||||
| 19 | 1 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 0 | $self->render(json => { | |||||||||
| 21 | error => $@ | ||||||||||
| 22 | }, | ||||||||||
| 23 | status => 409, | ||||||||||
| 24 | ); | ||||||||||
| 25 | 0 | return; | |||||||||
| 26 | } | ||||||||||
| 27 | } | ||||||||||
| 28 | 1 | ▶ | if (not $data->{foo} eq 'bar') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 0 | $self->render(json => { | |||||||||
| 30 | error => "Can not find key 'foo' with value 'bar' in JSON body", | ||||||||||
| 31 | }, | ||||||||||
| 32 | status => 409, | ||||||||||
| 33 | ); | ||||||||||
| 34 | } | ||||||||||
| 35 | 1 | $self->respond_to(json => {json => {key => 'value'}, | |||||||||
| 36 | status => 202, | ||||||||||
| 37 | }, | ||||||||||
| 38 | ); | ||||||||||
| 39 | 1 | }; | |||||||||
| 40 | |||||||||||
| 41 | 1 | 1; | |||||||||
| 42 | |||||||||||
| 43 | __END__ | ||||||||||