File: | t/090_corpus__010_error_full.t |
Coverage: | 100.0% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | #!perl | ||||||
2 | |||||||
3 | 1 1 1 | 3581 2 20 | use strict; | ||||
4 | 1 1 1 | 2 1 25 | use warnings; | ||||
5 | 1 1 1 | 530 312 3 | use lib 'lib'; | ||||
6 | |||||||
7 | 1 1 1 | 620 103694 3 | use Test::Most; | ||||
8 | 1 1 1 | 21380 6196 3 | use JSON qw/decode_json/; | ||||
9 | 1 1 1 | 793 2 1428 | use JSON::DJARE::Writer; | ||||
10 | |||||||
11 | 1 | 62251 | my $expected = decode_json( join '', (<DATA>) ); | ||||
12 | 1 | 4 | my $from = 'myapi.com/coefficiants'; | ||||
13 | 1 2 | 3 2 | my $timestamp = sub { '2020-12-09 16:09:53+00:00' }; | ||||
14 | |||||||
15 | 1 | 4 | for my $t ( | ||||
16 | { | ||||||
17 | name => 'from in new()', | ||||||
18 | new_args => [ auto_timestamp => $timestamp, meta_from => $from ], | ||||||
19 | error_args => [] | ||||||
20 | }, | ||||||
21 | { | ||||||
22 | name => 'from in error()', | ||||||
23 | new_args => [ auto_timestamp => $timestamp ], | ||||||
24 | error_args => [ from => $from ] | ||||||
25 | } | ||||||
26 | ) | ||||||
27 | { | ||||||
28 | |||||||
29 | my $djare = JSON::DJARE::Writer->new( | ||||||
30 | djare_version => '0.0.2', | ||||||
31 | meta_version => '0.0.1', | ||||||
32 | 2 2 | 2499 7 | @{ $t->{'new_args'} } | ||||
33 | ); | ||||||
34 | |||||||
35 | my $result = $djare->error( | ||||||
36 | 'Invalid payload provided', | ||||||
37 | id => '10.10.3.59:453294281', | ||||||
38 | code => 'BADPAYLOAD', | ||||||
39 | detail => 'Value at [/error/title]: expected[string] actual[array]', | ||||||
40 | trace => [ | ||||||
41 | { | ||||||
42 | instancePath => "/error/title", | ||||||
43 | schemaPath => "#/definitions/error/properties/title/type", | ||||||
44 | keyword => "type", | ||||||
45 | params => { | ||||||
46 | type => "string" | ||||||
47 | }, | ||||||
48 | message => "must be string" | ||||||
49 | } | ||||||
50 | ], | ||||||
51 | 2 2 | 7 4 | @{ $t->{'error_args'} } | ||||
52 | ); | ||||||
53 | |||||||
54 | 2 | 6 | eq_or_diff( $result, $expected, "matches for case: " . $t->{'name'} ); | ||||
55 | } | ||||||
56 | |||||||
57 | 1 | 1981 | done_testing(); | ||||
58 |