File: 100-request-create.t

package info (click to toggle)
libponapi-client-perl 0.002012-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 292 kB
  • sloc: perl: 941; makefile: 2
file content (59 lines) | stat: -rw-r--r-- 1,386 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!perl

use strict;
use warnings;

use Test::More;
use Test::Moose;

use JSON::MaybeXS qw( decode_json );

BEGIN {
    use_ok('PONAPI::Client::Request::Create');
}

my %TEST_DATA = (
    type => 'articles',
    data => {
        body    => "The 4nd shortest article. Ever.",
        created => "2015-08-22T14:56:29.000Z",
        status  => "pending approval",
        title   => "A forth title",
        updated => "2015-08-22T14:56:28.000Z",
    },
);

subtest '... testing object' => sub {

    my $req = PONAPI::Client::Request::Create->new( %TEST_DATA );

    isa_ok( $req, 'PONAPI::Client::Request::Create');
    does_ok($req, 'PONAPI::Client::Request');
    does_ok($req, 'PONAPI::Client::Request::Role::IsPOST');
    does_ok($req, 'PONAPI::Client::Request::Role::HasType');
    does_ok($req, 'PONAPI::Client::Request::Role::HasData');

    can_ok( $req, 'method' );
    can_ok( $req, 'path' );
    can_ok( $req, 'request_params' );

};

subtest '... testing request parameters' => sub {

    my $req = PONAPI::Client::Request::Create->new( %TEST_DATA );

    my $EXPECTED = +{
        method       => 'POST',
        path         => '/articles',
        body         => { data => $TEST_DATA{data} },
    };

    my $GOT = +{ $req->request_params };
    $GOT->{body} = decode_json($GOT->{body});

    is_deeply( $GOT, $EXPECTED, 'checked request parametes' );

};

done_testing;