Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Testing script for stargazers.
  • Loading branch information
Talina06 committed Jul 1, 2014
1 parent 6ffe1e3 commit 86c6d28
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions t/server/controller/user/stargazer.t
@@ -0,0 +1,62 @@
use strict;
use warnings;

use MetaCPAN::Server::Test;
use Test::More;

test_psgi app, sub {
my $cb = shift;

ok( my $user = $cb->( GET '/user?access_token=testing' ), 'get user' );
is( $user->code, 200, 'code 200' );
ok( $user = decode_json( $user->content ), 'decode json' );

ok(
my $res = $cb->(
POST '/user/stargazer?access_token=testing',
Content => encode_json(
{
module => 'Moose::Cookbook',
release => 'Moose-2.1209',
author => 'DOY'
}
)
),
"POST stargazer"
);
is( $res->code, 201, 'status created' );
ok( my $location = $res->header('location'), "location header set" );
ok( $res = $cb->( GET $location ), "GET $location" );
is( $res->code, 200, 'found' );
my $json = decode_json( $res->content );
is( $json->{user}, $user->{id}, 'user is ' . $user->{id} );
ok( $res = $cb->( DELETE "/user/stargazer/Moose::Cookbook?access_token=testing" ),
"DELETE /user/stargazer/MO/Moose::Cookbook" );
is( $res->code, 200, 'status ok' );
ok( $res = $cb->( GET "$location?access_token=testing" ),
"GET $location" );
is( $res->code, 404, 'not found' );

ok( $user = $cb->( GET '/user?access_token=bot' ), 'get bot' );
is( $user->code, 200, 'code 200' );
ok( $user = decode_json( $user->content ), 'decode json' );
ok( !$user->{looks_human}, 'user looks like a bot' );
ok(
$res = $cb->(
POST '/user/stargazer?access_token=bot',
Content => encode_json(
{
module => 'Moose::Cookbook',
release => 'Moose-2.1209',
author => 'DOY'
}
)
),
"POST stargazer"
);
ok( decode_json( $res->content ), 'decode response' );
is( $res->code, 403, 'forbidden' );

};

done_testing;

0 comments on commit 86c6d28

Please sign in to comment.