Last active
August 29, 2015 14:15
-
-
Save meru-akimbo/8b2b8ed5ff7c0c419fac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!perl | |
use strict; | |
use warnings; | |
use utf8; | |
use HTTP::Request::Common; | |
use Path::Tiny; | |
use Plack::Test; | |
use Plack::Request; | |
use Test::More; | |
use Test::JsonAPI::Autodoc; | |
BEGIN { | |
$ENV{TEST_JSONAPI_AUTODOC} = 1; | |
} | |
my $tempdir = Path::Tiny->tempdir('test-jsonapi-autodoc-XXXXXXXX'); | |
set_documents_path($tempdir); | |
my $app = sub { | |
my $env = shift; | |
my $req = Plack::Request->new($env); | |
return [ | |
200, | |
[ 'Content-Type' => 'application/json' ], | |
[ | |
'{ | |
"hoge": { | |
"a": "aa", | |
"b": "bb" | |
} | |
}' | |
] | |
]; | |
}; | |
subtest 'output doc' => sub { | |
test_psgi $app, sub { | |
my $cb = shift; | |
describe 'POST /' => sub { | |
my $req = POST '/'; | |
$req->header('Content-Type' => 'application/json'); | |
$req->content(q{ | |
{ | |
"id": 1, | |
"message": "blah blah" | |
} | |
}); | |
plack_ok($cb, $req, 200, "get message ok"); | |
}; | |
}; | |
}; | |
(my $filename = path($0)->basename) =~ s/\.t$//; | |
$filename .= '.md'; | |
my $fh = path("$tempdir/$filename")->openr_utf8; | |
chomp (my $generated_at_line = <$fh>); | |
<$fh>; # blank | |
like $generated_at_line, qr/generated at: \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d/, 'generated at ok'; | |
my $got = do { local $/; <$fh> }; | |
my $expected = do { local $/; <DATA> }; | |
is $got, $expected, 'result ok'; | |
done_testing; | |
__DATA__ | |
## POST / | |
get message ok | |
### Target Server | |
http://localhost | |
(Plack application) | |
### Parameters | |
__application/json__ | |
- `id`: Number (e.g. 1) | |
- `message`: String (e.g. "blah blah") | |
### Request | |
POST / | |
### Response | |
- Status: 200 | |
- Content-Type: application/json | |
```json | |
{ | |
"hoge" : { | |
"a" : "aa", | |
"b" : "bb" | |
} | |
} | |
``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment