summary refs log tree commit diff
path: root/t/spore-method/payload.t
blob: 483d9cc59d182104f23237c4a8588cb059e10ec7 (plain) (blame)
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
use strict;
use warnings;
use Test::More tests => 4;

use Test::Exception;

use JSON;
use Net::HTTP::Spore;

my $api_with_payload = {
    base_url => 'foo',
    methods  => {
        create_user => {
            method           => 'POST',
            path             => '/user',
            required_payload => 1,
        },
        list_user => {
            method => 'GET',
            path   => '/user',
        }
    },
};

my $obj =
  Net::HTTP::Spore->new_from_string( JSON::encode_json($api_with_payload),
    base_url => 'http://localhost' );

dies_ok { $obj->create_user(); };
like $@->body->{error}, qr/this method require a payload/;

dies_ok { $obj->list_user( payload => {} ) };
like $@->body->{error}, qr/payload requires a PUT or POST method/;