|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | +use lib 't/lib'; |
| 4 | + |
| 5 | +use Cpanel::JSON::XS qw( encode_json ); |
| 6 | +use MetaCPAN::Server::Test qw( app GET test_psgi ); |
| 7 | +use MetaCPAN::TestHelpers qw( decode_json_ok ); |
| 8 | +use Test::More; |
| 9 | + |
| 10 | +use HTTP::Request::Common (); |
| 11 | + |
| 12 | +test_psgi app, sub { |
| 13 | + my $cb = shift; |
| 14 | + |
| 15 | + ok( my $res = $cb->( GET '/user/profile?access_token=testing' ), |
| 16 | + 'GET /user/profile' ); |
| 17 | + is( $res->code, 200, 'code 200' ); |
| 18 | + my $profile = decode_json_ok($res); |
| 19 | + |
| 20 | + # An author whose name is already ASCII has an empty/null asciiname. Saving |
| 21 | + # the profile form sends "asciiname": null. This must not be rejected with |
| 22 | + # "asciiname is required": asciiname is required => 1 but has a default, so |
| 23 | + # an absent value is filled in at construction time. |
| 24 | + my $put = HTTP::Request::Common::PUT( |
| 25 | + '/user/profile?access_token=testing', |
| 26 | + Content_Type => 'application/json', |
| 27 | + Content => encode_json( { |
| 28 | + name => 'Moritz Onken', |
| 29 | + asciiname => undef, |
| 30 | + website => ['http://metacpan.org/'], |
| 31 | + email => ['onken@netcubed.de'], |
| 32 | + city => 'Karlsruhe', |
| 33 | + region => 'BW', |
| 34 | + country => 'DE', |
| 35 | + } ), |
| 36 | + ); |
| 37 | + |
| 38 | + ok( $res = $cb->($put), 'PUT /user/profile with null asciiname' ); |
| 39 | + is( $res->code, 201, 'profile saved (status created)' ) |
| 40 | + or diag( $res->content ); |
| 41 | + |
| 42 | + my $saved = decode_json_ok($res); |
| 43 | + is( $saved->{asciiname} // q{}, |
| 44 | + q{}, 'asciiname is empty (default applied), not rejected' ); |
| 45 | +}; |
| 46 | + |
| 47 | +done_testing; |
0 commit comments