diff options
author | Edmund von der Burg <evdb@mysociety.org> | 2011-05-20 16:05:15 +0100 |
---|---|---|
committer | Edmund von der Burg <evdb@mysociety.org> | 2011-05-20 16:05:15 +0100 |
commit | cfcda98c6859672b843c15407e0c55d39da98b83 (patch) | |
tree | 52dd274da375d9370aa17007f6c27f699c2da35d /t | |
parent | 0518f68fcdc68241ddf7a0d083c450136a9e5efa (diff) |
Added tests for bad requests
Diffstat (limited to 't')
-rw-r--r-- | t/app/controller/json.t | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/t/app/controller/json.t b/t/app/controller/json.t new file mode 100644 index 000000000..e5fda5d27 --- /dev/null +++ b/t/app/controller/json.t @@ -0,0 +1,36 @@ +use strict; +use warnings; + +use Test::More; + +use FixMyStreet::TestMech; +my $mech = FixMyStreet::TestMech->new; + +subtest "check that a bad request produces the right response" => sub { + + my $bad_date = "Invalid dates supplied"; + my $bad_type = "Invalid type supplied"; + + my %tests = ( + '' => $bad_date, + 'foo=bar' => $bad_date, + 'type=&start_date=&end_date=' => $bad_date, + 'type=&start_date=bad&end_date=2000-02-01' => $bad_date, + 'type=&start_date=2000-01-01&end_date=bad' => $bad_date, + 'type=&start_date=2000-02-31&end_date=2000-02-01' => $bad_date, + 'type=&start_date=2000-01-01&end_date=2000-02-31' => $bad_date, + + 'type=&start_date=2000-01-01&end_date=2000-02-01' => $bad_type, + 'type=foo&start_date=2000-01-01&end_date=2000-02-01' => $bad_type, + ); + + foreach my $q ( sort keys %tests ) { + is_deeply # + $mech->get_ok_json("/json?$q"), # + { error => $tests{$q} }, # + "correct error for query '$q'"; + } + +}; + +done_testing(); |