From cfcda98c6859672b843c15407e0c55d39da98b83 Mon Sep 17 00:00:00 2001 From: Edmund von der Burg Date: Fri, 20 May 2011 16:05:15 +0100 Subject: Added tests for bad requests --- t/app/controller/json.t | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 t/app/controller/json.t (limited to 't/app/controller/json.t') 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(); -- cgit v1.2.3