Skip to content

Commit

Permalink
Merge branch 'garu/v3' of github.com:cpan-testers/cpantesters-api int…
Browse files Browse the repository at this point in the history
…o garu/v3
  • Loading branch information
garu committed May 11, 2017
2 parents d5fda3d + 2769737 commit 2a04c4b
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 153 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ document is used by
[Mojolicious::Plugin::OpenAPI](http://metacpan.org/pod/Mojolicious::Plugin::OpenAPI)
to generate the Mojolicious routes and validate the input and output
automatically. Each route should have an `x-mojo-to` key to link it to
a `controller` (class) and `action` (method).
a `controller` (class) and `action` (method). It should also have an
`operationId` that is globally unique for all API files.

##### `share/templates`

Expand Down
14 changes: 7 additions & 7 deletions share/v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"controller": "Report",
"action": "report"
},
"operationId": "addReport",
"operationId": "v3_report_post",
"parameters": [{
"name": "report",
"in": "body",
Expand Down Expand Up @@ -75,7 +75,7 @@
"/release": {
"get": {
"tags": [ "Release" ],
"operationId": "release_all",
"operationId": "v3_release_all",
"summary": "Get summary test report info about all CPAN releases",
"x-mojo-to": {
"controller": "Release",
Expand All @@ -100,7 +100,7 @@
"/release/dist/{dist}": {
"get": {
"tags": [ "Release" ],
"operationId": "release_dist",
"operationId": "v3_release_dist",
"summary": "Get summary test report info for releases of a distribution",
"x-mojo-to": {
"controller": "Release",
Expand Down Expand Up @@ -129,7 +129,7 @@
"/release/author/{author}": {
"get": {
"tags": [ "Release" ],
"operationId": "release_author",
"operationId": "v3_release_author",
"summary": "Get summary test report info for releases by an author",
"x-mojo-to": {
"controller": "Release",
Expand Down Expand Up @@ -158,7 +158,7 @@
"/upload": {
"get": {
"tags": [ "Upload" ],
"operationId": "upload_all",
"operationId": "v3_upload_all",
"summary": "Get all uploads to CPAN",
"description": "This route gets uploads to CPAN. Asking for a WebSocket will subscribe to a feed of new uploads.",
"x-mojo-to": {
Expand Down Expand Up @@ -187,7 +187,7 @@
"/upload/dist/{dist}": {
"get": {
"tags": [ "Upload" ],
"operationId": "upload_dist",
"operationId": "v3_upload_dist",
"summary": "Get uploads for a dist",
"description": "This route gets uploads to CPAN for a specific distribution. Asking for a WebSocket will subscribe to a feed of new uploads.",
"x-mojo-to": {
Expand Down Expand Up @@ -217,7 +217,7 @@
"/upload/author/{author}": {
"get": {
"tags": [ "Upload" ],
"operationId": "upload_author",
"operationId": "v3_upload_author",
"summary": "Get uploads for an author",
"description": "This route gets uploads to CPAN for the specific author. Asking for a WebSocket will subscribe to a feed of new uploads.",
"x-mojo-to": {
Expand Down
3 changes: 3 additions & 0 deletions t/api.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ subtest 'can get OpenAPI document' => sub {
$t->get_ok( '/v1' )
->status_is( 200 )
->header_like( 'Content-Type' => qr{^application/json} );
$t->get_ok( '/v3' )
->status_is( 200 )
->header_like( 'Content-Type' => qr{^application/json} );
};

done_testing;
103 changes: 54 additions & 49 deletions t/controller/release.t
Original file line number Diff line number Diff line change
Expand Up @@ -208,68 +208,73 @@ subtest 'sanity check that items were inserted' => sub {
or diag explain [ $rs->all ];
};

subtest 'all releases' => sub {
$t->get_ok( '/v1/release' )
->status_is( 200 )
->json_is( [ map { +{ $_->%{ @API_FIELDS } } } $data{Release}->@[0..2] ] );
subtest '/v1/release' => \&_test_api, '/v1';
subtest '/v3/release' => \&_test_api, '/v3';

subtest 'since (disabled until optimized)' => sub {
$t->get_ok( '/v1/release?since=2016-08-20T00:00:00Z' )
->status_is( 400 )
->json_has( '/errors' )
->or( sub { diag explain shift->tx->res->json } );
};
};
sub _test_api( $base ) {
subtest 'all releases' => sub {
$t->get_ok( $base . '/release' )
->status_is( 200 )
->json_is( [ map { +{ $_->%{ @API_FIELDS } } } $data{Release}->@[0..2] ] );

subtest 'by dist' => sub {
$t->get_ok( '/v1/release/dist/My-Dist' )
->status_is( 200 )
->json_is( [ map { +{ $_->%{ @API_FIELDS } } } $data{Release}->@[0,1] ] );
subtest 'since (disabled until optimized)' => sub {
$t->get_ok( $base . '/release?since=2016-08-20T00:00:00Z' )
->status_is( 400 )
->json_has( '/errors' )
->or( sub { diag explain shift->tx->res->json } );
};
};

subtest 'since' => sub {
$t->get_ok( '/v1/release/dist/My-Dist?since=2016-08-20T00:00:00Z' )
subtest 'by dist' => sub {
$t->get_ok( $base . '/release/dist/My-Dist' )
->status_is( 200 )
->json_is( [ map { +{ $_->%{ @API_FIELDS } } } $data{Release}[1] ] );
};
->json_is( [ map { +{ $_->%{ @API_FIELDS } } } $data{Release}->@[0,1] ] );

subtest 'dist not found' => sub {
$t->get_ok( '/v1/release/dist/NOT_FOUND' )
->status_is( 404 )
->json_is( {
errors => [ { message => 'Distribution "NOT_FOUND" not found', 'path' => '/' } ],
} );
};
};
subtest 'since' => sub {
$t->get_ok( $base . '/release/dist/My-Dist?since=2016-08-20T00:00:00Z' )
->status_is( 200 )
->json_is( [ map { +{ $_->%{ @API_FIELDS } } } $data{Release}[1] ] );
};

subtest 'by author' => sub {
$t->get_ok( '/v1/release/author/PREACTION' )
->status_is( 200 )
->json_is( [ map { +{ $_->%{ @API_FIELDS } } } $data{Release}->@[0,2] ] );
subtest 'dist not found' => sub {
$t->get_ok( $base . '/release/dist/NOT_FOUND' )
->status_is( 404 )
->json_is( {
errors => [ { message => 'Distribution "NOT_FOUND" not found', 'path' => '/' } ],
} );
};
};

subtest 'since' => sub {
$t->get_ok( '/v1/release/author/PREACTION?since=2016-08-20T00:00:00Z' )
subtest 'by author' => sub {
$t->get_ok( $base . '/release/author/PREACTION' )
->status_is( 200 )
->json_is( [ map { +{ $_->%{ @API_FIELDS } } } $data{Release}[2] ] );
};
->json_is( [ map { +{ $_->%{ @API_FIELDS } } } $data{Release}->@[0,2] ] );

subtest 'author not found' => sub {
$t->get_ok( '/v1/release/author/NOT_FOUND' )
->status_is( 404 )
->json_is( {
errors => [ { message => 'Author "NOT_FOUND" not found', path => '/' } ],
} );
subtest 'since' => sub {
$t->get_ok( $base . '/release/author/PREACTION?since=2016-08-20T00:00:00Z' )
->status_is( 200 )
->json_is( [ map { +{ $_->%{ @API_FIELDS } } } $data{Release}[2] ] );
};

subtest 'author not found' => sub {
$t->get_ok( $base . '/release/author/NOT_FOUND' )
->status_is( 404 )
->json_is( {
errors => [ { message => 'Author "NOT_FOUND" not found', path => '/' } ],
} );
};
};
};

subtest 'input validation' => sub {
subtest 'input validation' => sub {

subtest '"since" must be an ISO8601 date/time' => sub {
$t->get_ok( '/v1/release/dist/My-Dist?since=Sat Nov 19 14:18:40 2016' )
->status_is( 400 )
->json_has( '/errors' )
->or( sub { diag explain shift->tx->res->json } );
subtest '"since" must be an ISO8601 date/time' => sub {
$t->get_ok( $base . '/release/dist/My-Dist?since=Sat Nov 19 14:18:40 2016' )
->status_is( 400 )
->json_has( '/errors' )
->or( sub { diag explain shift->tx->res->json } );
};
};
};
}

done_testing;

Loading

0 comments on commit 2a04c4b

Please sign in to comment.