-use 5.6.0;
-
use strict;
use warnings;
use Test::More;
use Test::WWW::Mechanize::Catalyst 'RestTest';
use HTTP::Request::Common;
-use JSON;
+use JSON::MaybeXS;
-my $json = JSON->new->utf8;
+my $json = JSON::MaybeXS->new(utf8 => 1);
my $mech = Test::WWW::Mechanize::Catalyst->new;
ok( my $schema = DBICTest->init_schema(), 'got schema' );
# test create returns an error as expected when passing invalid value
{
- my $long_string = '-' x 1024;
+ my $data = {
+ producerid => 100,
+ name => 'Producer',
+ };
- my $req = POST(
- $producer_create_url,
- { producerid => $long_string,
- name => $long_string,
- },
- 'Accept' => 'text/json'
+ my $req = POST($producer_create_url, $data, 'Accept' => 'text/json');
+ $mech->request( $req, $content_type );
+ cmp_ok( $mech->status, '==', 200, 'create with pk value ok' );
+ my $response = $json->decode( $mech->content );
+ is_deeply(
+ $response,
+ { success => 'true', list => $data },
+ 'json for producer with pk value ok'
);
+ # try to insert same data again, as this seems to be the only way to
+ # force an insert to fail for SQLite.
+ # It accepts too long columns as well as wrong datatypes without errors.
+ # The bind with datatype of newer DBIC versions numifies non-integer
+ # values passed as pk value too.
$mech->request( $req, $content_type );
cmp_ok( $mech->status, '==', 400, 'invalid param value produces error' );
}